Pathfinding.GridGraph.GenerateMatrix C# (CSharp) Method

GenerateMatrix() public method

public GenerateMatrix ( ) : void
return void
        public void GenerateMatrix()
        {
            size = unclampedSize;

            size.x *= Mathf.Sign (size.x);
            //size.y *= Mathf.Sign (size.y);
            size.y *= Mathf.Sign (size.y);

            //Clamp the nodeSize at 0.1
            nodeSize = Mathf.Clamp (nodeSize,size.x/1024F,Mathf.Infinity);//nodeSize < 0.1F ? 0.1F : nodeSize;
            nodeSize = Mathf.Clamp (nodeSize,size.y/1024F,Mathf.Infinity);

            size.x = size.x < nodeSize ? nodeSize : size.x;
            //size.y = size.y < 0.1F ? 0.1F : size.y;
            size.y = size.y < nodeSize ? nodeSize : size.y;

            boundsMatrix.SetTRS (center,Quaternion.Euler (rotation),new Vector3 (aspectRatio,1,1));

            //bounds.center = boundsMatrix.MultiplyPoint (Vector3.up*height*0.5F);
            //bounds.size = new Vector3 (width*nodeSize,height,depth*nodeSize);

            width = Mathf.FloorToInt (size.x / nodeSize);
            depth = Mathf.FloorToInt (size.y / nodeSize);

            if (Mathf.Approximately (size.x / nodeSize,Mathf.CeilToInt (size.x / nodeSize))) {
                width = Mathf.CeilToInt (size.x / nodeSize);
            }

            if (Mathf.Approximately (size.y / nodeSize,Mathf.CeilToInt (size.y / nodeSize))) {
                depth = Mathf.CeilToInt (size.y / nodeSize);
            }

            //height = size.y;

            matrix.SetTRS (boundsMatrix.MultiplyPoint3x4 (-new Vector3 (size.x,0,size.y)*0.5F),Quaternion.Euler(rotation), new Vector3 (nodeSize*aspectRatio,1,nodeSize));
        }

Usage Example

Ejemplo n.º 1
0
        void DrawFirstSection(GridGraph graph)
        {
            DrawWidthDepthFields(graph);

            newNodeSize = EditorGUILayout.FloatField(new GUIContent("Node size", "The size of a single node. The size is the side of the node square in world units"), graph.nodeSize);

            newNodeSize = newNodeSize <= 0.01F ? 0.01F : newNodeSize;

            float prevRatio = graph.aspectRatio;

            graph.aspectRatio = EditorGUILayout.FloatField(new GUIContent("Aspect Ratio", "Scaling of the nodes width/depth ratio. Good for isometric games"), graph.aspectRatio);

            DrawIsometricField(graph);

            if (graph.nodeSize != newNodeSize || prevRatio != graph.aspectRatio)
            {
                if (!locked)
                {
                    graph.nodeSize = newNodeSize;
                    Matrix4x4 oldMatrix = graph.matrix;
                    graph.GenerateMatrix();
                    if (graph.matrix != oldMatrix)
                    {
                        //Rescann the graphs
                        //AstarPath.active.AutoScan ();
                        GUI.changed = true;
                    }
                }
                else
                {
                    int tmpWidth = graph.width;
                    int tmpDepth = graph.depth;

                    float delta = newNodeSize / graph.nodeSize;
                    graph.nodeSize      = newNodeSize;
                    graph.unclampedSize = RoundVector3(new Vector2(tmpWidth * graph.nodeSize, tmpDepth * graph.nodeSize));
                    Vector3 newCenter = graph.matrix.MultiplyPoint3x4(new Vector3((tmpWidth / 2F) * delta, 0, (tmpDepth / 2F) * delta));
                    graph.center = RoundVector3(newCenter);

                    graph.GenerateMatrix();

                    //Make sure the width & depths stay the same
                    graph.width = tmpWidth;
                    graph.depth = tmpDepth;
                    AutoScan();
                }
            }

            DrawPositionField(graph);

            graph.rotation = EditorGUILayout.Vector3Field("Rotation", graph.rotation);

            if (GUILayout.Button(new GUIContent("Snap Size", "Snap the size to exactly fit nodes"), GUILayout.MaxWidth(100), GUILayout.MaxHeight(16)))
            {
                SnapSizeToNodes(graph.width, graph.depth, graph);
            }
        }
All Usage Examples Of Pathfinding.GridGraph::GenerateMatrix