Пример #1
0
        public override void OnInspectorGUI()
        {
            if (graphProperty.objectReferenceValue != null)
            {
                base.OnInspectorGUI();

                movingObstacleTag.stringValue = EditorGUILayout.TagField("Obstacle Tag", movingObstacleTag.stringValue);

                Color originalColor = GUI.color;
                EditorGUILayout.Space();

                GUI.contentColor = Color.white;
                Rect rect = EditorGUILayout.GetControlRect(false, 50);
                rect = EditorGUILayout.GetControlRect(false, 50);
                if (GUI.Button(rect, new GUIContent("Rebuild Graph")))
                {
                    graph.RebuildNodegraph();
                    SceneView.RepaintAll();
                }
            }
            else
            {
                graphProperty.objectReferenceValue = EditorGUILayout.ObjectField("Graph", graphProperty.objectReferenceValue, typeof(Graph), allowSceneObjects: false);
                EditorGUILayout.HelpBox("Create a graph or add here.", MessageType.Error, wide: true);
                if (GUILayout.Button("Create new Graph"))
                {
                    string path     = EditorUtility.SaveFilePanelInProject("Create new Graph", "New Graph", "asset", "Create a new Graph asset");
                    Graph  newGraph = CreateInstance <Graph>();
                    AssetDatabase.CreateAsset(newGraph, path);
                    graphProperty.objectReferenceValue = AssetDatabase.LoadAssetAtPath(path, typeof(Graph));
                }
            }

            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            movingObstacleTag.stringValue = EditorGUILayout.TagField("Obstacle Tag", movingObstacleTag.stringValue);

            if (clearBtn == null)
            {
                clearBtn = new GUIStyle(GUI.skin.button);
                clearBtn.normal.textColor = Color.white;
                clearBtn.active.textColor = Color.white;
            }

            if (graphProperty.objectReferenceValue != null)
            {
                Color originalColor = GUI.color;
                EditorGUILayout.Space();

                var actionStyle = new GUIStyle(EditorStyles.boldLabel);
                actionStyle.normal.textColor = Color.blue;
                EditorGUILayout.LabelField("Current Action: " + nodegraph.State, actionStyle);

                GUI.contentColor = Color.white;
                Rect rect   = EditorGUILayout.GetControlRect(false, 50);
                var  offset = rect.width /= 6;

                switch (nodegraph.State)
                {
                case NodegraphState.None:
                    if (GUI.Button(rect, new GUIContent(gearsTex, "Rebuild Graph")))
                    {
                        nodegraph.RebuildNodegraph();
                        SceneView.RepaintAll();
                    }

                    rect.x += offset;
                    if (GUI.Button(rect, new GUIContent(plusTex, "Place Nodes")))
                    {
                        nodegraph.State = NodegraphState.Placing;
                    }

                    rect.x += offset;
                    if (GUI.Button(rect, new GUIContent(bulkTex, "Bulk Node Placement")))
                    {
                        nodegraph.State = NodegraphState.Bulk;
                        var position = SceneView.lastActiveSceneView.camera.transform.position + SceneView.lastActiveSceneView.camera.transform.forward * nodegraph.m_bulkSpawnDistance;
                        bulkControl = new BulkControl(position);
                    }

                    rect.x += offset;
                    if (GUI.Button(rect, new GUIContent(penTex, "Edit Nodes")))
                    {
                        nodegraph.State = NodegraphState.Editing;
                        selectedNodes.Clear();
                    }

                    rect.x += offset;
                    if (GUI.Button(rect, new GUIContent(removeTex, "Remove Nodes")))
                    {
                        nodegraph.State = NodegraphState.Removing;
                    }

                    rect.x += offset;
                    if (GUI.Button(rect, new GUIContent(clearTex, "Clear Nodes"), clearBtn))
                    {
                        nodegraph.ClearNodes();
                        SceneView.RepaintAll();

                        currentNode = null;
                        //selectedIndex = -1;
                        selectedNodes.Clear();
                    }
                    break;

                case NodegraphState.Bulk:
                    if (GUI.Button(rect, new GUIContent(confirmTex, "Create Bulk Nodes")))
                    {
                        Vector3Int extension = bulkControl.Extension;

                        int controlID = GUIUtility.GetControlID(FocusType.Keyboard);
                        Handles.color = Color.green;
                        for (int x = -extension.x; x < extension.x; x += nodegraph.m_bulkNodeDistanceGap)
                        {
                            for (int y = -extension.y; y < extension.y; y += nodegraph.m_bulkNodeDistanceGap)
                            {
                                for (int z = -extension.z; z < extension.z; z += nodegraph.m_bulkNodeDistanceGap)
                                {
                                    nodegraph.AddNode(new Vector3(x, y, z) + bulkControl.Position);
                                }
                            }
                        }

                        nodegraph.State = NodegraphState.None;
                        EditorUtility.SetDirty(graphProperty.objectReferenceValue);

                        currentNode = null;
                        //selectedIndex = -1;
                    }
                    goto case NodegraphState.Placing;

                case NodegraphState.Editing:
                    //rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                    originalColor = GUI.color;
                    GUI.color     = Color.grey;
                    rect.width    = EditorGUIUtility.currentViewWidth;
                    EditorGUI.LabelField(rect, "Selected: " + selectedNodes.Count);
                    rect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.LabelField(rect, "Select SHIFT to select multiple.");
                    GUI.color = originalColor;

                    rect = EditorGUILayout.GetControlRect(false, 50);
                    if (GUI.Button(rect, new GUIContent("Cancel Actions", cancelTex)))
                    {
                        nodegraph.State = NodegraphState.None;
                        EditorUtility.SetDirty(graphProperty.objectReferenceValue);

                        currentNode = null;
                        //selectedIndex = -1;
                        selectedNodes.Clear();
                    }
                    break;

                case NodegraphState.Placing:
                    rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                    //rect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.LabelField(rect, "Press SPACE to place node in view position.", EditorStyles.boldLabel);
                    rect = EditorGUILayout.GetControlRect(false, 50);
                    if (GUI.Button(rect, new GUIContent("Cancel Actions", cancelTex)))
                    {
                        nodegraph.State = NodegraphState.None;
                        EditorUtility.SetDirty(graphProperty.objectReferenceValue);

                        currentNode = null;
                        //selectedIndex = -1;
                        selectedNodes.Clear();
                    }
                    break;

                case NodegraphState.Removing:
                    rect = EditorGUILayout.GetControlRect(false, 50);
                    if (GUI.Button(rect, new GUIContent("Cancel Actions", cancelTex)))
                    {
                        nodegraph.State = NodegraphState.None;
                        EditorUtility.SetDirty(graphProperty.objectReferenceValue);

                        currentNode = null;
                        //selectedIndex = -1;
                        selectedNodes.Clear();
                    }
                    break;
                }

                // node list
                EditorGUILayout.Space();
                showNodes = EditorGUILayout.Foldout(showNodes, "Node list");
                if (showNodes)
                {
                    var nodelist = nodegraph.GetNodes();

                    for (int i = 0; i < nodelist.Count; i++)
                    {
                        rect = EditorGUILayout.GetControlRect();

                        Color original = GUI.color;
                        GUI.color = selectedNodes.Contains(nodelist[i]) ? Color.cyan : Color.white;

                        nodelist[i].Position = EditorGUI.Vector3Field(rect, string.Format("#{0}", i), nodelist[i].Position);
                        GUI.color            = original;
                    }

                    SceneView.RepaintAll();
                }

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
            }
        }