private void Update() { // Main state machine switch (this.currentState) { case GAMESTATE.IDLE: { break; } case GAMESTATE.PLAYING: { btTileManager.instance.playerTile.ResetUpdateValues(); btFunctionNode.NODE_STATE executeState = btFunctionTreeManager.instance.ExecuteTree(); this.currentState = GAMESTATE.TILE_UPDATE; btInterfaceTreeManager.instance.UpdateNodeGlowColour(); if (executeState == btFunctionNode.NODE_STATE.FAILED) { this.StopAndReset(); btUIManager.instance.DisplayMessageDialog("Tree Failure", "The tree stopped, meaning that there were no more actions that could run."); break; } break; } case GAMESTATE.TILE_UPDATE: // During the update, the game manager waits for the tile manager to finish { bool doneUpdating = btTileManager.instance.UpdateTiles(); bool doneMoving = btTileManager.instance.ExecuteTileMovements(); if (doneUpdating == true && doneMoving == true) { this.currentState = GAMESTATE.PLAYING; } break; } case GAMESTATE.DEAD_PLAYER: { this.StopAndReset(); break; } case GAMESTATE.LEVEL_COMPLETE: { this.currentState = GAMESTATE.IDLE; break; } default: { Debug.LogError("Uncaught GAMESTATE: " + this.currentState); break; } } }
/// <summary> /// Runs the functional tree and returns the execution state of the root node /// </summary> /// <returns>The state of the root node</returns> public btFunctionNode.NODE_STATE ExecuteTree() { this.rootFunctionNode.Reset(); btFunctionNode.NODE_STATE executeState = this.rootFunctionNode.TreeExecute(); return(executeState); }