public static void Init(NodeType nT, object sT, NodePin pin, Vector2 pos, int count = 2)
        {
            Instance             = GetWindow <NodeCreatePopup>(true);
            Instance.maxSize     = new Vector2(200, 100);
            Instance.minSize     = Instance.maxSize;
            Instance.nodeType    = nT;
            Instance.subType     = sT;
            Instance.mouseLoc    = pos;
            Instance.pinToAttach = pin;
            Instance.posInp      = new List <string>();
            Instance.nodeCount   = count;
            SetNCP();

            switch (nT)
            {
            case NodeType.Function:
                FunctionNode.FunctionType f = (FunctionNode.FunctionType)sT;
                Instance.titleContent = new GUIContent("Create " + (f).ToString() + " Node");
                Instance.posInp       = FunctionNode.validCombos[f];
                break;

            case NodeType.Math:
                MathNode.OpType t = (MathNode.OpType)sT;
                Instance.titleContent = new GUIContent("Create " + (t).ToString() + " Node");
                Instance.posInp       = MathNode.validCombos[t];
                Instance.nodeCount    = 2;
                break;

            case NodeType.Control:
                //Instance.titleContent = new GUIContent("Create " + ((ControlNode.ControlType)sT).ToString() + " Node");
                Instance.titleContent = new GUIContent("Create Cast Node");
                Instance.posInp       = new List <string>(ControlNode.castables.Keys);
                break;

            case NodeType.Fetch:
                Instance.titleContent = new GUIContent("Fetch Variable");
                // input from list of variables in database
                break;
            }

            if (Instance.nodeCount < 0 || Instance.posInp.Count == 1)
            {
                Instance.CreateNode();
            }
        }
예제 #2
0
        public override void DrawView(Rect editorRect, Rect PercentRect, Event e, NodeGraph graph)
        {
            base.DrawView(editorRect, PercentRect, e, graph);

            // reposition to fit on screen
            float dy = window.position.height - (body.height + body.y);

            if (dy < 0)
            {
                body.y += dy;
            }
            float dx = window.position.width - (body.width + body.x);

            if (dx < 0)
            {
                body.x += dx;
            }

            ProcessEvents(e);

            Vector2 margin = new Vector2(6, 12);

            size = new Vector2(200, 100);

            //Rect viewRect = new Rect(0, 0, body.width, body.height);
            //Rect ctrlRect = new Rect(x,y, ctrlWidth, ctrlHeight);
            try {
                GUI.Box(body, "", skin.GetStyle("NodeCreationBackground"));
                GUILayout.BeginArea(new Rect(body.x + margin.x, body.y + margin.y,
                                             body.width - 2 * margin.x, body.height - 2 * margin.y));
                scrollPos = GUILayout.BeginScrollView(scrollPos, false, true);
                EditorGUILayout.BeginVertical();
                {
                    if (showDialogues = EditorGUILayout.Foldout(showDialogues, "Dialogue"))
                    {
                        //Debug.Log("In my sack");
                        foreach (ControlNode.ControlType cT in ControlNode.dialogControls)
                        {
                            if (size.y < 400)
                            {
                                size.y += 10;
                            }
                            if (GUILayout.Button(cT.ToString(), skin.GetStyle("NodeCreationButton")))
                            {
                                CreateNode(graph, NodeType.Control, VarType.Exec, cT);
                            }
                        }
                    }

                    if (showControls = EditorGUILayout.Foldout(showControls, "Controls"))
                    {
                        foreach (ControlNode.ControlType cT in cTypes)
                        {
                            if (ControlNode.dialogControls.Contains(cT))
                            {
                                continue;
                            }
                            if (size.y < 400)
                            {
                                size.y += 10;
                            }
                            if (cT != ControlNode.ControlType.Custom &&
                                GUILayout.Button(cT.ToString(), skin.GetStyle("NodeCreationButton")))
                            {
                                if (cT == ControlNode.ControlType.Cast)
                                {
                                    NodeCreatePopup.Init(NodeType.Control, cT, pinToAttach, mouseLoc);
                                    Destroy(true);
                                }
                                else
                                {
                                    CreateNode(graph, NodeType.Control, VarType.Exec, cT);
                                }
                            }
                        }

                        if (GUILayout.Button("Sub Start", skin.GetStyle("NodeCreationButton")))
                        {
                            CreateNode(graph, NodeType.Event, VarType.Object, "New SubStart");
                        }

                        //if (GUILayout.Button("End", skin.GetStyle("NodeCreationButton"))) {
                        //    CreateNode(graph, NodeType.Event, VarType.Object, true);
                        //}
                    }

                    if (showMath = EditorGUILayout.Foldout(showMath, "Math"))
                    {
                        foreach (MathNode.OpType op in ops)
                        {
                            if (size.y < 400)
                            {
                                size.y += 10;
                            }
                            if (GUILayout.Button(op.ToString(), skin.GetStyle("NodeCreationButton")))
                            {
                                // create math FunctionNode
                                MathNode mn = new MathNode();
                                mn.Initialize(); mn.Construct(op, VarType.Float, 2);
                                NodeCreatePopup.Init(NodeType.Math, op, pinToAttach, mouseLoc,
                                                     mn.multiplePins ? -1 : 2);
                                Destroy(true);
                            }
                        }
                    }

                    if (showFunc = EditorGUILayout.Foldout(showFunc, "Functions"))
                    {
                        foreach (FunctionNode.FunctionType cT in fTypes)
                        {
                            if (size.y < 400)
                            {
                                size.y += 10;
                            }
                            if (GUILayout.Button(cT.ToString(), skin.GetStyle("NodeCreationButton")))
                            {
                                CreateNode(graph, NodeType.Function, VarType.Object, cT);
                            }
                        }
                    }
                }

                EditorGUILayout.EndVertical();
                GUILayout.EndScrollView();
                GUILayout.EndArea();
            } catch {
                GUILayout.EndArea();
            }
        }