Made windowspawner keep track of spawned window count
This commit is contained in:
@@ -27,7 +27,7 @@ namespace InterfaceOff.WorldScene
|
||||
private float MouseYaw = 90;
|
||||
private int CurrentFrameIndex;
|
||||
|
||||
private List<PlayerFrameInfo> FrameInfo = new();
|
||||
private readonly List<PlayerFrameInfo> FrameInfo = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<WindowInteractions>();
|
||||
windowBase.Interactions.SetAttachedTo(windowBase);
|
||||
|
||||
windowBase.Components = go.GetComponent<WindowComponents>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace InterfaceOff
|
||||
{
|
||||
if (m_TilesRotatedCorrectly == 4)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
DestroyWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user