void PlacingNodes(int id) { RaycastHit hitInfo; Ray click = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); if (Physics.Raycast(click, out hitInfo, 1000, graph.solidLayerMask, graph.m_hitTriggers)) { Handles.color = Color.yellow; Handles.DrawWireCube(hitInfo.point, Vector3.one / 4f); var nodes = graph.GetNodes(); Handles.color = Color.white; for (int ni = 0; ni < nodes.Count; ni++) { if (Vector3.Distance(hitInfo.point, nodes[ni].Position) <= graph.m_nodeMaximumDistance) { Handles.DrawDottedLine(hitInfo.point, nodes[ni].Position, 2); } } } switch (Event.current.type) { case EventType.MouseDown: // placing mode and mouse on Scene tab if (EditorWindow.mouseOverWindow.titleContent.text == "Scene") { // grab mouse down if (Event.current.button == 0) { if (Physics.Raycast(click, out hitInfo, 1000, graph.solidLayerMask)) { graph.AddNode(hitInfo.point); if (autoRebuild.boolValue) { graph.RebuildNodegraph(); } } Event.current.Use(); } } break; case EventType.KeyDown: if (Event.current.keyCode == KeyCode.Space) { Camera sceneCamera = SceneView.lastActiveSceneView.camera; var position = sceneCamera.transform.position + sceneCamera.transform.forward; graph.AddNode(position); if (autoRebuild.boolValue) { graph.RebuildNodegraph(); } Event.current.Use(); } break; } }
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(); } }