Added a new moving window type

This commit is contained in:
Pasha Bibko
2026-01-13 11:16:16 +00:00
parent eae7b615d6
commit e235c9e440
9 changed files with 78 additions and 21 deletions

View File

@@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="project">
<words>
<w>gameobject</w>
</words>
</dictionary>
</component>

View File

@@ -630,7 +630,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &1867692259 --- !u!224 &1867692259
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -7,11 +7,21 @@ namespace InterfaceOff
public WindowInteractions Interactions { get; set; } public WindowInteractions Interactions { get; set; }
public WindowComponents Components { get; set; } public WindowComponents Components { get; set; }
public Vector3 Velocity { get; set; }
public void InstantiateWindowBase() public void InstantiateWindowBase()
{ {
transform.position = CanvasManager.GetRandomPositionOnCanvas(); transform.position = CanvasManager.GetRandomPositionOnCanvas();
OnWindowInstantiation();
} }
public void LateUpdate()
{
transform.position += Velocity * Time.deltaTime;
}
public virtual void OnWindowInstantiation() { }
public virtual void OnWindowClicked() { } public virtual void OnWindowClicked() { }
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
namespace InterfaceOff namespace InterfaceOff
{ {
@@ -31,29 +32,37 @@ namespace InterfaceOff
} }
} }
private void Update() private void SpawnNewRandomWindow()
{ {
if (Input.GetKeyDown(KeyCode.Space)) /* Creates the gameobject with a random class */
GameObject go = Instantiate(SampleChild, GameCanvas.transform);
go.SetActive(true);
Type type = WindowTypes.GetRandom();
WindowBase windowBase = go.AddComponent(type) as WindowBase;
/* Checks it created correctly before instantiating further */
if (DebugUtils.IsNull(windowBase))
{ {
/* Creates the gameobject with a random class */ Debug.LogError("How did this happen");
GameObject go = Instantiate(SampleChild, GameCanvas.transform); return;
go.SetActive(true); }
Type type = WindowTypes.GetRandom();
WindowBase windowBase = go.AddComponent(type) as WindowBase;
/* Checks it created correctly before instantiating further */
if (DebugUtils.IsNull(windowBase))
{
Debug.LogError("How did this happen");
return;
}
windowBase.Interactions = go.GetComponent<WindowInteractions>(); /* Makes sure the WindowInteractions and WindowComponents are setup before passing to user code */
windowBase.Interactions.SetAttachedTo(windowBase); windowBase.Interactions = go.GetComponent<WindowInteractions>();
windowBase.Interactions.SetAttachedTo(windowBase);
windowBase.Components = go.GetComponent<WindowComponents>(); windowBase.Components = go.GetComponent<WindowComponents>();
windowBase.InstantiateWindowBase(); windowBase.InstantiateWindowBase();
}
private void FixedUpdate()
{
/* Checks if it should spawn a window */
bool shouldSpawn = Random.Range(0, 40) == 0;
if (shouldSpawn)
{
SpawnNewRandomWindow();
} }
} }
} }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8cc86789c70b427d88ef6a4672547137
timeCreated: 1768302148

View File

@@ -0,0 +1,25 @@
using UnityEngine;
namespace InterfaceOff
{
public class MovingWindow : WindowBase
{
private int m_Health = 5;
public override void OnWindowInstantiation()
{
Components.WindowImage.color = Color.red;
Velocity = new Vector3(100, 100, 0);
}
public override void OnWindowClicked()
{
/* Decreases health and destroys if at 0 */
m_Health--;
if (m_Health <= 0)
{
Destroy(gameObject);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7ad1aa722804bbba796feea129247f1
timeCreated: 1768302389