void Update() { // First remove any null (destroyed) gameobjects: activeEvents.RemoveAll(x => x == null); activeCount = activeEvents.Count; if (IsBlocked()) { return; } // While there are events in the queue and we haven't spawned any blocking // events, dequeue and spawn: bool done = false; while (!done) { if (eventQueue.Count > 0) { GameEvent next = eventQueue.Dequeue(); GameEventBehaviour eventBehaviour = SpawnEvent(next); if (eventBehaviour != null && eventBehaviour.IsBlocking) { done = true; } } else { done = true; } } // When the CommandManager isn't blocking, update the valid plays (which allows the player to act): if (!CommandManager.Instance.BlockingEvents) { if (updatedPlays != null) { CommandManager.Instance.ValidPlays = updatedPlays; updatedPlays = null; } } // When the GameEventQueue isn't blocking and there are no more events // incoming, update the gameview, which theoretically shouldn't change // anything if (!IsBlocked() && eventQueue.Count == 0) { if (updatedView != null) { GameManager.Instance.UpdateView(updatedView); updatedView = null; } } }
private GameEventBehaviour SpawnEvent(GameEvent data) { GameObject prototype = AssetManager.Instance.GetGameEvent(data.prototypeName); if (prototype == null) { Debug.LogError("Failed to find " + data.prototypeName + " prototype"); return(null); } GameObject go = Instantiate(prototype); GameEventBehaviour eventBehaviour = go.GetComponent <GameEventBehaviour>(); if (eventBehaviour == null) { Debug.LogError(go + " was expected to have " + typeof(GameEventBehaviour).ToString()); } eventBehaviour.Data = data; activeEvents.Add(eventBehaviour); Debug.Log("Adding game event " + eventBehaviour); return(eventBehaviour); }