public bool ReplaceIfSameAsExistingNode(PuzzleStateEdge edge) { PuzzleStateNode sameState = null; if (stateMap.TryGetValue(edge.toNode.state, out sameState)) { edge.ReplaceToNode(sameState); return(true); } return(false); }
void RefreshStatesGUI() { if (state == lastCalculatedState) { return; } actionsPerNode = new List <PuzzleStateEdge> [puzzle.nodes.Count]; for (int i = 0; i < state.outgoing.Count; i++) { PuzzleStateEdge child = state.outgoing[i]; PuzzleNode actionNode = child.actionNode; int nodeIndex = puzzle.nodes.IndexOf(actionNode); if (actionsPerNode[nodeIndex] == null) { actionsPerNode[nodeIndex] = new List <PuzzleStateEdge> (); } actionsPerNode[nodeIndex].Add(child); } lastCalculatedState = state; }
void StatesGUI() { Rect area = cam.pixelRect.FlipY(); GUILayout.BeginArea(area); area.position = Vector2.zero; int spacing = kSpacing; Rect optionsRect = new Rect(area.width - 150 - spacing, spacing, 150, kButtonHeight); GUI.enabled = puzzleFront.HasUndo(); if (GUI.Button(GetRectHNeg(ref optionsRect, 70, spacing), "Undo")) { puzzleFront.Undo(); } if (GUI.Button(GetRectHNeg(ref optionsRect, 70, spacing), "Restart")) { puzzleFront.Reset(); } GUI.enabled = true; showHints = GUI.Toggle(GetRectHNeg(ref optionsRect, 150, spacing), showHints, "Show Hints"); RefreshStatesGUI(); if (Time.time > puzzleFront.doneTime) { for (int i = 0; i < puzzleFront.nodes.Count; i++) { NodeFront nodeFront = puzzleFront.nodes[i]; PuzzleNode actionNode = nodeFront.node; int nodeIndex = puzzle.nodes.IndexOf(actionNode); if (actionsPerNode[nodeIndex] == null) { continue; } int actionCount = actionsPerNode[nodeIndex].Count; Vector3 nodePosition = nodeFront.transform.position - Vector3.up * 0.2f; Vector2 pos = cam.WorldToScreenPoint(nodePosition); pos.y = cam.pixelRect.height - pos.y; pos -= cam.pixelRect.min; GUI.color = new Color(1, 1, 1, 0.7f); Rect rect = new Rect(pos.x - 60, pos.y, 120, 24 + kButtonHeight * actionCount); GUI.Box(rect, string.Empty, "OptionBox"); for (int j = 0; j < actionsPerNode[i].Count; j++) { PuzzleStateEdge childAction = actionsPerNode[i][j]; GUI.color = Color.white; GUI.contentColor = Color.green; if (showHints) { // Show as green if goal path that's either // further along or we are not currently on goal path. if (childAction.toNode.goalPath && (childAction.directPath || !state.goalPath)) { GUI.color = Color.green; } else if (childAction.toNode.stuck) { GUI.color = Color.red; } } rect = new Rect(pos.x - 58, pos.y + 22 + kButtonHeight * j, 116, kButtonHeight); if (GUI.Button(rect, childAction.name, "MenuOption")) { puzzleFront.GoToState(childAction.toNode); } } } GUI.color = Color.white; } GUILayout.EndArea(); }