public void OnSceneGUI() { Event currentEvent = Event.current; Vector3 worldPoint = InputHelpers.GetXZPlaneCollisionInEditorFixedHeight(0f, currentEvent); Debug.Log(worldPoint); if (InputHelpers.ClickedLeft()) { //Vector3 worldPoint = InputHelpers.GetXZPlaneCollisionInEditorFixedHeight(0f, currentEvent); //Debug.Log(worldPoint); if (Event.current.control) { worldPoint = worldPoint.SnapToGrid(); } Node_Behaviour nodeBehaviour = graphBehaviour.CreateNodeBehaviour(worldPoint); nodeBehaviour.gameObject.SelectInEditor(); } //if (GUI.changed) // EditorUtility.SetDirty(graphBehaviour); }
public void OnSceneGUI() { UnityEngine.Event currentEvent = UnityEngine.Event.current; //NodeUtils.DrawCircle(node.Position, 3f); // Delete the Node if (InputHelpers.Pressed(KeyCode.D)) { nodeBehaviour.Node.Delete(); return; } /*****************- Position-Changes -************************************************************/ // Update Positions for single or multi-select if (nodeBehaviour.transform.position != oldPosition) { oldPosition = nodeBehaviour.transform.position; foreach (Node_Behaviour go in nodeBehaviours) { NodeUtils.DrawAnglePieGizmo(go.Node); if (Event.current.control) { go.transform.position = go.transform.position.SnapToGrid(); go.Node._position = go.transform.position; } else { go.Node._position = go.transform.position; } this.nodeBehaviour.GraphBehaviour.UpdateEdgeIntersections(); } //// fire change-events foreach (Node_Behaviour go in nodeBehaviours) { //Debug.Log(go.name + "OnNodePosition Node2D_Editor"); go.Node.OnNodeChanged(); } } /*****************************************************************************************************/ // Get the mousepointer on XZ-plane and draw a line Vector3 worldPoint = InputHelpers.GetXZPlaneCollisionInEditorFixedHeight(0f, currentEvent); //InputHelpers.GetXZPlaneCollisionInEditor(currentEvent); if (Event.current.control) { worldPoint = worldPoint.SnapToGrid(); } Handles.color = Color.green; Handles.DrawLine(nodeBehaviour.transform.position, worldPoint); if (InputHelpers.ClickedLeft()) { //if() // if another Node is within distance, connect the two nodes with a new edge Node_Behaviour foundNode = nodeBehaviour.GraphBehaviour.GetNodeInDistance(worldPoint, 1f); if (foundNode != null) { if (foundNode != nodeBehaviour) { // Create a new EdgeBehaviour with the given nodes Edge_Behaviour newEdgeBehaviour = nodeBehaviour.GraphBehaviour.CreateEdgeBehaviour(nodeBehaviour, foundNode); foundNode.gameObject.SelectInEditor(); //newEdgeBehaviour.Edge.OnFromToChanged(); //} //if (currentEvent.control || currentEvent.shift) //{ //Node_Behaviour.combineWithLastSelectedNode = true; //currentEvent.Use(); } } else { Vector3 pointOnEdge; float pointOnEdgeParameter; Edge_Behaviour foundEdge = nodeBehaviour.GraphBehaviour.GetEdgeInDistanceWithPoint(worldPoint, 1f, out pointOnEdge, out pointOnEdgeParameter); if (foundEdge != null) { Debug.Log("Found Edge: " + foundEdge.name + " hit at t = " + pointOnEdgeParameter + " at position " + pointOnEdge); // Create new Node at the cutting-point on the Edge Node_Behaviour newNodeBehaviour = nodeBehaviour.GraphBehaviour.CreateNodeBehaviour(pointOnEdge); // Create new Edge for first part Edge_Behaviour cutEdge1 = nodeBehaviour.GraphBehaviour.CreateEdgeBehaviour(foundEdge.FromBehaviour, newNodeBehaviour); // Create new Edge for second part Edge_Behaviour cutEdge2 = nodeBehaviour.GraphBehaviour.CreateEdgeBehaviour(newNodeBehaviour, foundEdge.ToBehaviour); if (foundEdge.FromBehaviour != nodeBehaviour && foundEdge.ToBehaviour != nodeBehaviour) { // Create new Edge from the lastNode (this) to the new Node Edge_Behaviour newEdgeBehaviour = nodeBehaviour.GraphBehaviour.CreateEdgeBehaviour(nodeBehaviour, newNodeBehaviour); //Debug.Log("############# Done creating a new Wall ##################"); } foundEdge.Edge.Delete(); newNodeBehaviour.Node.OnNodeChanged(); newNodeBehaviour.gameObject.SelectInEditor(); } else //if (nodeBehaviour.GraphBehaviour != null) { //Debug.Log("############# Start creating a new Wall ##################"); Node_Behaviour newNodeBehaviour = nodeBehaviour.GraphBehaviour.CreateNodeBehaviour(worldPoint); Edge_Behaviour newEdgeBehaviour = nodeBehaviour.GraphBehaviour.CreateEdgeBehaviour(nodeBehaviour, newNodeBehaviour); //Debug.Log("############# Done creating a new Wall ##################"); newNodeBehaviour.gameObject.SelectInEditor(); currentEvent.Use(); } } } HandleUtility.Repaint(); //if (InputHelpers.MouseUp()) //{ // Debug.Log("RoomRecognition"); // ////this is sooooo NOT good.... // foreach (Wall wall in node.Graph.Iem.Prefab.Walls) // wall.RoomRecognition(); //} //if (GUI.changed) // EditorUtility.SetDirty(nodeBehaviour); }