Ejemplo n.º 1
0
        private void Toolbar(Rect rect, SerializedProperty graphProperty)
        {
            if (GUI.Button(rect, plusTex, ButtonStyle(graph.State == NodegraphState.Placing)))
            {
                graphState.enumValueIndex = (int)NodegraphState.Placing;
            }
            rect.x += X_OFFSET;

            if (GUI.Button(rect, penTex, ButtonStyle(graph.State == NodegraphState.Editing)))
            {
                graphState.enumValueIndex = (int)NodegraphState.Editing;
            }
            rect.x += X_OFFSET;

            if (GUI.Button(rect, removeTex, ButtonStyle(graph.State == NodegraphState.Removing)))
            {
                graphState.enumValueIndex = (int)NodegraphState.Removing;
            }
            rect.x += X_OFFSET;

            if (GUI.Button(rect, clearTex, ButtonStyle(graph.State == NodegraphState.Clearing)))
            {
                if (EditorUtility.DisplayDialog("Clearing all the Waypoint Nodes", "This action will " +
                                                "remove all the nodes from the currently selected Waypoint. Are you sure?",
                                                "Yes", "No"))
                {
                    graph.ClearNodes();
                }
                graphState.enumValueIndex = (int)NodegraphState.None;
            }
            rect.x += X_OFFSET;

            rect.width *= 2;
            if (GUI.Button(rect, "Close"))
            {
                Selection.activeGameObject = null;
                Tools.current = Tool.Move;
            }

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 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();
            }
        }