Exemple #1
0
        public static void Initialize(string handleName, NodeHandleData data)
        {
            NodeHandleEditor window = CreateInstance <NodeHandleEditor>();

            window.handleData   = data;
            window.titleContent = new GUIContent("Handle Editor: " + handleName);
            window.ShowUtility();
        }
Exemple #2
0
        //The GUI call for this Window
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(10f, 10f, 200f, position.height - 20f));

            nodeName        = EditorGUI.TextField(new Rect(0f, 0f, 200f, 20f), nodeName);
            nodeDescription = EditorGUI.TextArea(new Rect(0f, 30f, 200f, 60f), nodeDescription);

            EditorGUI.BeginChangeCheck();

            nodeSize.x = EditorGUI.DelayedFloatField(new Rect(0f, 100f, 95f, 20f), nodeSize.x);
            nodeSize.y = EditorGUI.DelayedFloatField(new Rect(105f, 100f, 95f, 20f), nodeSize.y);

            if (EditorGUI.EndChangeCheck() && viewSize != nodeSize)
            {
                nodeSize = Northwind.Essentials.VectorMath.Step(nodeSize, 16f);

                oldSize = viewSize;
                timer   = blendTime;
            }

            fixedSize = EditorGUI.Toggle(new Rect(0f, 120f, 200f, 20f), new GUIContent("Fixed"), fixedSize);

            nodeColor = EditorGUI.ColorField(new Rect(0f, 150f, 200f, 20f), new GUIContent("Color"), nodeColor);

            EditorGUI.BeginChangeCheck();

            // Inputs and Outputs
            EditorGUI.LabelField(new Rect(0f, 180f, 100f, 20f), new GUIContent("Inputs"), GUI.skin.GetStyle("LargeButtonLeft"));

            GUILayout.BeginArea(new Rect(4f, 200f, 96f, 200f), GUI.skin.GetStyle("CN Box"));

            for (int ih = 0; ih < inputHandles.Count; ih++)
            {
                if (GUI.Button(new Rect(4f, 4f + ih * 24f, 88f, 20f), "Input " + ih))
                {
                    NodeHandleEditor.Initialize("Input " + ih, inputHandles[ih]);
                }
            }

            GUILayout.EndArea();

            if (GUI.Button(new Rect(0f, 400f, 50f, 20f), "+", GUI.skin.GetStyle("LargeButtonLeft")))
            {
                if (inputHandles.Count < 8)
                {
                    inputHandles.Add(new NodeHandleData());
                }
            }

            if (GUI.Button(new Rect(50f, 400f, 50f, 20f), "-", GUI.skin.GetStyle("LargeButtonMid")))
            {
                inputHandles.RemoveAt(inputHandles.Count - 1);
            }

            EditorGUI.LabelField(new Rect(100f, 180f, 100f, 20f), new GUIContent("Outputs"), GUI.skin.GetStyle("LargeButtonRight"));

            GUILayout.BeginArea(new Rect(100f, 200f, 96f, 200f), GUI.skin.GetStyle("CN Box"));

            for (int oh = 0; oh < outputHandles.Count; oh++)
            {
                if (GUI.Button(new Rect(4f, 4f + oh * 24f, 88f, 20f), "Output " + oh))
                {
                    NodeHandleEditor.Initialize("Output " + oh, outputHandles[oh]);
                }
            }

            GUILayout.EndArea();

            if (GUI.Button(new Rect(100f, 400f, 50f, 20f), "+", GUI.skin.GetStyle("LargeButtonMid")))
            {
                if (outputHandles.Count < 8)
                {
                    outputHandles.Add(new NodeHandleData());
                }
            }

            if (GUI.Button(new Rect(150f, 400f, 50f, 20f), "-", GUI.skin.GetStyle("LargeButtonRight")))
            {
                outputHandles.RemoveAt(outputHandles.Count - 1);
            }

            if (EditorGUI.EndChangeCheck())
            {
                readd = true;
            }


            // Creation buttons
            if (GUI.Button(new Rect(0f, position.height - 40f, 95f, 20f), "Create"))
            {
                string template = GetNodeTemplate();

                // Node Data
                template = template.Replace("#NODE_NAME#", nodeName);
                template = template.Replace("#NODE_DESCRIPTION#", nodeDescription);
                template = template.Replace("#NODE_WIDTH#", nodeSize.x + "f");
                template = template.Replace("#NODE_HEIGHT#", nodeSize.y + "f");
                template = template.Replace("#NODE_FIXED#", fixedSize ? "true" : "false");
                template = template.Replace("#NODE_COLOR#", nodeColor.r + "f, " + nodeColor.g + "f, " + nodeColor.b + "f");

                // Class Data
                template = template.Replace("#NODE_CLASSNAME#", nodeName.Replace(" ", ""));

                // Input Handles
                if (inputHandles.Count <= 0)
                {
                    template = template.Replace("#NODE_INPUT_HANDLES#", "// No Inputs");
                }
                else
                {
                    string handles = "";

                    for (int ih = 0; ih < inputHandles.Count; ih++)
                    {
                        string handleTemplate = (ih > 0 ? "\t\t" : "") + GetHandleTemplate();

                        handleTemplate = handleTemplate.Replace("#HANDLE_ID#", ih + "");
                        handleTemplate = handleTemplate.Replace("#HANDLE_CONNECTION#", "ConnectionType.Input");
                        handleTemplate = handleTemplate.Replace("#HANDLE_Y#", inputHandles[ih].y + "f");
                        handleTemplate = handleTemplate.Replace("#HANDLE_FIXED#", inputHandles[ih].fixedPosition ? "true" : "false");
                        handleTemplate = handleTemplate.Replace("#HANDLE_TOOLTIP#", inputHandles[ih].tooltip);

                        handleTemplate = handleTemplate.Replace("#HANDLE_CONNECTION_SMALL#", "input");

                        handles += handleTemplate + "\n\n";
                    }

                    template = template.Replace("#NODE_INPUT_HANDLES#", handles);
                }

                // Output Handles
                if (outputHandles.Count <= 0)
                {
                    template = template.Replace("#NODE_OUTPUT_HANDLES#", "// No Outputs");
                }
                else
                {
                    string handles = "";

                    for (int oh = 0; oh < outputHandles.Count; oh++)
                    {
                        string handleTemplate = (oh > 0 ? "\t\t" : "") + GetHandleTemplate();

                        handleTemplate = handleTemplate.Replace("#HANDLE_ID#", oh + "");
                        handleTemplate = handleTemplate.Replace("#HANDLE_CONNECTION#", "ConnectionType.Output");
                        handleTemplate = handleTemplate.Replace("#HANDLE_Y#", outputHandles[oh].y + "f");
                        handleTemplate = handleTemplate.Replace("#HANDLE_FIXED#", outputHandles[oh].fixedPosition ? "true" : "false");
                        handleTemplate = handleTemplate.Replace("#HANDLE_TOOLTIP#", outputHandles[oh].tooltip);

                        handleTemplate = handleTemplate.Replace("#HANDLE_CONNECTION_SMALL#", "output");

                        handles += handleTemplate + "\n\n";
                    }

                    template = template.Replace("#NODE_OUTPUT_HANDLES#", handles);
                }

                FileOperator.SaveToStringFile(template, FileOperator.GetProjectPath() + GetSelectedPathOrFallback() + "/" + nodeName.Replace(" ", "") + "Node.cs");

                template = GetEditorTemplate();

                template = template.Replace("#NODE_CLASS#", nodeName.Replace(" ", "") + "Node");

                FileOperator.SaveToStringFile(template, FileOperator.GetProjectPath() + GetSelectedPathOrFallback() + "/Editor/" + nodeName.Replace(" ", "") + "NodeEditor.cs");

                AssetDatabase.Refresh();

                Close();
            }

            if (GUI.Button(new Rect(105f, position.height - 40f, 95f, 20f), "Cancel"))
            {
                Close();
            }

            GUILayout.EndArea();

            //GUILayout.Label(GetSelectedPathOrFallback());

            GUILayout.BeginArea(new Rect(220f, 0f, position.width - 220f, position.height), GUI.skin.GetStyle("GroupBox"));

            NodePreviewer.DrawNodePreview(new Vector2((position.width - 220f) / 2f - (viewSize.x + addedDemoSize.x + 64f) / 2f, position.height / 2f - (viewSize.y + addedDemoSize.y + 32f) / 2f), null, new NodeDataAttribute(nodeName, nodeDescription, viewSize.x + addedDemoSize.x, viewSize.y + addedDemoSize.y, red: nodeColor.r, green: nodeColor.g, blue: nodeColor.b),
                                          tempHandles.ToArray());

            GUILayout.EndArea();
        }