Exemple #1
0
    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);
            }
        }
    }
Exemple #2
0
    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);
    }