//GraphUndo undoState;
        //byte[] savedBytes;

        public override void OnSceneGUI(NavGraph target)
        {
            Event e = Event.current;



            GridGraph graph = target as GridGraph;

            Matrix4x4 matrixPre = graph.matrix;

            graph.GenerateMatrix();

            if (e.type == EventType.MouseDown)
            {
                isMouseDown = true;
            }
            else if (e.type == EventType.MouseUp)
            {
                isMouseDown = false;
            }

            if (!isMouseDown)
            {
                savedMatrix = graph.boundsMatrix;
            }

            Handles.matrix = savedMatrix;

            if ((graph.GetType() == typeof(GridGraph) && graph.nodes == null) || (graph.uniformWidthDepthGrid && graph.depth * graph.width != graph.nodes.Length) || graph.matrix != matrixPre)
            {
                //Rescan the graphs
                if (AstarPath.active.AutoScan())
                {
                    GUI.changed = true;
                }
            }

            Matrix4x4 inversed = savedMatrix.inverse;

            Handles.color = AstarColor.BoundsHandles;

            Handles.DrawCapFunction cap = Handles.CylinderCap;

            Vector2 extents = graph.unclampedSize * 0.5F;

            Vector3 center = inversed.MultiplyPoint3x4(graph.center);


        #if UNITY_3_3
            if (Tools.current == 3)
            {
        #else
            if (Tools.current == Tool.Scale)
            {
        #endif

                Vector3 p1 = Handles.Slider(center + new Vector3(extents.x, 0, 0), Vector3.right, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(extents.x, 0, 0)), cap, 0);
                Vector3 p2 = Handles.Slider(center + new Vector3(0, 0, extents.y), Vector3.forward, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(0, 0, extents.y)), cap, 0);
                //Vector3 p3 = Handles.Slider (center+new Vector3 (0,extents.y,0),	Vector3.up,			0.1F*HandleUtility.GetHandleSize (center+new Vector3 (0,extents.y,0)),cap,0);

                Vector3 p4 = Handles.Slider(center + new Vector3(-extents.x, 0, 0), -Vector3.right, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(-extents.x, 0, 0)), cap, 0);
                Vector3 p5 = Handles.Slider(center + new Vector3(0, 0, -extents.y), -Vector3.forward, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(0, 0, -extents.y)), cap, 0);

                Vector3 p6 = Handles.Slider(center, Vector3.up, 0.1F * HandleUtility.GetHandleSize(center), cap, 0);

                Vector3 r1 = new Vector3(p1.x, p6.y, p2.z);
                Vector3 r2 = new Vector3(p4.x, p6.y, p5.z);

                //Debug.Log (graph.boundsMatrix.MultiplyPoint3x4 (Vector3.zero)+" "+graph.boundsMatrix.MultiplyPoint3x4 (Vector3.one));

                //if (Tools.viewTool != ViewTool.Orbit) {

                graph.center = savedMatrix.MultiplyPoint3x4((r1 + r2) / 2F);

                Vector3 tmp = r1 - r2;
                graph.unclampedSize = new Vector2(tmp.x, tmp.z);

                //}

        #if UNITY_3_3
            }
            else if (Tools.current == 1)
            {
        #else
            }
            else if (Tools.current == Tool.Move)
            {
        #endif

                if (Tools.pivotRotation == PivotRotation.Local)
                {
                    center = Handles.PositionHandle(center, Quaternion.identity);

                    if (Tools.viewTool != ViewTool.Orbit)
                    {
                        graph.center = savedMatrix.MultiplyPoint3x4(center);
                    }
                }
                else
                {
                    Handles.matrix = Matrix4x4.identity;

                    center = Handles.PositionHandle(graph.center, Quaternion.identity);

                    if (Tools.viewTool != ViewTool.Orbit)
                    {
                        graph.center = center;
                    }
                }
        #if UNITY_3_3
            }
            else if (Tools.current == 2)
            {
        #else
            }
            else if (Tools.current == Tool.Rotate)
            {
        #endif
                //The rotation handle doesn't seem to be able to handle different matrixes of some reason
                Handles.matrix = Matrix4x4.identity;

                Quaternion rot = Handles.RotationHandle(Quaternion.Euler(graph.rotation), graph.center);

                if (Tools.viewTool != ViewTool.Orbit)
                {
                    graph.rotation = rot.eulerAngles;
                }
            }

            //graph.size.x = Mathf.Max (graph.size.x,1);
            //graph.size.y = Mathf.Max (graph.size.y,1);
            //graph.size.z = Mathf.Max (graph.size.z,1);

            Handles.matrix = Matrix4x4.identity;



        #if ASTARDEBUG
            //Draws some info over the node closest to the mouse
            Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            Vector3 p = ray.GetPoint(100);


            if (Event.current.shift)
            {
                GraphNode close = graph.GetNearest(p).node;

                if (close != null)
                {
                    node1 = close;
                }

                if (node1 == null)
                {
                    return;
                }

                Handles.SphereCap(0, (Vector3)node1.position, Quaternion.identity, graph.nodeSize * 0.5F);


                //Node node = node1;

                GUI.color = Color.white;
                //Handles.Label((Vector3)node.position + Vector3.up*2,"G : "+node.+"\nH : "+node.h+"\nF : "+node.f+"\nPosition : "+node.position.ToString (),EditorStyles.whiteBoldLabel);
            }
        #endif
        }
Ejemplo n.º 2
0
        //GraphUndo undoState;
        //byte[] savedBytes;

        public override void OnSceneGUI(NavGraph target)
        {
            Event e = Event.current;



            GridGraph graph = target as GridGraph;

            Matrix4x4 matrixPre = graph.matrix;

            graph.GenerateMatrix();

            if (e.type == EventType.MouseDown)
            {
                isMouseDown = true;
            }
            else if (e.type == EventType.MouseUp)
            {
                isMouseDown = false;
            }

            if (!isMouseDown)
            {
                savedMatrix = graph.boundsMatrix;
            }

            Handles.matrix = savedMatrix;

            if ((graph.GetType() == typeof(GridGraph) && graph.nodes == null) || (graph.uniformWidthDepthGrid && graph.depth * graph.width != graph.nodes.Length) || graph.matrix != matrixPre)
            {
                //Rescan the graphs
                if (AutoScan())
                {
                    GUI.changed = true;
                }
            }

            Matrix4x4 inversed = savedMatrix.inverse;

            Handles.color = AstarColor.BoundsHandles;

            Handles.DrawCapFunction cap = Handles.CylinderCap;

            Vector2 extents = graph.unclampedSize * 0.5F;

            Vector3 center = inversed.MultiplyPoint3x4(graph.center);


        #if UNITY_3_3
            if (Tools.current == 3)
            {
        #else
            if (Tools.current == Tool.Scale)
            {
        #endif

                Vector3 p1 = Handles.Slider(center + new Vector3(extents.x, 0, 0), Vector3.right, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(extents.x, 0, 0)), cap, 0);
                Vector3 p2 = Handles.Slider(center + new Vector3(0, 0, extents.y), Vector3.forward, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(0, 0, extents.y)), cap, 0);
                //Vector3 p3 = Handles.Slider (center+new Vector3 (0,extents.y,0),	Vector3.up,			0.1F*HandleUtility.GetHandleSize (center+new Vector3 (0,extents.y,0)),cap,0);

                Vector3 p4 = Handles.Slider(center + new Vector3(-extents.x, 0, 0), -Vector3.right, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(-extents.x, 0, 0)), cap, 0);
                Vector3 p5 = Handles.Slider(center + new Vector3(0, 0, -extents.y), -Vector3.forward, 0.1F * HandleUtility.GetHandleSize(center + new Vector3(0, 0, -extents.y)), cap, 0);

                Vector3 p6 = Handles.Slider(center, Vector3.up, 0.1F * HandleUtility.GetHandleSize(center), cap, 0);

                Vector3 r1 = new Vector3(p1.x, p6.y, p2.z);
                Vector3 r2 = new Vector3(p4.x, p6.y, p5.z);

                //Debug.Log (graph.boundsMatrix.MultiplyPoint3x4 (Vector3.zero)+" "+graph.boundsMatrix.MultiplyPoint3x4 (Vector3.one));

                //if (Tools.viewTool != ViewTool.Orbit) {

                graph.center = savedMatrix.MultiplyPoint3x4((r1 + r2) / 2F);

                Vector3 tmp = r1 - r2;
                graph.unclampedSize = new Vector2(tmp.x, tmp.z);

                //}

        #if UNITY_3_3
            }
            else if (Tools.current == 1)
            {
        #else
            }
            else if (Tools.current == Tool.Move)
            {
        #endif

                if (Tools.pivotRotation == PivotRotation.Local)
                {
                    center = Handles.PositionHandle(center, Quaternion.identity);

                    if (Tools.viewTool != ViewTool.Orbit)
                    {
                        graph.center = savedMatrix.MultiplyPoint3x4(center);
                    }
                }
                else
                {
                    Handles.matrix = Matrix4x4.identity;

                    center = Handles.PositionHandle(graph.center, Quaternion.identity);

                    if (Tools.viewTool != ViewTool.Orbit)
                    {
                        graph.center = center;
                    }
                }
        #if UNITY_3_3
            }
            else if (Tools.current == 2)
            {
        #else
            }
            else if (Tools.current == Tool.Rotate)
            {
        #endif
                //The rotation handle doesn't seem to be able to handle different matrixes of some reason
                Handles.matrix = Matrix4x4.identity;

                Quaternion rot = Handles.RotationHandle(Quaternion.Euler(graph.rotation), graph.center);

                if (Tools.viewTool != ViewTool.Orbit)
                {
                    graph.rotation = rot.eulerAngles;
                }
            }

            //graph.size.x = Mathf.Max (graph.size.x,1);
            //graph.size.y = Mathf.Max (graph.size.y,1);
            //graph.size.z = Mathf.Max (graph.size.z,1);

            Handles.matrix = Matrix4x4.identity;
        }