private void AcceptDragAndDrop() { EventType eventType = Event.current.type; bool isAccepted = false; if ((eventType == EventType.DragUpdated || eventType == EventType.DragPerform)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (eventType == EventType.DragPerform) { DragAndDrop.AcceptDrag(); isAccepted = true; } Event.current.Use(); } if (isAccepted && DragAndDrop.objectReferences [0].GetType() == typeof(StateMachine)) { Pasteboard.Copy(new List <Node> () { DragAndDrop.objectReferences [0] as StateMachine }); Pasteboard.Paste(Event.current.mousePosition + scrollPosition, FsmEditor.Active); } }
private void NodeContextMenu(){ if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1){ return; } Node node=MouseOverNode(); if (node == null) { return; } GenericMenu nodeMenu = new GenericMenu (); nodeMenu.AddItem (FsmContent.makeTransition, false, delegate() { fromNode=node; }); if(!node.IsStartNode && !(node is AnyState)){ nodeMenu.AddItem (FsmContent.setAsDefault, false, delegate() { FsmEditorUtility.SetDefaultNode(node,FsmEditor.Active); }); }else{ nodeMenu.AddDisabledItem(FsmContent.setAsDefault); } if (node.GetType () == typeof(State)) { State state = node as State; nodeMenu.AddItem (FsmContent.sequence, state.IsSequence, delegate() { state.IsSequence=!state.IsSequence; }); } if (node.GetType () != typeof(AnyState)) { nodeMenu.AddItem (FsmContent.copy, false, delegate() { Pasteboard.Copy (selection); }); nodeMenu.AddItem (FsmContent.delete, false, delegate() { if (selection.Contains (node)) { foreach (Node mNode in selection) { if(!(mNode is AnyState)){ FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); } else { FsmEditorUtility.DeleteNode (node); } EditorUtility.SetDirty (FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem(FsmContent.copy); nodeMenu.AddDisabledItem(FsmContent.delete); } nodeMenu.ShowAsContext (); Event.current.Use (); }
protected override void CanvasContextMenu () { if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1 || FsmEditor.Active == null){ return; } GenericMenu canvasMenu = new GenericMenu (); canvasMenu.AddItem (FsmContent.createState, false, delegate() { State state= FsmEditorUtility.AddNode<State>(mousePosition,FsmEditor.Active); state.IsStartNode=FsmEditor.Active.GetStartNode() == null; FsmEditorUtility.UpdateNodeColor(state); }); canvasMenu.AddItem (FsmContent.createSubFsm, false, delegate() { StateMachine stateMachine=FsmEditorUtility.AddNode<StateMachine>(mousePosition,FsmEditor.Active); stateMachine.IsStartNode=FsmEditor.Active.GetStartNode() == null; FsmEditorUtility.UpdateNodeColor(stateMachine); }); canvasMenu.AddItem (FsmContent.copy, false, delegate() { Pasteboard.Copy(new List<Node>(){FsmEditor.Active}); }); if (Pasteboard.CanPaste ()) { canvasMenu.AddItem (FsmContent.paste, false, delegate() { Pasteboard.Paste(mousePosition,FsmEditor.Active); }); } canvasMenu.AddSeparator (""); if (Selection.activeGameObject != null) { canvasMenu.AddItem (FsmContent.addToSelection, false, delegate() { foreach(GameObject go in Selection.gameObjects){ ICodeBehaviour behaviour = go.AddComponent<ICodeBehaviour>(); behaviour.stateMachine = FsmEditor.Active.Root; EditorUtility.SetDirty(behaviour); } SelectGameObject(Selection.activeGameObject); }); canvasMenu.AddItem (FsmContent.bindToGameObject, false, delegate() { foreach(GameObject go in Selection.gameObjects){ ICodeBehaviour behaviour = go.AddComponent<ICodeBehaviour>(); behaviour.stateMachine = (StateMachine)FsmUtility.Copy(FsmEditor.Active.Root);//FsmEditor.Active.Root; EditorUtility.SetDirty(behaviour); } SelectGameObject(Selection.activeGameObject); }); } else { canvasMenu.AddDisabledItem(FsmContent.addToSelection); canvasMenu.AddDisabledItem(FsmContent.bindToGameObject); } if (FsmEditor.Active.Root != null && !EditorUtility.IsPersistent(FsmEditor.Active.Root)) { canvasMenu.AddItem (FsmContent.saveAsAsset, false, delegate() { string mPath = EditorUtility.SaveFilePanelInProject ( "Save StateMachine as Asset", "New StateMachine.asset", "asset", ""); if(mPath != null){ StateMachine stateMachine=(StateMachine)FsmUtility.Copy(FsmEditor.Active.Root); AssetDatabase.CreateAsset(stateMachine,mPath); AssetDatabase.SaveAssets(); FsmEditorUtility.ParentChilds(stateMachine); } }); } else { canvasMenu.AddDisabledItem(FsmContent.saveAsAsset); } canvasMenu.ShowAsContext (); }
private void NodeContextMenu () { if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1) { return; } Node node = MouseOverNode (); if (node == null) { return; } GenericMenu nodeMenu = new GenericMenu (); if (Application.isPlaying && this.active != null && this.active.Owner != null && node != this.active.Owner.ActiveNode) { nodeMenu.AddItem (new GUIContent ("Execute"), false, delegate { this.active.Owner.SetNode (node); }); } nodeMenu.AddItem (FsmContent.makeTransition, false, delegate() { fromNode = node; }); if (!node.IsStartNode && !(node is AnyState)) { nodeMenu.AddItem (FsmContent.setAsDefault, false, delegate() { FsmEditorUtility.SetDefaultNode (node, FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem (FsmContent.setAsDefault); } if (node.GetType () == typeof(State)) { State state = node as State; nodeMenu.AddItem (FsmContent.sequence, state.IsSequence, delegate() { state.IsSequence = !state.IsSequence; }); } if (node.GetType () != typeof(AnyState)) { nodeMenu.AddItem (FsmContent.moveToSubStateMachine, false, delegate() { StateMachine stateMachine = FsmEditorUtility.AddNode<StateMachine> (mousePosition, FsmEditor.Active); Pasteboard.Copy (selection); Pasteboard.Paste (mousePosition, stateMachine); foreach (Node mNode in selection) { if (!(mNode is AnyState)) { FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); EditorUtility.SetDirty (FsmEditor.Active); }); if (FsmEditor.Active.Parent != null) { nodeMenu.AddItem (FsmContent.moveToParentStateMachine, false, delegate() { Pasteboard.Copy (selection); Pasteboard.Paste (mousePosition, FsmEditor.Active.Parent); foreach (Node mNode in selection) { if (!(mNode is AnyState)) { FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); EditorUtility.SetDirty (FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem (FsmContent.moveToParentStateMachine); } nodeMenu.AddItem (FsmContent.copy, false, delegate() { Pasteboard.Copy (selection); }); nodeMenu.AddItem (FsmContent.delete, false, delegate() { if (selection.Contains (node)) { foreach (Node mNode in selection) { if (!(mNode is AnyState)) { FsmEditorUtility.DeleteNode (mNode); } } selection.Clear (); UpdateUnitySelection (); } else { FsmEditorUtility.DeleteNode (node); } EditorUtility.SetDirty (FsmEditor.Active); }); } else { nodeMenu.AddDisabledItem (FsmContent.copy); nodeMenu.AddDisabledItem (FsmContent.delete); } nodeMenu.ShowAsContext (); Event.current.Use (); }