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); }
public void OnGUI() { if (dragNDrop.DropAreaBegin("outer")) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.LightGreyBlue); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("outer"); } if (dragNDrop.DropAreaBegin("outer2")) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, color); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); if (dragNDrop.ThisDropArea.ContainsMouse() && InputHelpers.ClickedLeft()) { color = XKCDColors.Blue; } if (color == XKCDColors.Blue) { dragNDrop.ThisDropArea.Rect = EasingCurves.EaseRect( "outer2", dragNDrop.ThisDropArea.Rect, new Rect(dragNDrop.ThisDropArea.Rect).AddOffset(new Rect(-100, -100, -200, -200)), EasingCurves.EaseType.easeOutElastic); } dragNDrop.DropAreaEnd("outer2"); } if (dragNDrop.DragObjectBegin(strings[0])) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, strings[0].ToString()); GUI.DrawTexture(dragNDrop.CurrentDragObject.CurrentRect, DefaultIconSet.Device); // DropAreas if (dragNDrop.DropAreaBegin("inner1")) { Rect drawRect = new Rect(dragNDrop.CurrentDragObject.CurrentRect); drawRect.x += 10; drawRect.y += 10; drawRect.width = 130; drawRect.height = 150; dragNDrop.ThisDropArea.Rect = drawRect; CustomGUIUtils.DrawBox(drawRect, XKCDColors.LightRed); GUI.Label(drawRect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("inner1"); } if (dragNDrop.DropAreaBegin("inner2")) { Rect drawRect = new Rect(dragNDrop.CurrentDragObject.CurrentRect); drawRect.x += 10; drawRect.y += 210; drawRect.width = 130; drawRect.height = 150; dragNDrop.ThisDropArea.Rect = drawRect; CustomGUIUtils.DrawBox(drawRect, XKCDColors.GreenApple); GUI.Label(drawRect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("inner2"); } // DragObjects if (dragNDrop.DragObjectBegin(strings[1])) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, strings[1].ToString()); GUI.DrawTexture(dragNDrop.CurrentDragObject.CurrentRect, DefaultIconSet.Device); dragNDrop.DragObjectEnd(strings[1]); } if (dragNDrop.DragObjectBegin(strings[2])) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, strings[2].ToString()); GUI.DrawTexture(dragNDrop.CurrentDragObject.CurrentRect, DefaultIconSet.Device); dragNDrop.DragObjectEnd(strings[2]); } dragNDrop.DragObjectEnd(strings[0]); } //foreach (DropArea dropArea in dragNDrop.dropAreas.Values) //{ // if (dropArea.Object != null) // { // if (dropArea.Object.GetType() == typeof(A)) // { // A readA = dropArea.GetObject<A>(); // Debug.Log("A gelesen: " + readA.ToString()); // } // } //} }