Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            if (DashEditorCore.EditorConfig.settingsShowInspectorLogo)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Box(Resources.Load <Texture>("Textures/dash"), GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();
            }

            if (EditorUtility.IsPersistent(target))
            {
                GUI.enabled = false;
            }

            EditorGUI.BeginChangeCheck();

            if (((IEditorControllerAccess)Controller).graphAsset == null && !Controller.HasBoundGraph)
            {
                GUILayout.BeginVertical();

                var oldColor = GUI.color;
                GUI.color = new Color(1, 0.75f, 0.5f);
                if (GUILayout.Button("Create Graph", GUILayout.Height(40)))
                {
                    if (EditorUtility.DisplayDialog("Create Graph", "Create Bound or Asset Graph?",
                                                    "Bound", "Asset"))
                    {
                        BindGraph(GraphUtils.CreateEmptyGraph());
                    }
                    else
                    {
                        ((IEditorControllerAccess)Controller).graphAsset = GraphUtils.CreateGraphAsAssetFile();
                    }
                }

                GUI.color = oldColor;

                ((IEditorControllerAccess)Controller).graphAsset =
                    (DashGraph)EditorGUILayout.ObjectField(((IEditorControllerAccess)Controller).graphAsset,
                                                           typeof(DashGraph), true);
            }
            else
            {
                GUILayout.BeginVertical();

                var oldColor = GUI.color;
                GUI.color = new Color(1, 0.75f, 0.5f);
                if (GUILayout.Button("Open Editor", GUILayout.Height(40)))
                {
                    OpenEditor();
                }

                GUI.color = oldColor;

                if (!Controller.HasBoundGraph)
                {
                    EditorGUI.BeginChangeCheck();

                    ((IEditorControllerAccess)Controller).graphAsset =
                        (DashGraph)EditorGUILayout.ObjectField(((IEditorControllerAccess)Controller).graphAsset,
                                                               typeof(DashGraph), true);

                    if (EditorGUI.EndChangeCheck())
                    {
                        DashEditorCore.EditController(Controller);
                    }

                    if (GUILayout.Button("Bind Graph"))
                    {
                        BindGraph(Controller.Graph);
                    }
                }
                else
                {
                    if (GUILayout.Button("Save to Asset"))
                    {
                        DashGraph graph = GraphUtils.CreateGraphAsAssetFile(Controller.Graph);
                        if (graph != null)
                        {
                            Controller.BindGraph(null);
                            ((IEditorControllerAccess)Controller).graphAsset = graph;
                        }
                    }

                    if (GUILayout.Button("Remove Graph"))
                    {
                        if (DashEditorCore.EditorConfig.editingGraph == Controller.Graph)
                        {
                            DashEditorCore.UnloadGraph();
                        }

                        Controller.BindGraph(null);
                    }
                }
            }

            Controller.useCustomTarget = EditorGUILayout.Toggle(
                new GUIContent("Use Custom Target", "Customize target which is this gameobject transform by default."),
                Controller.useCustomTarget);

            if (Controller.useCustomTarget == true)
            {
                Controller.customTarget =
                    (Transform)EditorGUILayout.ObjectField("Custom Target", Controller.customTarget, typeof(Transform),
                                                           true);
            }
            else
            {
                Controller.customTarget = null;
            }

            Controller.autoStart =
                EditorGUILayout.Toggle(
                    new GUIContent("Auto Start", "Automatically call an input on a graph when controller is started."),
                    Controller.autoStart);

            if (Controller.autoStart)
            {
                Controller.autoStartInput =
                    EditorGUILayout.TextField("Auto Start Input", Controller.autoStartInput);
            }

            Controller.autoOnEnable =
                EditorGUILayout.Toggle(
                    new GUIContent("Auto OnEnable",
                                   "Automatically call an input on a graph when controller is enabled."), Controller.autoOnEnable);

            if (Controller.autoOnEnable)
            {
                Controller.autoOnEnableInput =
                    EditorGUILayout.TextField("Auto OnEnable Input", Controller.autoOnEnableInput);
            }

            GUILayout.EndVertical();

            if (Controller.Graph != null)
            {
                if (Controller.HasBoundGraph)
                {
                    GUIVariableUtils.DrawVariablesInspector("Graph Variables", Controller.Graph.variables, Controller.gameObject);
                }
                else
                {
                    Controller.showGraphVariables =
                        EditorGUILayout.Toggle("Show Graph Variables", Controller.showGraphVariables);

                    if (Controller.showGraphVariables)
                    {
                        GUIStyle style = new GUIStyle();
                        style.fontStyle        = FontStyle.Italic;
                        style.normal.textColor = Color.yellow;
                        style.alignment        = TextAnchor.MiddleCenter;
                        EditorGUILayout.LabelField("Warning these are not bound to instance.", style);
                        GUIVariableUtils.DrawVariablesInspector("Graph Variables", Controller.Graph.variables, Controller.gameObject);
                    }
                }
            }

            Controller.advancedInspector = EditorGUILayout.Toggle(new GUIContent("Show Advanced Inspector", ""), Controller.advancedInspector);

            if (Controller.advancedInspector)
            {
                DrawExposedPropertiesInspector();
            }

            if (Controller.advancedInspector && Controller.Graph != null)
            {
                GUILayout.Space(16);
                DrawGraphStructureInspector();
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 2
0
        protected void DrawVariablesGUI(Vector2 p_position, bool p_global, Color p_color, DashVariables p_variables, ref bool p_minimized, GameObject p_boundObject)
        {
            Rect rect = new Rect(p_position.x, p_position.y, 380, p_minimized ? 32 : 200);

            DrawBoxGUI(rect, p_global ? "Global Variables" : "Graph Variables", TextAnchor.UpperCenter, p_color);

            var minStyle = new GUIStyle();

            minStyle.normal.textColor = Color.white;
            minStyle.fontStyle        = FontStyle.Bold;
            minStyle.fontSize         = 20;
            if (GUI.Button(new Rect(rect.x + rect.width - 20 + (p_minimized ? 0 : 2), rect.y + 2, 20, 20), p_minimized ? "+" : "-", minStyle))
            {
                p_minimized = !p_minimized;
                GUI.FocusControl("");
            }

            if (p_minimized)
            {
                return;
            }

            if (p_global && PrefabUtility.GetPrefabInstanceStatus(p_boundObject) != PrefabInstanceStatus.NotAPrefab)
            {
                var style = new GUIStyle();
                style.alignment        = TextAnchor.MiddleCenter;
                style.normal.textColor = Color.white;
                style.fontSize         = 20;
                style.wordWrap         = true;
                EditorGUI.TextArea(new Rect(rect.x + 5, rect.y + 30, rect.width - 10, rect.height - 30), "Global variables on prefab instances are not supported!", style);
                return;
            }

            GUILayout.BeginArea(new Rect(rect.x + 5, rect.y + 30, rect.width - 10, rect.height - 79));
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false);

            EditorGUI.BeginChangeCheck();

            if (p_variables != null)
            {
                int index = 0;
                foreach (var variable in p_variables)
                {
                    GUIVariableUtils.VariableField(p_variables, variable.Name, p_boundObject, rect.width - 10);
                    EditorGUILayout.Space(4);
                    index++;
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();

            if (GUI.Button(new Rect(rect.x + 4, rect.y + rect.height - 48, rect.width - 8, 20), "Add Variable"))
            {
                TypesMenu.Show((type) => OnAddVariable(p_variables, type));
            }

            if (GUI.Button(new Rect(rect.x + 4, rect.y + rect.height - 24, rect.width / 2 - 6, 20), "Copy Variables"))
            {
                VariableUtils.CopyVariables(p_variables);
            }

            if (GUI.Button(new Rect(rect.x + rect.width / 2 + 2, rect.y + rect.height - 24, rect.width / 2 - 6, 20), "Paste Variables"))
            {
                VariableUtils.PasteVariables(p_variables, p_boundObject);
            }

            if (EditorGUI.EndChangeCheck())
            {
                DashEditorCore.SetDirty();
            }

            UseEvent(new Rect(rect.x, rect.y, rect.width, rect.height));
        }