From 6c3e7ca111234d9817e07ee78cb838350854995d Mon Sep 17 00:00:00 2001 From: Pasha Date: Mon, 19 Jan 2026 20:22:35 +0000 Subject: [PATCH] Made windowspawner keep track of spawned window count --- Assets/Scripts/DevPlayerController.cs | 2 +- Assets/Scripts/WindowBase.cs | 5 ++++- Assets/Scripts/WindowSpawner.cs | 17 ++++++++++++----- Assets/Scripts/Windows/BasicWindow.cs | 5 ----- Assets/Scripts/Windows/ImageWindow.cs | 2 +- Assets/Scripts/Windows/MovingWindow.cs | 5 ----- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/DevPlayerController.cs b/Assets/Scripts/DevPlayerController.cs index 8ccc6ec..cb8324b 100644 --- a/Assets/Scripts/DevPlayerController.cs +++ b/Assets/Scripts/DevPlayerController.cs @@ -27,7 +27,7 @@ namespace InterfaceOff.WorldScene private float MouseYaw = 90; private int CurrentFrameIndex; - private List FrameInfo = new(); + private readonly List FrameInfo = new(); private void Awake() { diff --git a/Assets/Scripts/WindowBase.cs b/Assets/Scripts/WindowBase.cs index a208463..4007894 100644 --- a/Assets/Scripts/WindowBase.cs +++ b/Assets/Scripts/WindowBase.cs @@ -5,14 +5,16 @@ namespace InterfaceOff { public abstract class WindowBase : MonoBehaviour { + private WindowSpawner Creator; public WindowInteractions Interactions { get; set; } public WindowComponents Components { get; set; } protected Vector2 Velocity; - public void InstantiateWindowBase() + public void InstantiateWindowBase(WindowSpawner creator) { transform.position = CanvasManager.GetRandomPositionOnCanvas(); + Creator = creator; OnWindowInstantiation(); } @@ -60,6 +62,7 @@ namespace InterfaceOff protected void DestroyWindow() { + Creator.AlertOfDespawnedWindow(); Destroy(gameObject); } } diff --git a/Assets/Scripts/WindowSpawner.cs b/Assets/Scripts/WindowSpawner.cs index 728a355..ae43486 100644 --- a/Assets/Scripts/WindowSpawner.cs +++ b/Assets/Scripts/WindowSpawner.cs @@ -20,9 +20,11 @@ namespace InterfaceOff [field: SerializeField] private SpawnableWindowType[] WindowTypes { get; set; } private int TotalSpawnWeight { get; set; } + + [field: SerializeField] public int SpawnedWindowCount { get; private set; } [field: SerializeField] public bool AutoSpawn { get; private set; } = true; - private int SpawnCounter { get; set; } + private int TimeTillNextSpawn { get; set; } private void Awake() { @@ -74,14 +76,19 @@ namespace InterfaceOff Debug.LogError("How did this happen"); return; } + + /* Updates the window trackers */ + SpawnedWindowCount++; /* Makes sure the WindowInteractions and WindowComponents are set up before passing to user code */ windowBase.Interactions = go.GetComponent(); windowBase.Interactions.SetAttachedTo(windowBase); windowBase.Components = go.GetComponent(); - windowBase.InstantiateWindowBase(); + windowBase.InstantiateWindowBase(creator: this); } + + public void AlertOfDespawnedWindow() => SpawnedWindowCount--; private void FixedUpdate() { @@ -92,10 +99,10 @@ namespace InterfaceOff const int MAXIMUM_SPAWN_TIME = 5 * TICKS_PER_SECOND; /* Decreases the spawn counter and spawns if at 0 */ - SpawnCounter = Math.Max(0, SpawnCounter - 1); - if (SpawnCounter == 0) + TimeTillNextSpawn = Math.Max(0, TimeTillNextSpawn - 1); + if (TimeTillNextSpawn == 0) { - SpawnCounter = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME); + TimeTillNextSpawn = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME); SpawnNewRandomWindow(); } } diff --git a/Assets/Scripts/Windows/BasicWindow.cs b/Assets/Scripts/Windows/BasicWindow.cs index 275efcd..7ec088a 100644 --- a/Assets/Scripts/Windows/BasicWindow.cs +++ b/Assets/Scripts/Windows/BasicWindow.cs @@ -12,10 +12,5 @@ namespace InterfaceOff Components.InfoText.text = advert.Name; Components.WindowImage.color = new Color(1, 1, 1, 1); } - - public override void OnWindowCloseButtonClicked() - { - Destroy(gameObject); - } } } \ No newline at end of file diff --git a/Assets/Scripts/Windows/ImageWindow.cs b/Assets/Scripts/Windows/ImageWindow.cs index 51d2f58..3825bb2 100644 --- a/Assets/Scripts/Windows/ImageWindow.cs +++ b/Assets/Scripts/Windows/ImageWindow.cs @@ -63,7 +63,7 @@ namespace InterfaceOff { if (m_TilesRotatedCorrectly == 4) { - Destroy(gameObject); + DestroyWindow(); } } } diff --git a/Assets/Scripts/Windows/MovingWindow.cs b/Assets/Scripts/Windows/MovingWindow.cs index 9808272..7dd5992 100644 --- a/Assets/Scripts/Windows/MovingWindow.cs +++ b/Assets/Scripts/Windows/MovingWindow.cs @@ -16,10 +16,5 @@ namespace InterfaceOff float angle = Random.Range(0, Mathf.PI * 2); Velocity = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * 100; } - - public override void OnWindowCloseButtonClicked() - { - Destroy(gameObject); - } } } \ No newline at end of file