Example #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="nodeRect">The rectangle of the node</param>
 /// <param name="nodeData">Custom data assigned to the node</param>
 /// <param name="menu">The context menu for right clicks</param>
 public Node(Rect nodeRect, System.Object nodeData = null,
             GUIGenericMenu menu = null)
 {
     NodeRect    = nodeRect;
     NodeData    = nodeData;
     ContextMenu = menu;
 }
Example #2
0
        private void InitializeContextMenus()
        {
            ConnectNodeInputMode nodeConnector = NodeEditor.GetInputMode <ConnectNodeInputMode>();

            nodeContextMenu = new GUIGenericMenu();

            if (EditorApplication.isPlaying)
            {
                nodeContextMenu.AddMenuItem(string.Empty, "Load Scene", LoadScene);
                nodeContextMenu.AddSeparator();
            }
            else
            {
                nodeContextMenu.AddMenuItem(string.Empty, "Load Scene", LoadSceneInEditor, OpenSceneMode.Single);
                nodeContextMenu.AddMenuItem(string.Empty, "Load Scene Additive", LoadSceneInEditor, OpenSceneMode.Additive);
                nodeContextMenu.AddSeparator();
            }

            nodeContextMenu.AddMenuItem(string.Empty,
                                        "Make Transition", nodeConnector.Activate);
            nodeContextMenu.AddMenuItem(string.Empty, "Set as Entry", SetAsEntryNode);
            nodeContextMenu.AddSeparator();
            nodeContextMenu.AddMenuItem(string.Empty, "Delete", DeleteEditorComponent, false);
            nodeContextMenu.AddMenuItem(string.Empty, "Delete and Exclude Scene", DeleteEditorComponent, true);

            connectorContextMenu = new GUIGenericMenu();
            connectorContextMenu.AddMenuItem(string.Empty, "Delete", DeleteEditorComponent);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="menu">Context menu for right clicking</param>
        /// <param name="connectedNodes">List of nodes to assign to this connection</param>
        public Connector(GUIGenericMenu menu, params Node[] connectedNodes)
        {
            ContextMenu = menu;

            foreach (Node node in connectedNodes)
            {
                AddNode(node);
            }
        }
        /// <summary>
        /// Clears the data associated with the current context menu
        /// </summary>
        public void ClearContextMenu()
        {
            if (activeContextMenu != null)
            {
                activeContextMenu.Hide();
            }

            activeContextMenu = null;
            contextMenuOwner  = null;
        }
Example #5
0
        /// <summary>
        /// Clean up
        /// </summary>
        protected override void OnDeactivated()
        {
            if (activeMenu == null)
            {
                return;
            }

            activeMenu.OnHide -= ActiveMenu_OnHide;
            activeMenu         = null;
            NodeEditor.ClearContextMenu();
        }
Example #6
0
        private void PopulateConnections(GUIGenericMenu contextMenu)
        {
            SceneNodeCollection nodes = SerializedManager.SceneNodes;

            List <TransitionConnector> madeTransitions = new List <TransitionConnector>();

            foreach (SceneNode node in nodes.SceneNodes)
            {
                foreach (SceneTransition transition in node.SceneInfo.Transitions)
                {
                    TransitionConnector existingOut = madeTransitions.Find((x) =>
                    {
                        return(((SceneNode)x.GetStartNode()).SceneId == node.SceneId &&
                               ((SceneNode)x.GetEndNode()).SceneId == transition.DestinationSceneId);
                    });

                    if (existingOut != null)
                    {
                        existingOut.ConnectionCount++;
                        continue;
                    }

                    TransitionConnector existingIn = madeTransitions.Find((x) =>
                    {
                        return(((SceneNode)x.GetStartNode()).SceneId == transition.DestinationSceneId &&
                               ((SceneNode)x.GetEndNode()).SceneId == node.SceneId);
                    });

                    TransitionConnector newConnection = new TransitionConnector();

                    newConnection.ContextMenu = contextMenu;
                    newConnection.AddNode(node);

                    if (node.SceneId == transition.DestinationSceneId)
                    {
                        AddSelfTransitionNodes(newConnection, node);
                    }

                    newConnection.AddNode(nodes.SceneNodes.Find((x) =>
                                                                x.SceneId == transition.DestinationSceneId));

                    if (existingIn != null)
                    {
                        newConnection.ShiftOver = true;
                        existingIn.ShiftOver    = true;
                    }

                    NodeEditor.AddConnector(newConnection);
                    madeTransitions.Add(newConnection);
                }
            }
        }
        /// <summary>
        /// Change the context menu that is currently active
        /// </summary>
        /// <param name="newMenu">The menu to show</param>
        /// <param name="owner">The object that the context menu was opened on</param>
        public void ChangeActiveContextMenu(GUIGenericMenu newMenu, System.Object owner)
        {
            if (activeContextMenu != null)
            {
                activeContextMenu.Hide();
            }

            activeContextMenu = newMenu;
            contextMenuOwner  = owner;

            if (activeContextMenu != null)
            {
                activeContextMenu.Show(owner);
            }
        }
Example #8
0
        /// <summary>
        /// Helper for updating the active menu cached in this class
        /// and in the Node Editor
        /// </summary>
        /// <param name="menu">The menu to be set</param>
        /// <param name="menuOwner">The owner of the menu</param>
        protected void UpdateActiveMenu(GUIGenericMenu menu, System.Object menuOwner)
        {
            if (activeMenu != null)
            {
                activeMenu.OnHide -= ActiveMenu_OnHide;
                activeMenu.Hide();
            }

            activeMenu = menu;

            if (activeMenu != null)
            {
                activeMenu.OnHide += ActiveMenu_OnHide;
                NodeEditor.ChangeActiveContextMenu(menu, menuOwner);
            }
        }
Example #9
0
    private void OnGUI()
    {
        if (nodeEditor == null)
        {
            GUIGenericMenu nodeMenu = new GUIGenericMenu();

            nodeMenu.AddMenuItem("Make Transition", StartConnection);
            nodeMenu.AddMenuItem("Create Node", CreateNewNode);
            nodeMenu.AddMenuItem("Create/Items/", "Node");
            nodeMenu.AddMenuItem("Delete Node", Delete);

            nodeEditor = new NodeEditor();
            nodeEditor.EnableBoxSelect();
            nodeEditor.EnableNodeSelect();
            nodeEditor.EnableConnectorSelect();
            nodeEditor.EnableNodeDrag();
            nodeEditor.EnableNodeRightClick();
            nodeEditor.EnableConnectorRightClick();
            nodeEditor.EnableInputMode <ConnectorMakerMode>(2);

            connectorMode = new ConnectNodeInputMode(nodeEditor, 2);
            nodeEditor.EnableInputMode(connectorMode);

            Node node1 = new TextNode(Vector2.zero, "Test", null, nodeMenu);
            Node node2 = new TextNode(Vector2.one * 50f, "Test 2", null, nodeMenu);

            GUIGenericMenu connectMenu = new GUIGenericMenu();
            connectMenu.AddMenuItem("Delete Connection", DeleteConnection);
            nodeEditor.AddNode(node1);
            nodeEditor.AddNode(node2);
            //nodeEditor.AddConnector(new Connector(connectMenu, node1, node2));
            // nodeEditor.AddConnector(new Connector(connectMenu, node1, nodeEditor.MouseNode));
        }

        if (nodeEditor.OnGUI(position.WithPosition(Vector2.zero)))
        {
            Repaint();
        }
    }
Example #10
0
        /// <summary>
        /// Fills the node editor with nodes that represent the scene data
        /// </summary>
        /// <param name="nodeContextMenu">The context menu to be given to each node</param>
        private void PopulateNodes(GUIGenericMenu nodeContextMenu)
        {
            SceneNodeCollection nodes = SerializedManager.SceneNodes;

            foreach (SceneNode node in nodes.SceneNodes)
            {
                node.ContextMenu = nodeContextMenu;

                node.IsEntryScene = SerializedManager.IsEntryScene(node.SceneId);

                if (node.SceneId == SceneManagerController.ANY_SCENE_ID)
                {
                    node.SceneInfo = SerializedManager.TargetManager.AnyScene;
                }
                else
                {
                    node.SceneInfo = SerializedManager.TargetManager.GetSceneById(node.SceneId);
                }

                NodeEditor.AddNode(node);
            }
        }
Example #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="position">The position of the node</param>
 /// <param name="nodeData">Custom data assigned to the node</param>
 /// <param name="menu">The context menu for right clicks</param>
 public Node(Vector2 position, System.Object nodeData = null,
             GUIGenericMenu menu = null)
     : this(new Rect(position, Vector2.one), nodeData, menu)
 {
 }
Example #12
0
 public TextNode(Rect nodeRect, string nodeText,
                 System.Object nodeData = null, GUIGenericMenu contextMenu = null)
     : base(nodeRect, nodeData, contextMenu)
 {
     NodeText = nodeText;
 }
Example #13
0
 public TextNode(Vector2 position, string nodeText,
                 System.Object nodeData = null, GUIGenericMenu contextMenu = null)
     : this(new Rect(position, Vector2.one), nodeText, nodeData, contextMenu)
 {
 }