public void AddNodeBehaviour(Node_Behaviour nodeBehaviour) { if (!this.nodeBehaviours.Contains(nodeBehaviour)) { this.nodeBehaviours.Add(nodeBehaviour); } }
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 List <Vector3> CalculateIntersections(Node_Behaviour nodeBehaviour) { intersections.Clear(); foreach (Edge edge in nodeBehaviour.Node.Edges) { foreach (Edge intersectingEdge in this.Graph.Edges) { IntersectionHelper intersection = IntersectionHelper.Line2LineIntersect( edge.From.Position, edge.To.Position, intersectingEdge.From.Position, intersectingEdge.To.Position); if (edge.From.Position == intersectingEdge.From.Position || edge.From.Position == intersectingEdge.To.Position || edge.To.Position == intersectingEdge.From.Position || edge.To.Position == intersectingEdge.To.Position) { continue; } if (intersection.Status == IntersectionStatus.COINCIDENT || intersection.Status == IntersectionStatus.PARALLEL) { } else if (intersection.Status == IntersectionStatus.INTERSECTION) { intersections.AddRange(intersection.points); Debug.Log("Intersections Found " + intersection.points.Count); } } } return(intersections); }
/// <summary> /// /// </summary> /// <param name="mousePosition"></param> /// <param name="distance"></param> /// <returns></returns> public Edge_Behaviour GetEdgeInDistance(Node_Behaviour node, float distance) { Edge_Behaviour result = null; float minDistance = float.MaxValue; Vector3 nearestPointOnEdge; foreach (Edge_Behaviour edgeBehaviour in edgeBehaviours) { Edge edge = edgeBehaviour.Edge; if (!node.Node.Edges.Contains(edge)) { nearestPointOnEdge = MathUtils.GetMinDistancePointOnLine( edge.From.Position, edge.To.Position, node.transform.position); float tmp = (node.transform.position - nearestPointOnEdge).sqrMagnitude; if (tmp < minDistance) { minDistance = tmp; result = edgeBehaviour; } } } if (minDistance < distance && result != null) { return(result); } return(null); }
/// <summary> /// /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public Edge_Behaviour CreateEdgeBehaviour(Node_Behaviour from, Node_Behaviour to) { //Debug.Log("GraphBehaviour: Going to create EdgeBehaviour for From-Node " + from.node.Id + " and To-Node " + to.node.Id); if (from == null || to == null) { return(null); } Edge edge = this.graph.CreateEdge(from.Node, to.Node); if (edgesParent == null) { CheckParents(); } //Debug.Log("GraphBehaviour: Create EdgeBehaviour for From-Node " + from.node.Id + " and To-Node " + to.node.Id); GameObject edgeGO = edgesParent.CreateChild(edge.Id); Edge_Behaviour edgeBehaviour = edgeGO.AddComponent <Edge_Behaviour>(); edgeBehaviour.InitializeBehaviour(this, edge, from, to); AddEdgeBehaviour(edgeBehaviour); return(edgeBehaviour); }
public void InitializeBehaviour(Graph_Behaviour graphBehaviour, Edge edge, Node_Behaviour fromBehaviour, Node_Behaviour toBehaviour) { this.onGraphEvent = new EventHandler(OnGraphEvent); this.GraphBehaviour = graphBehaviour; this.Edge = edge; this.fromBehaviour = fromBehaviour; this.ToBehaviour = toBehaviour; }
public Node_Behaviour CreateNodeBehaviour(Vector3 position) { //Debug.Log("GraphBehaviour: Create Node at Position " + position); Node node = this.graph.CreateNode(position); Node_Behaviour nodeBehaviour = CreateNodeBahaviour(node); return(nodeBehaviour); }
public static void DrawSecondLevelHelpLines(Node node) { foreach (Edge edge in node.Edges) { if (edge.From == node) { Node_Behaviour.DrawHelpLines(edge.To, Color.green, true); } else { Node_Behaviour.DrawHelpLines(edge.From, Color.green, true); } } }
public void Awake() { // the single target nodeBehaviour = target as Node_Behaviour; node = nodeBehaviour.Node; // multiple targets nodeBehaviours = new List <Node_Behaviour>(); nodes = targets; foreach (Object item in nodes) { Node_Behaviour go = (Node_Behaviour)item; nodeBehaviours.Add(go); } }
private Node_Behaviour CreateNodeBahaviour(Node node) { //Debug.Log("GraphBehaviour: Create NodeBehaviour for Node " + node.Id); if (nodesParent == null) { CheckParents(); } GameObject nodeGO = nodesParent.CreateChild(node.Id); Node_Behaviour nodeBehaviour = nodeGO.AddComponent <Node_Behaviour>(); nodeBehaviour.InitializeBehaviour(this, node); AddNodeBehaviour(nodeBehaviour); return(nodeBehaviour); }
/// <summary> /// /// </summary> /// <param name="mousePosition"></param> /// <param name="distance"></param> /// <param name="pointOnEdge"></param> /// <param name="pointOnEdgeParameter"></param> /// <returns></returns> public Edge_Behaviour GetEdgeInDistanceWithPoint(Node_Behaviour node, float distance, out Vector3 pointOnEdge, out float pointOnEdgeParameter) { Edge_Behaviour edgeBehaviour = GetEdgeInDistance(node, distance); pointOnEdge = Vector3.zero; pointOnEdgeParameter = float.NaN; if (edgeBehaviour != null) { pointOnEdge = MathUtils.GetMinDistancePointOnLine( edgeBehaviour.Edge.From.Position, edgeBehaviour.Edge.To.Position, node.transform.position, out pointOnEdgeParameter); } return(edgeBehaviour); }
private void OnGraphEvent(System.Object sender, EventArgs e) { GraphEventArgs args = (GraphEventArgs)e; //Debug.Log("Edge-Behaviour " + gameObject.name + " \n" + args.ToString()); switch (args.GraphEvent) { //case GraphEventType.NodeChanged: // Debug.Log(this.name + " EdgeBehaviour: NodeChanged (sender" + ((Edge)sender).ToString() + ")"); // break; //case GraphEventType.NodeDeleted: // Debug.Log(this.name + " EdgeBehaviour: NodeDeleted (sender" + ((Edge)sender).ToString() + ")"); // break; case GraphEventType.EdgeChanged: //Debug.Log(this.name + " EdgeBehaviour: EdgeChanged (sender" + ((Edge)sender).ToString() + ")"); this.transform.position = edge.Position; break; case GraphEventType.EdgeFromChanged: //Debug.Log(this.name + " EdgeBehaviour: EdgeFromChanged (sender" + ((Edge)sender).ToString() + ")"); this.fromBehaviour = graphBehaviour.GetNodeBehaviourByID(this.edge.From.Id); break; case GraphEventType.EdgeToChanged: //Debug.Log(this.name + " EdgeBehaviour: EdgeToChanged (sender" + ((Edge)sender).ToString() + ")"); this.toBehaviour = graphBehaviour.GetNodeBehaviourByID(this.edge.To.Id); break; case GraphEventType.EdgeDeleted: //Debug.Log(this.name + " EdgeBehaviour: EdgeDeleted (sender" + ((Edge)sender).ToString() + ")"); // TODO: wenn andere auf das Edge-Behaviour hören, muss HIER zuerst weitergefeuert werden. this.Edge = null; return; default: break; } }
/// <summary> /// Get the node Nodebehaviour with the minimal distance within the given Distance /// </summary> /// <param name="mousePosition"></param> /// <param name="distance"></param> /// <returns></returns> public Node_Behaviour GetNodeInDistance(Vector3 worldPoint, float distance) { Node_Behaviour result = null; float minDistance = float.MaxValue; foreach (Node_Behaviour nodeBehaviour in nodeBehaviours) { float tmp = (worldPoint - nodeBehaviour.Node.Position).magnitude; if (tmp < minDistance) { minDistance = tmp; result = nodeBehaviour; } } if (minDistance < distance) { return(result); } else { return(null); } }
//public void DeleteEdgeBehaviour(Edge_Behaviour edgeBehaviour) //{ // edgeBehaviour.Edge.Delete(); //} public Edge_Behaviour CreateEdgeBehaviour(Node from, Node to) { //Debug.Log("GraphBehaviour: Going to create EdgeBehaviour for From-Node " + from.node.Id + " and To-Node " + to.node.Id); if (from == null || to == null) { return(null); } Node_Behaviour fromBehaviour = GetNodeBehaviourByID(from.Id); if (fromBehaviour == null) { fromBehaviour = CreateNodeBahaviour(from); } Node_Behaviour toBehaviour = GetNodeBehaviourByID(to.Id); if (toBehaviour == null) { toBehaviour = CreateNodeBahaviour(to); } return(CreateEdgeBehaviour(fromBehaviour, toBehaviour)); }
public void RemoveNodeBehaviour(Node_Behaviour nodeBehaviour) { //Debug.Log("Graphbehaviour RemoveNodeBehaviour : " + nodeBehaviour.name); this.nodeBehaviours.Remove(nodeBehaviour); }
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 OnSceneGUI() { if (edge != null && !edgeBehaviour.gameObject.IsDestroyed()) { UnityEngine.Event currentEvent = UnityEngine.Event.current; // Just in case that the values are changed in the editor if ((edge.From != null) && (edge.To != null)) { if (currentEvent.type != EventType.mouseDrag) { Vector3 handlePosition = edge.Position; Vector3 newPosition = edgeBehaviour.transform.position; if (newPosition != handlePosition) { edge.Position = newPosition; edgeBehaviour.transform.position = edge.Position; this.edgeBehaviour.GraphBehaviour.UpdateEdgeIntersections(); } } } // Delete edge if D-Key is pressed if (InputHelpers.Pressed(KeyCode.D) && edgeBehaviour != null) { edgeBehaviour.Edge.Delete(); return; } // Worked: but only for node/edge-layer --> wall-endings have to be changed as well... // --> maybe with teh graphEvent FromToChanged in the Wall //// Switch ends on DoubleClick //if (InputHelpers.DoubleLeftClick()) // edge.SwitchEnds(); if (InputHelpers.DoubleLeftClicked()) { // Get the mousepointer on XZ-plane and draw a line Vector3 worldPoint = InputHelpers.GetXZPlaneCollisionInEditor(currentEvent); float pointOnEdgeParameter; Vector3 pointOnEdge = MathUtils.GetMinDistancePointOnLine( edgeBehaviour.Edge.From.Position, edgeBehaviour.Edge.To.Position, worldPoint, out pointOnEdgeParameter); // Create new Node at the cutting-point on the Edge Node_Behaviour newNodeBehaviour = edgeBehaviour.GraphBehaviour.CreateNodeBehaviour(pointOnEdge); // Create new Edge for first part Edge_Behaviour cutEdge1 = edgeBehaviour.GraphBehaviour.CreateEdgeBehaviour(edgeBehaviour.FromBehaviour, newNodeBehaviour); // Create new Edge for second part Edge_Behaviour cutEdge2 = edgeBehaviour.GraphBehaviour.CreateEdgeBehaviour(newNodeBehaviour, edgeBehaviour.ToBehaviour); //HandleUtility.Repaint(); edgeBehaviour.Edge.Delete(); Debug.Log("Deleted old Edge"); newNodeBehaviour.Node.OnNodeChanged(); Debug.Log("NewNode ChangedEvent"); UnityEngine.Object[] objects = new UnityEngine.Object[1]; objects[0] = newNodeBehaviour.gameObject; Selection.objects = objects; Debug.Log("After selecting the new node"); Undo.CreateSnapshot(); Debug.Log("Create Snapshot"); HandleUtility.Repaint(); Debug.Log("Repaint"); return; } if (GUI.changed) { EditorUtility.SetDirty(edgeBehaviour); } } }
public override void OnInspectorGUI() { GUILayout.Label("Behaviour_Node2D-Editor", EditorStyles.boldLabel); if (Selection.gameObjects.Length >= 2) { if (GUILayout.Button("Merge Nodes")) { GameObject node1 = Selection.gameObjects[0]; Node_Behaviour node1Behaviour = node1.GetComponent <Node_Behaviour>(); Node node1Node = node1Behaviour.Node; List <GameObject> mergeNodesGOs = new List <GameObject>(); List <Node> combineNodes = new List <Node>(); for (int i = 1; i < Selection.gameObjects.Length; i++) { GameObject node2 = Selection.gameObjects[1]; Node_Behaviour node2Behaviour = node2.GetComponent <Node_Behaviour>(); Node node2Node = node2Behaviour.Node; combineNodes.Add(node2Node); mergeNodesGOs.Add(node2); } node1Node.MergeWith(combineNodes.ToArray()); foreach (GameObject go in mergeNodesGOs) { DestroyImmediate(go); } } } EditorGUILayout.Separator(); EditorGUILayout.Separator(); //// Get Position from changes in the VectorField in Inspection Vector3 oldPosition = node.Position; Vector3 newPosition = EditorGUILayout.Vector3Field("Position", node.Position); if (oldPosition != newPosition) { Debug.Log("Auslöser Node2D-Editor-OnInspectorGUI"); node.Position = newPosition; nodeBehaviour.transform.position = newPosition; } if (nodeBehaviour != null && node != null) { EditorGUILayout.Separator(); if (edgesFoldout = EditorGUILayout.Foldout(edgesFoldout, "Edges")) { CustomGUIUtils.BeginGroup(); if (arrivalsFoldout = EditorGUILayout.Foldout(arrivalsFoldout, "Arrivals (" + node.ArrivalDegree.ToString() + ")")) { CustomGUIUtils.BeginGroup(); int count = 0; foreach (Edge edge in node.Arrivals) { EditorGUILayout.LabelField("Arrival " + count++, edge.Id); } CustomGUIUtils.EndGroup(); } if (departuresFoldout = EditorGUILayout.Foldout(departuresFoldout, "Departures (" + node.DepartureDegree.ToString() + ")")) { CustomGUIUtils.BeginGroup(); int count = 0; foreach (Edge edge in node.Departures) { EditorGUILayout.LabelField("Departure " + count++, edge.Id); } CustomGUIUtils.EndGroup(); } if (EditorGUILayout.Foldout(listenerFoldout, "Listeners")) { CustomGUIUtils.BeginGroup(); int count = 0; foreach (string name in node.PrintEventHandlers()) { EditorGUILayout.LabelField("" + count++, name); } CustomGUIUtils.EndGroup(); } CustomGUIUtils.EndGroup(); } } EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (advancedGizmoSettings = EditorGUILayout.Foldout(advancedGizmoSettings, "Behaviour_Edge2D-Advanced-Gizmo-Settings")) { CustomGUIUtils.BeginGroup(); Node_Behaviour.NodeGizmoSize = (Node_Behaviour.GizmoSize)EditorGUILayout.EnumPopup("GizmoSize", Node_Behaviour.NodeGizmoSize); Node_Behaviour.DrawLabels = EditorGUILayout.Toggle("Show Label", Node_Behaviour.DrawLabels); nodeBehaviour.DrawHelpLinesGizmo = EditorGUILayout.Toggle("Show Help-Lines", nodeBehaviour.DrawHelpLinesGizmo); nodeBehaviour.DrawSecondLevelHelpLinesGizmo = EditorGUILayout.Toggle("Show SecondLevel Help-Lines", nodeBehaviour.DrawSecondLevelHelpLinesGizmo); Node_Behaviour.DrawAnglePieGizmoMaster = EditorGUILayout.Toggle("Draw Angle-Pie Gizmo", Node_Behaviour.DrawAnglePieGizmoMaster); if (Node_Behaviour.DrawAnglePieGizmoMaster) { CustomGUIUtils.BeginGroup(); nodeBehaviour.DrawAnglePieGizmo = EditorGUILayout.Toggle("Draw Angle-Pie Gizmo", nodeBehaviour.DrawAnglePieGizmo); if (nodeBehaviour.DrawAnglePieGizmo) { Node_Behaviour.DrawAnglePieGizmoDynamic = EditorGUILayout.Toggle("Dynamic Radius", Node_Behaviour.DrawAnglePieGizmoDynamic); if (!Node_Behaviour.DrawAnglePieGizmoDynamic) { nodeBehaviour.AnglePieGizmoRadius = EditorGUILayout.Slider("Radius", nodeBehaviour.AnglePieGizmoRadius, 0f, 10f); } } CustomGUIUtils.EndGroup(); } CustomGUIUtils.EndGroup(); } EditorGUILayout.Separator(); EditorGUILayout.Separator(); // Draw the DefaultInspector for this Behvaiour showDefaultInspector = this.DrawDefaultInspectorFoldout(nodeBehaviour, showDefaultInspector); if (GUI.changed) { EditorUtility.SetDirty(nodeBehaviour); } }