public override void DrawWindow(Node b) { if (b.stateRef.currentState == null) { EditorGUILayout.LabelField("Add State to Modify:"); } else { if (!b.collapse) { } else { b.windowRect.height = 100; } b.collapse = EditorGUILayout.Toggle("Collapse All", b.collapse); } b.stateRef.currentState = (State)EditorGUILayout.ObjectField(b.stateRef.currentState, typeof(State), false); if (b.previousCollapse != b.collapse) { b.previousCollapse = b.collapse; } if (b.stateRef.previousState != b.stateRef.currentState) { b.isDuplicate = BehaviourNodeEditor.settings.currentGraph.IsStateDuplicate(b); b.stateRef.previousState = b.stateRef.currentState; if (!b.isDuplicate) { Vector3 pos = new Vector3(b.windowRect.x, b.windowRect.y, 0); pos.x += b.windowRect.width * 2; SetupReorderableLists(b); for (int i = 0; i < b.stateRef.currentState.transitions.Count; i++) { pos.y += i * 100; BehaviourNodeEditor.AddTransitionNodeFromTransition(b.stateRef.currentState.transitions[i], b, pos); } BehaviourNodeEditor.forceSetDirty = true; } } if (b.isDuplicate) { EditorGUILayout.LabelField("State is a Duplicate!"); b.windowRect.height = 100; return; } if (b.stateRef.currentState != null) { b.isAssigned = true; if (!b.collapse) { if (b.stateRef.serializedState == null) { SetupReorderableLists(b); } float standard = 150; b.stateRef.serializedState.Update(); b.showActions = EditorGUILayout.Toggle("Show Actions ", b.showActions); if (b.showActions) { EditorGUILayout.LabelField(""); b.stateRef.onFixedUpdateList.DoLayoutList(); EditorGUILayout.LabelField(""); b.stateRef.onUpdateList.DoLayoutList(); standard += 100 + 40 + (b.stateRef.onUpdateList.count + b.stateRef.onFixedUpdateList.count) * 20; } b.showEnterExit = EditorGUILayout.Toggle("Show Enter/Exit ", b.showEnterExit); if (b.showEnterExit) { EditorGUILayout.LabelField(""); b.stateRef.onEnterList.DoLayoutList(); EditorGUILayout.LabelField(""); b.stateRef.onExitList.DoLayoutList(); standard += 100 + 40 + (b.stateRef.onEnterList.count + b.stateRef.onExitList.count) * 20; } b.stateRef.serializedState.ApplyModifiedProperties(); b.windowRect.height = standard; } } else { b.isAssigned = false; } }
//Initialize editor window title and size static void ShowEditor() { editor = GetWindow <BehaviourNodeEditor>(); editor.titleContent = new GUIContent("Node Editor"); editor.minSize = new Vector2(800, 800); }
public override void DrawCurve(Node b) { Rect rect = b.windowRect; rect.y += b.windowRect.height * .5f; rect.width = 1; rect.height = 1; Node e = BehaviourNodeEditor.settings.currentGraph.GetNodeWithIndex(b.enterNode); if (e == null) { BehaviourNodeEditor.settings.currentGraph.DeleteNode(b.id); } else { Color targetColor = Color.green; if (!b.isAssigned || b.isDuplicate) { targetColor = Color.red; } Rect r = e.windowRect; BehaviourNodeEditor.DrawNodeCurve(r, rect, true, targetColor); } if (b.isDuplicate) { return; } if (b.targetNode > 0) { Node t = BehaviourNodeEditor.settings.currentGraph.GetNodeWithIndex(b.targetNode); if (t == null) { b.targetNode = -1; } else { rect = b.windowRect; rect.x += rect.width; Rect endRect = t.windowRect; endRect.x -= endRect.width * .5f; Color targetColor = Color.green; if (t.drawNode is DrawStateNode) { if (!t.isAssigned || t.isDuplicate) { targetColor = Color.red; } } else { if (!t.isAssigned) { targetColor = Color.red; } else { targetColor = Color.yellow; } } BehaviourNodeEditor.DrawNodeCurve(rect, endRect, false, targetColor); } } }