Made windowspawner keep track of spawned window count

This commit is contained in:
2026-01-19 20:22:35 +00:00
parent e636e28d3a
commit 6c3e7ca111
6 changed files with 18 additions and 18 deletions

View File

@@ -27,7 +27,7 @@ namespace InterfaceOff.WorldScene
private float MouseYaw = 90; private float MouseYaw = 90;
private int CurrentFrameIndex; private int CurrentFrameIndex;
private List<PlayerFrameInfo> FrameInfo = new(); private readonly List<PlayerFrameInfo> FrameInfo = new();
private void Awake() private void Awake()
{ {

View File

@@ -5,14 +5,16 @@ namespace InterfaceOff
{ {
public abstract class WindowBase : MonoBehaviour public abstract class WindowBase : MonoBehaviour
{ {
private WindowSpawner Creator;
public WindowInteractions Interactions { get; set; } public WindowInteractions Interactions { get; set; }
public WindowComponents Components { get; set; } public WindowComponents Components { get; set; }
protected Vector2 Velocity; protected Vector2 Velocity;
public void InstantiateWindowBase() public void InstantiateWindowBase(WindowSpawner creator)
{ {
transform.position = CanvasManager.GetRandomPositionOnCanvas(); transform.position = CanvasManager.GetRandomPositionOnCanvas();
Creator = creator;
OnWindowInstantiation(); OnWindowInstantiation();
} }
@@ -60,6 +62,7 @@ namespace InterfaceOff
protected void DestroyWindow() protected void DestroyWindow()
{ {
Creator.AlertOfDespawnedWindow();
Destroy(gameObject); Destroy(gameObject);
} }
} }

View File

@@ -21,8 +21,10 @@ namespace InterfaceOff
[field: SerializeField] private SpawnableWindowType[] WindowTypes { get; set; } [field: SerializeField] private SpawnableWindowType[] WindowTypes { get; set; }
private int TotalSpawnWeight { get; set; } private int TotalSpawnWeight { get; set; }
[field: SerializeField] public int SpawnedWindowCount { get; private set; }
[field: SerializeField] public bool AutoSpawn { get; private set; } = true; [field: SerializeField] public bool AutoSpawn { get; private set; } = true;
private int SpawnCounter { get; set; } private int TimeTillNextSpawn { get; set; }
private void Awake() private void Awake()
{ {
@@ -75,14 +77,19 @@ namespace InterfaceOff
return; return;
} }
/* Updates the window trackers */
SpawnedWindowCount++;
/* Makes sure the WindowInteractions and WindowComponents are set up before passing to user code */ /* Makes sure the WindowInteractions and WindowComponents are set up before passing to user code */
windowBase.Interactions = go.GetComponent<WindowInteractions>(); windowBase.Interactions = go.GetComponent<WindowInteractions>();
windowBase.Interactions.SetAttachedTo(windowBase); windowBase.Interactions.SetAttachedTo(windowBase);
windowBase.Components = go.GetComponent<WindowComponents>(); windowBase.Components = go.GetComponent<WindowComponents>();
windowBase.InstantiateWindowBase(); windowBase.InstantiateWindowBase(creator: this);
} }
public void AlertOfDespawnedWindow() => SpawnedWindowCount--;
private void FixedUpdate() private void FixedUpdate()
{ {
if (AutoSpawn) if (AutoSpawn)
@@ -92,10 +99,10 @@ namespace InterfaceOff
const int MAXIMUM_SPAWN_TIME = 5 * TICKS_PER_SECOND; const int MAXIMUM_SPAWN_TIME = 5 * TICKS_PER_SECOND;
/* Decreases the spawn counter and spawns if at 0 */ /* Decreases the spawn counter and spawns if at 0 */
SpawnCounter = Math.Max(0, SpawnCounter - 1); TimeTillNextSpawn = Math.Max(0, TimeTillNextSpawn - 1);
if (SpawnCounter == 0) if (TimeTillNextSpawn == 0)
{ {
SpawnCounter = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME); TimeTillNextSpawn = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME);
SpawnNewRandomWindow(); SpawnNewRandomWindow();
} }
} }

View File

@@ -12,10 +12,5 @@ namespace InterfaceOff
Components.InfoText.text = advert.Name; Components.InfoText.text = advert.Name;
Components.WindowImage.color = new Color(1, 1, 1, 1); Components.WindowImage.color = new Color(1, 1, 1, 1);
} }
public override void OnWindowCloseButtonClicked()
{
Destroy(gameObject);
}
} }
} }

View File

@@ -63,7 +63,7 @@ namespace InterfaceOff
{ {
if (m_TilesRotatedCorrectly == 4) if (m_TilesRotatedCorrectly == 4)
{ {
Destroy(gameObject); DestroyWindow();
} }
} }
} }

View File

@@ -16,10 +16,5 @@ namespace InterfaceOff
float angle = Random.Range(0, Mathf.PI * 2); float angle = Random.Range(0, Mathf.PI * 2);
Velocity = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * 100; Velocity = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * 100;
} }
public override void OnWindowCloseButtonClicked()
{
Destroy(gameObject);
}
} }
} }