private void CreateTypeList()
        {
            ConstantTypes types = (ConstantTypes)target;

            list = new ReorderableList(types.current_types, typeof(Type), true, true, true, true);

            list.drawHeaderCallback = rect => {
                EditorGUI.LabelField(rect, "Current Types");
            };

            list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                //rect.y += 2;
                Type last_value = GUIDraw.AnyField(rect, types.current_types[index]);
                if (last_value != types.current_types[index])
                {
                    UndoManager.RecordObject(target, "Type Change");
                    types.current_types[index] = last_value;
                }
                //GUI.Label(rect, types.current_types[index].GetTypeName(true));
            };

            list.onRemoveCallback = (ReorderableList list) => {
                UndoManager.RecordObject(target, "Remove type");
                types.current_types.RemoveAt(list.index);
                list.index = list.count - 1;
            };

            list.onAddDropdownCallback = (Rect buttonRect, ReorderableList list) => {
                if (generic_menu == null)
                {
                    generic_menu = new GenericMenu();
                    foreach (Type type in ReflectionUtils.GetFullTypes())
                    {
                        if (type == null)
                        {
                            continue;
                        }

                        string type_path = type.GetTypePath(true);

                        generic_menu.AddItem(new GUIContent(type_path), false, () => {
                            UndoManager.RecordObject(target, "Add new type");
                            types.current_types.Add(type);
                            CreateTypeList();
                        });
                    }
                }
                generic_menu.ShowAsContext();
            };
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            bool restore_wide_mode = EditorGUIUtility.wideMode;

            EditorGUIUtility.wideMode   = true;
            EditorGUIUtility.labelWidth = 0.0f;
            EditorGUIUtility.fieldWidth = 0.0f;

            if (GUILayout.Button("Open in Editor"))
            {
                GraphEditorWindow.OpenEditor(asset);
            }
            try {
                DrawMenuMode();

                GUILayout.Space(5.0f);

                switch (currentMenu)
                {
                //Graph
                case 0:
                    string title = EditorGUILayout.TextField(asset.title);
                    GUIDraw.GhostLabel(title, "Title...", -2.0f, 5.0f);
                    if (title != asset.title)
                    {
                        UndoManager.RecordObject(target, "Title Change");
                        asset.title = title;
                        GraphEditor.current_validate = true;
                    }
                    GUILayout.Space(3.0f);
                    string subtitle = EditorGUILayout.TextArea(asset.subtitle, GUILayout.MinHeight(50.0f));
                    GUIDraw.GhostLabel(subtitle, "Subtitle...", -2.0f, 5.0f);
                    if (subtitle != asset.subtitle)
                    {
                        UndoManager.RecordObject(target, "Subtitle Change");
                        asset.subtitle = subtitle;
                        GraphEditor.current_validate = true;
                    }
                    GUILayout.Label(string.Format("Nodes: {0}", asset.graph.nodes.Count.ToString()));
                    break;

                //Parameters
                case 1:
                    input_list.DoLayoutList();
                    output_list.DoLayoutList();
                    break;

                //Variables
                case 2:
                    variable_list.DoLayoutList();
                    break;

                //Node Inspector
                case 3:
                    DrawNodeInspector();
                    break;
                }
            }
            catch {
                CreateReorderableLists();
                GraphEditor.current_validate = true;
            }

            if (GUI.changed)
            {
                UndoManager.SetDirty(target);
                GUI.changed = false;
            }

            EditorGUIUtility.wideMode = restore_wide_mode;
        }
示例#3
0
        public override void OnInspectorGUI()
        {
            GraphController controller = (GraphController)target;
            GraphAsset      graph      = controller.graph;

            OnEnableAction  on_enable  = controller.on_enable;
            bool            once       = controller.once;
            float           seconds    = controller.seconds;
            OnDisableAction on_disable = controller.on_disable;

            controller.CopyParameters();

            graph = (GraphAsset)EditorGUILayout.ObjectField(new GUIContent("Graph"), controller.graph, typeof(GraphAsset), false);

            if (controller.graph != graph)
            {
                controller.OnGraphChange(controller.graph, graph);
            }

            if (controller.graph)
            {
                on_enable = (OnEnableAction)EditorGUILayout.EnumPopup(new GUIContent("OnEnable"), controller.on_enable);

                switch (on_enable)
                {
                case OnEnableAction.DoNothing:
                case OnEnableAction.PlayGraph:
                    if (height != 0.0f)
                    {
                        height = 0.0f;
                        EditorUtils.RepaintInspector();
                    }
                    seconds = 0.0f;
                    break;

                case OnEnableAction.WaitForSeconds:
                    GUILayout.BeginVertical("Box");
                    if (height != EditorGUIUtility.singleLineHeight)
                    {
                        height = Mathf.MoveTowards(height, EditorGUIUtility.singleLineHeight, 1.0f);
                        EditorUtils.RepaintInspector();
                    }
                    once    = EditorGUILayout.Toggle(new GUIContent("Only Once"), controller.once, GUILayout.Height(height));
                    seconds = EditorGUILayout.FloatField(new GUIContent("Seconds"), controller.seconds, GUILayout.Height(height));
                    GUILayout.EndVertical();
                    break;
                }
                on_disable = (OnDisableAction)EditorGUILayout.EnumPopup(new GUIContent("OnDisable"), controller.on_disable);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Ping to Asset"))
                {
                    EditorGUIUtility.PingObject(controller.graph);
                }
                if (GUILayout.Button("Open in Editor"))
                {
                    GraphEditorWindow.OpenEditor(controller.graph);
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal("RL Header");
            {
                GUILayout.Space(15.0f);
                GUILayout.BeginVertical();
                {
                    foldout = EditorGUILayout.Foldout(foldout, new GUIContent(string.Format("Variables [{0}]", controller.properties.Values.Where(p => p.is_public).Count())));
                }
                GUILayout.EndVertical();
                if (GUILayout.Toggle(debug, debug ? "Debug" : "Normal", (GUIStyle)"minibutton") != debug)
                {
                    debug = !debug;
                }
            }
            GUILayout.EndHorizontal();

            if (foldout)
            {
                GUILayout.BeginHorizontal("RL Background", GUILayout.MinHeight(10.0f));
                {
                    GUILayout.Space(10.0f);
                    GUILayout.BeginVertical();
                    {
                        foreach (VariableObject property in controller.properties.Values.ToList())
                        {
                            if (property.is_public || debug)
                            {
                                object last_value = property.GetValue();
                                object new_value  = GUIDraw.AnyField(last_value, property.valueType, debug ? property.name + string.Format(" (ID = {0}, Type = {1})", property.id, property.valueType.GetTypeName(true, true)) : property.name);
                                if (new_value != last_value)
                                {
                                    UndoManager.RecordObject(target, "Change Value");
                                    property.SetValue(new_value);
                                }
                            }
                        }
                    }
                    GUILayout.Space(5.0f);
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }

            if (GUI.changed)
            {
                UndoManager.RecordObject(target, "GraphController Inspector");
                controller.graph      = graph;
                controller.on_enable  = on_enable;
                controller.once       = once;
                controller.seconds    = seconds;
                controller.on_disable = on_disable;
                UndoManager.SetDirty(target);
            }
        }
示例#4
0
 private void DrawNodeInspector()
 {
     if (!GraphEditor.is_drag && GraphEditor.activeNode)
     {
         GUILayout.Space(20.0f);
         foreach (Node node in GraphEditor.selection)
         {
             //GUILayout.Label(string.Format("{0} : {1}", GraphEditor.scroll, node.position));
             GUILayout.BeginVertical(node.title, "window");
             if (node is IListPort)
             {
                 GUILayout.BeginHorizontal();
                 if (GUILayout.Button("Add Port"))
                 {
                     UndoManager.RecordObject(asset, "Add Port");
                     ((IListPort)node).AddPort();
                     node.Validate();
                     //GraphEditor.current_validate = true;
                 }
                 if (GUILayout.Button("Remove Port"))
                 {
                     UndoManager.RecordObject(asset, "Remove Node");
                     ((IListPort)node).RemovePort();
                     node.Validate();
                     //GraphEditor.current_validate = true;
                 }
                 GUILayout.EndHorizontal();
             }
             foreach (Port port in node.portValues)
             {
                 var plug   = port as IPlug;
                 var input  = port as IInputValue;
                 var output = port as IOutputValue;
                 if (input != null)
                 {
                     if (plug != null && plug.IsPlugged())
                     {
                         GUILayout.BeginHorizontal();
                         GUI.enabled = false;
                         GUIDraw.AnyField(input.GetDefaultValue(), input.valueType, port.name, GUILayout.ExpandWidth(true));
                         GUI.enabled = true;
                         if (GUILayout.Button("x", GUILayout.Width(20.0f)))
                         {
                             UndoManager.RecordObject(asset, "Unplug Port");
                             plug.Unplug();
                         }
                         GUILayout.EndHorizontal();
                     }
                     else
                     {
                         object last_value = input.GetDefaultValue();
                         object new_value  = GUIDraw.AnyField(last_value, input.valueType, port.name, GUILayout.ExpandWidth(true));
                         if (new_value != last_value)
                         {
                             UndoManager.RecordObject(asset, "Change Value");
                             input.SetDefaultValue(new_value);
                         }
                     }
                 }
                 else if (output != null)
                 {
                     GUILayout.BeginHorizontal();
                     GUILayout.Label("[PORT] " + port.name);
                     GUILayout.FlexibleSpace();
                     GUILayout.Label(string.Format("<{0}>", output.valueType.GetTypeName()));
                     if (plug != null && plug.IsPlugged())
                     {
                         if (GUILayout.Button("x", GUILayout.Width(20.0f)))
                         {
                             UndoManager.RecordObject(asset, "Unplug Port");
                             plug.Unplug();
                         }
                     }
                     GUILayout.EndHorizontal();
                 }
                 else
                 {
                     GUILayout.BeginHorizontal();
                     GUILayout.Label("[PORT] " + port.name);
                     if (plug != null)
                     {
                         GUILayout.FlexibleSpace();
                         if (plug.IsPlugged())
                         {
                             GUILayout.Label("[PLUGGED]");
                         }
                         else
                         {
                             GUILayout.Label("[UNPLUGGED]");
                         }
                     }
                     GUILayout.FlexibleSpace();
                     GUILayout.Label("[ACTION]");
                     if (plug != null && plug.IsPlugged())
                     {
                         if (GUILayout.Button("x", GUILayout.Width(20.0f)))
                         {
                             UndoManager.RecordObject(asset, "Unplug Port");
                             plug.Unplug();
                         }
                     }
                     GUILayout.EndHorizontal();
                 }
             }
             GUILayout.EndVertical();
         }
         GUILayout.FlexibleSpace();
     }
 }