private void ContextCallBack(object _object) { UserInteractions interactions = (UserInteractions)_object; switch (interactions) { case UserInteractions.ADDSTATE: StateNode stateNode = new StateNode { windowRectangle = new Rect(currentMousePosition.x, currentMousePosition.y, 200, 250), windowTitle = "State" }; windows.Add(stateNode); break; case UserInteractions.CREATETRANSITION: if (currentSelectedNode is StateNode) { StateNode node = (StateNode)currentSelectedNode; Transition transition = node.CreateTransition(); CreateTransitionNode(node.currentState.transitions.Count, transition, node); } break; case UserInteractions.DELETENODE: if (currentSelectedNode is StateNode) { StateNode targetNode = (StateNode)currentSelectedNode; targetNode.ClearReferences(); windows.Remove(targetNode); } if (currentSelectedNode is TransitionNode) { TransitionNode target = (TransitionNode)currentSelectedNode; windows.Remove(target); if (target.startState.currentState.transitions.Contains(target.targetTransition)) { target.startState.currentState.transitions.Remove(target.targetTransition); } } if (currentSelectedNode is CommentNode) { windows.Remove(currentSelectedNode); } break; case UserInteractions.COMMENTNODE: CommentNode commentNode = new CommentNode { windowRectangle = new Rect(currentMousePosition.x, currentMousePosition.y, 150, 75), windowTitle = "Comment" }; windows.Add(commentNode); break; default: break; } }
private void ModifyExistingNode(Event _event) { GenericMenu genericMenu = new GenericMenu(); if (currentSelectedNode is StateNode) { StateNode stateNode = (StateNode)currentSelectedNode; if (stateNode.currentState != null) { genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Create Transition"), false, ContextCallBack, UserInteractions.CREATETRANSITION); } else { genericMenu.AddSeparator(""); genericMenu.AddDisabledItem(new GUIContent("Create Transition")); } genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Delete State"), false, ContextCallBack, UserInteractions.DELETENODE); } if (currentSelectedNode is TransitionNode) { genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Delete Condition"), false, ContextCallBack, UserInteractions.DELETENODE); } if (currentSelectedNode is CommentNode) { genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Delete Comment"), false, ContextCallBack, UserInteractions.DELETENODE); } genericMenu.ShowAsContext(); _event.Use(); }
public static TransitionNode CreateTransitionNode(int _index, Transition _transition, StateNode _from) { Rect fromRectangle = _from.windowRectangle; fromRectangle.x += 50; float targetY = fromRectangle.y - fromRectangle.height; if (_from.currentState != null) { targetY += (_index * 100); } fromRectangle.y = targetY; TransitionNode transitionNode = CreateInstance <TransitionNode>(); transitionNode.Initialize(_from, _transition); transitionNode.windowRectangle = new Rect(fromRectangle.x + 200 + 100, fromRectangle.y + (fromRectangle.height * .7f), 200, 80); transitionNode.windowTitle = "Condition Check"; windows.Add(transitionNode); _from.dependencies.Add(transitionNode); return(transitionNode); }
public void Initialize(StateNode _startState, Transition _transition) { startState = _startState; targetTransition = _transition; }