private void Print(string prefix, Node node) { if (node.CurrentState == Node.State.ACTIVE) { string label = prefix + " > " + node + " (" + node.DebugNumStartCalls + "|" + node.DebugNumStopCalls + "|" + node.DebugNumStoppedCalls + (node.DebugNumStoppedCalls > 0 ? "|" + node.DebugLastResult : "") + ")"; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(label, GreenLabelStyle); if (GUILayout.Button("Stop")) { node.Stop(); } EditorGUILayout.EndHorizontal(); } else { string label = prefix + " - " + node + " (" + node.DebugNumStartCalls + "|" + node.DebugNumStopCalls + "|" + node.DebugNumStoppedCalls + (node.DebugNumStoppedCalls > 0 ? "|" + node.DebugLastResult : "") + ")"; if (node is Root) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(label); if (GUILayout.Button("Start")) { node.Start(); } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField(label); } } }
public override void StopLowerPriorityChildrenForChild(Node abortForChild, bool immediateRestart) { if (immediateRestart) { Assert.IsFalse(abortForChild.IsActive); if (childrenResults[abortForChild]) { succeededCount--; } else { failedCount--; } runningCount++; abortForChild.Start(); } else { throw new Exception("On Parallel Nodes all children have the same priority, thus the method does nothing if you pass false to 'immediateRestart'!"); } }
private void DrawNode(Node node, int depth, bool connected) { float tStopRequested = Mathf.Lerp(0.85f, 0.25f, 2.0f * (Time.time - node.DebugLastStopRequestAt)); float tStopped = Mathf.Lerp(0.85f, 0.25f, 2.0f * (Time.time - node.DebugLastStoppedAt)); bool inactive = node.CurrentState != Node.State.ACTIVE; float alpha = inactive ? Mathf.Max(0.35f, Mathf.Pow(tStopped, 1.5f)) : 1.0f; bool failed = (tStopped > 0.25f && tStopped < 1.0f && !node.DebugLastResult && inactive); bool stopRequested = (tStopRequested > 0.25f && tStopRequested < 1.0f && inactive); EditorGUILayout.BeginHorizontal(); { GUI.color = new Color(1f, 1f, 1f, alpha); string tagName; GUIStyle tagStyle = stopRequested ? nodeCapsuleStopRequested : (failed ? nodeCapsuleFailed : nodeCapsuleGray); bool drawLabel = !string.IsNullOrEmpty(node.Label); string label = node.Label; if (node is BlackboardCondition) { BlackboardCondition nodeBlackboardCond = node as BlackboardCondition; tagName = nodeBlackboardCond.Key + " " + operatorToString[nodeBlackboardCond.Operator] + " " + nodeBlackboardCond.Value; GUI.backgroundColor = new Color(0.9f, 0.9f, 0.6f); } else { if (node is Composite) { GUI.backgroundColor = new Color(0.3f, 1f, 0.1f); } if (node is Decorator) { GUI.backgroundColor = new Color(0.3f, 1f, 1f); } if (node is Task) { GUI.backgroundColor = new Color(0.5f, 0.1f, 0.5f); } if (node is ObservingDecorator) { GUI.backgroundColor = new Color(0.9f, 0.9f, 0.6f); } nameToTagString.TryGetValue(node.Name, out tagName); } if ((node is Container) && ((Container)node).Collapse) { if (!drawLabel) { drawLabel = true; label = tagName; } tagName = "..."; GUI.backgroundColor = new Color(0.4f, 0.4f, 0.4f); } if (string.IsNullOrEmpty(tagName)) { tagName = node.Name; } if (!drawLabel) { GUILayout.Label(tagName, tagStyle); } else { GUILayout.Label("(" + tagName + ") " + label, tagStyle); // Reset background color GUI.backgroundColor = Color.white; } GUILayout.FlexibleSpace(); // Draw Buttons if (node.CurrentState == Node.State.ACTIVE) { if (GUILayout.Button("stop", EditorStyles.miniButton)) { node.Stop(); } } else if (node is Root) { GUI.color = new Color(1f, 1f, 1f, 1f); if (GUILayout.Button("start", EditorStyles.miniButton)) { node.Start(); } GUI.color = new Color(1f, 1f, 1f, 0.3f); } // Draw Stats GUILayout.Label((node.DebugNumStoppedCalls > 0 ? node.DebugLastResult.ToString() : "") + " | " + node.DebugNumStartCalls + " , " + node.DebugNumStopCalls + " , " + node.DebugNumStoppedCalls, smallTextStyle); } EditorGUILayout.EndHorizontal(); // Draw the lines if (connected) { Rect rect = GUILayoutUtility.GetLastRect(); Handles.color = new Color(0f, 0f, 0f, 1f); Handles.BeginGUI(); float midY = 4 + (rect.yMin + rect.yMax) / 2f; Handles.DrawLine(new Vector2(rect.xMin - 5, midY), new Vector2(rect.xMin, midY)); Handles.EndGUI(); } }