Example #1
0
 public override void NodeDeleted(BaseNode node)
 {
     if (node.Equals(inputNode))
     {
         inputNode = null;
     }
 }
Example #2
0
        public override void SetInput(BaseInputNode input, Vector2 clickPos)
        {
            clickPos.x -= windowRect.x;
            clickPos.y -= windowRect.y;

            if (inputNodeRect.Contains(clickPos))
            {
                inputNode = input;
            }
        }
Example #3
0
        public override BaseInputNode CLickedOnIput(Vector2 pos)
        {
            BaseInputNode retVal = null;

            pos.x -= windowRect.x;
            pos.y -= windowRect.y;

            if (inputNodeRect.Contains(pos))
            {
                retVal    = inputNode;
                inputNode = null;
            }

            return(retVal);
        }
        private void OnGUI()
        {
            Event e = Event.current;

            mousePos = e.mousePosition;

            if (e.button == 1 && !makeTransitionMode)
            {
                if (e.type == EventType.MouseDown)
                {
                    bool clickedOnWindow = false;
                    int  selectIndex     = -1;

                    for (int i = 0; i < windows.Count; i++)
                    {
                        if (windows[i].windowRect.Contains(mousePos))
                        {
                            selectIndex     = i;
                            clickedOnWindow = true;
                            break;
                        }
                    }

                    if (!clickedOnWindow)
                    {
                        GenericMenu menu = new GenericMenu();

                        menu.AddItem(new GUIContent("Add Input Node"), false, ContextCallback, "inputNode");
                        menu.AddItem(new GUIContent("Add Output Node"), false, ContextCallback, "outputNode");
                        menu.AddItem(new GUIContent("Calculation Node"), false, ContextCallback, "calcNode");
                        menu.AddItem(new GUIContent("Comparison Node"), false, ContextCallback, "compNode");

                        menu.ShowAsContext();
                        e.Use();
                    }
                    else
                    {
                        GenericMenu menu = new GenericMenu();

                        menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, "makeTransition");
                        menu.AddSeparator("");
                        menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode");

                        menu.ShowAsContext();
                        e.Use();
                    }
                }
            }
            else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode)
            {
                bool clickedOnWindow = false;
                int  selectIndex     = -1;

                for (int i = 0; i < windows.Count; i++)
                {
                    if (windows[i].windowRect.Contains(mousePos))
                    {
                        selectIndex     = i;
                        clickedOnWindow = true;
                        break;
                    }
                }

                if (clickedOnWindow && !windows[selectIndex].Equals(selectedNode))
                {
                    windows[selectIndex].SetInput((BaseInputNode)selectedNode, mousePos);
                    makeTransitionMode = false;
                    selectedNode       = null;
                }

                if (!clickedOnWindow)
                {
                    makeTransitionMode = false;
                    selectedNode       = null;
                }

                e.Use();
            }
            else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode)
            {
                bool clickedOnWindow = false;
                int  selectIndex     = -1;

                for (int i = 0; i < windows.Count; i++)
                {
                    if (windows[i].windowRect.Contains(mousePos))
                    {
                        selectIndex     = i;
                        clickedOnWindow = true;
                        break;
                    }
                }

                if (clickedOnWindow)
                {
                    BaseInputNode nodeToChange = windows[selectIndex].CLickedOnIput(mousePos);

                    if (nodeToChange != null)
                    {
                        selectedNode       = nodeToChange;
                        makeTransitionMode = true;
                    }
                }
            }

            if (makeTransitionMode && selectedNode != null)
            {
                Rect mouseRect = new Rect(e.mousePosition.x, mousePos.y, 10, 10);
                DrawNodeCurve(selectedNode.windowRect, mouseRect);
                Repaint();
            }

            foreach (BaseNode n in windows)
            {
                n.DrawCurves();
            }

            BeginWindows();

            for (int i = 0; i < windows.Count; i++)
            {
                windows[i].windowRect = GUI.Window(i, windows[i].windowRect, DrawNodeWindow, windows[i].windowTitle);
            }

            EndWindows();
        }
 public virtual void SetInput(BaseInputNode input, Vector2 clickPos)
 {
 }