Exemple #1
0
        private void SelectResult(GraphEditor editor, int index)
        {
            var node = results[index].MakeNode();

            editor.AddNode(node, spawnPosition);

            if (context != null)
            {
                // Attempt to connect the two nodes
                foreach (var other in node.GetSockets())
                {
                    if (other.IsInput(editor.Graph) == contextWantsInput &&
                        other.GetSocketType(editor.Graph) == contextWantsType)
                    {
                        editor.Graph.Links.Add(editor.Graph, context, other);
                        break;
                    }
                }
            }
        }
Exemple #2
0
        private void DrawVariableResults(GraphEditor editor)
        {
            var variables = editor.Graph.Variables;

            if (variables.AsList().Count == 0)
            {
                XGUI.ResetToStyle(GUI.skin.label);
                XGUI.Alignment = TextAnchor.LowerCenter;
                XGUI.Enabled   = false;
                XGUI.FontStyle = FontStyle.Italic;
                XGUI.Label("No variables", XGUI.MaxHeight(30));
            }
            else
            {
                varScrollPos = GUILayout.BeginScrollView(varScrollPos);
                foreach (var variable in variables)
                {
                    XGUI.ResetToStyle(null);
                    XGUI.BeginHorizontal();

                    XGUI.ResetToStyle(GUI.skin.button);
                    if (XGUI.Button("Get", XGUI.Width(40)))
                    {
                        var node = ScriptableObject.CreateInstance <DynamicNode>();
                        node.name = "Get";

                        node.AddOutputSocket(new DynamicSocket(
                                                 variable.Name, variable.Value.Type, variable.Name));

                        node.AddEvalInvoke(new EvalInvoke(
                                               variable.Name, variable.Name, variable.Name, InvokeType.GetVar));
                        editor.AddNode(node, spawnPosition);
                    }
                    if (XGUI.Button("Set", XGUI.Width(40)))
                    {
                        var node = ScriptableObject.CreateInstance <DynamicNode>();
                        node.name = "Set";
                        node.SetInputWidth(60);

                        node.AddInputSocket(new DynamicSocket(
                                                "Exec", typeof(ExecType), "execIn"));
                        node.AddInputSocket(new DynamicSocket(
                                                "Value", variable.Value.Type, "value", SocketFlags.Editable));

                        node.AddOutputSocket(new DynamicSocket(
                                                 "Exec", typeof(ExecType), "execOut"));
                        node.AddOutputSocket(new DynamicSocket(
                                                 variable.Name, variable.Value.Type, variable.Name));

                        node.AddExecInvoke(new ExecInvoke(
                                               "execIn", "execOut", "newValue", variable.Name, variable.Name, InvokeType.SetVar));
                        editor.AddNode(node, spawnPosition);
                    }

                    XGUI.ResetToStyle(GUI.skin.label);
                    XGUI.Label(variable.Name);

                    XGUI.EndHorizontal();
                }

                GUILayout.EndScrollView();
            }
        }