private void SendCommand(GameCommand command) { if (currentCommand) { Debug.LogError("Can't send command while awaiting response."); return; } GameObject commandPrefab = null; if (command.CommandPrefabName != null) { commandPrefab = commandPrefabs.GetPrefab(command.CommandPrefabName); if (commandPrefab == null) { Debug.LogError("Command specified a prefab, but one was not found by that name: " + command.CommandPrefabName); } } if (commandPrefab != null) { GameObject go = Instantiate(commandPrefab); currentCommand = go.GetComponent <CommandBehaviour>(); go.transform.parent = transform; if (currentCommand == null) { Debug.LogError("Command prefab missing CommandBehaviour"); } currentCommand.Command = command; } validPlays = null; if (commandFilter != null) { commandFilter.HandleCommand(command); } GameClient.Instance.SendRequest(command); }
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; } } }
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; } } }