Beispiel #1
0
    /** Updates graphs with a created GUO.
     * Creates a Pathfinding::GraphUpdateObject with a Pathfinding::GraphUpdateShape
     * representing the polygon of this object and update all graphs using AstarPath::UpdateGraphs.
     * This will not update graphs directly. See AstarPath::UpdateGraph for more info.
     */
    public void Apply()
    {
        if (AstarPath.active == null) {
            Debug.LogError ("There is no AstarPath object in the scene");
            return;
        }

        firstApplied = true;

        Pathfinding.GraphUpdateShape shape = new Pathfinding.GraphUpdateShape ();
        shape.convex = convex;
        shape.points = points;

        GraphUpdateObject guo = new GraphUpdateObject (shape.GetBounds ());
        guo.shape = shape;
        guo.modifyWalkability = modifyWalkability;
        guo.setWalkability = setWalkability;
        guo.addPenalty = penalty;
        #if ConfigureTagsAsMultiple
        guo.tags = tags;
        #else
        guo.modifyTag = modifyTag;
        guo.setTag = setTag;
        #endif

        AstarPath.active.UpdateGraphs (guo);
    }
            public BurstShape(GraphUpdateShape scene, Allocator allocator)
            {
                var pts = scene.convex ? scene._convexPoints : scene._points;

                if (pts == null)
                {
                    points = new NativeArray <Vector3>(0, allocator);
                }
                else
                {
                    points = new NativeArray <Vector3>(pts, allocator);
                }

                origin  = scene.origin;
                right   = scene.right;
                forward = scene.forward;

                // Speeds up calculations below
                var mgn = scene.right.sqrMagnitude;

                if (mgn > 0)
                {
                    right /= mgn;
                }
                mgn = scene.forward.sqrMagnitude;
                if (mgn > 0)
                {
                    forward /= mgn;
                }
                containsEverything = false;
            }
Beispiel #3
0
    /** Updates graphs with a created GUO.
     * Creates a Pathfinding::GraphUpdateObject with a Pathfinding::GraphUpdateShape
     * representing the polygon of this object and update all graphs using AstarPath::UpdateGraphs.
     * This will not update graphs directly. See AstarPath::UpdateGraph for more info.
     */
    public void Apply()
    {
        if (AstarPath.active == null)
        {
            Debug.LogError("There is no AstarPath object in the scene");
            return;
        }

        firstApplied = true;

        Pathfinding.GraphUpdateShape shape = new Pathfinding.GraphUpdateShape();
        shape.convex = convex;
        shape.points = points;

        GraphUpdateObject guo = new GraphUpdateObject(shape.GetBounds());

        guo.shape             = shape;
        guo.modifyWalkability = modifyWalkability;
        guo.setWalkability    = setWalkability;
        guo.addPenalty        = penalty;
#if ConfigureTagsAsMultiple
        guo.tags = tags;
#else
        guo.modifyTag = modifyTag;
        guo.setTag    = setTag;
#endif

        AstarPath.active.UpdateGraphs(guo);
    }
Beispiel #4
0
        protected override List <GraphNode> GetNodesInRegion(Bounds b, GraphUpdateShape shape)
        {
            IntRect rectFromBounds = base.GetRectFromBounds(b);

            if (this.nodes == null || !rectFromBounds.IsValid() || this.nodes.Length != this.width * this.depth * this.layerCount)
            {
                return(ListPool <GraphNode> .Claim());
            }
            List <GraphNode> list = ListPool <GraphNode> .Claim(rectFromBounds.Width *rectFromBounds.Height *this.layerCount);

            for (int i = 0; i < this.layerCount; i++)
            {
                int num = i * this.width * this.depth;
                for (int j = rectFromBounds.xmin; j <= rectFromBounds.xmax; j++)
                {
                    for (int k = rectFromBounds.ymin; k <= rectFromBounds.ymax; k++)
                    {
                        int       num2      = num + k * this.width + j;
                        GraphNode graphNode = this.nodes[num2];
                        if (graphNode != null && b.Contains((Vector3)graphNode.position) && (shape == null || shape.Contains((Vector3)graphNode.position)))
                        {
                            list.Add(graphNode);
                        }
                    }
                }
            }
            return(list);
        }
 // Token: 0x060022A1 RID: 8865 RVA: 0x00193904 File Offset: 0x00191B04
 public Bounds GetBounds()
 {
     if (this.points == null || this.points.Length == 0)
     {
         Collider   component  = base.GetComponent <Collider>();
         Collider2D component2 = base.GetComponent <Collider2D>();
         Renderer   component3 = base.GetComponent <Renderer>();
         Bounds     bounds;
         if (component != null)
         {
             bounds = component.bounds;
         }
         else if (component2 != null)
         {
             bounds      = component2.bounds;
             bounds.size = new Vector3(bounds.size.x, bounds.size.y, Mathf.Max(bounds.size.z, 1f));
         }
         else
         {
             if (!(component3 != null))
             {
                 return(new Bounds(Vector3.zero, Vector3.zero));
             }
             bounds = component3.bounds;
         }
         if (this.legacyMode && bounds.size.y < this.minBoundsHeight)
         {
             bounds.size = new Vector3(bounds.size.x, this.minBoundsHeight, bounds.size.z);
         }
         return(bounds);
     }
     return(GraphUpdateShape.GetBounds(this.convex ? this.convexPoints : this.points, (this.legacyMode && this.legacyUseWorldSpace) ? Matrix4x4.identity : base.transform.localToWorldMatrix, this.minBoundsHeight));
 }
Beispiel #6
0
        public static Bounds GetBounds(Vector3[] points, Matrix4x4 matrix, float minimumHeight)
        {
            Vector3 b       = matrix.MultiplyPoint3x4(Vector3.zero);
            Vector3 vector  = matrix.MultiplyPoint3x4(Vector3.right) - b;
            Vector3 vector2 = matrix.MultiplyPoint3x4(Vector3.up) - b;
            Vector3 vector3 = matrix.MultiplyPoint3x4(Vector3.forward) - b;

            return(GraphUpdateShape.GetBounds(points, vector, vector2, vector3, b, minimumHeight));
        }
Beispiel #7
0
    /** Updates graphs with a created GUO.
     * Creates a Pathfinding.GraphUpdateObject with a Pathfinding.GraphUpdateShape
     * representing the polygon of this object and update all graphs using AstarPath.UpdateGraphs.
     * This will not update graphs directly. See AstarPath.UpdateGraph for more info.
     */
    public void Apply()
    {
        if (AstarPath.active == null)
        {
            Debug.LogError("There is no AstarPath object in the scene");
            return;
        }

        firstApplied = true;

        Pathfinding.GraphUpdateShape shape = new Pathfinding.GraphUpdateShape();
        shape.convex = convex;
        Vector3[] worldPoints = points;
        if (!useWorldSpace)
        {
            worldPoints = new Vector3[points.Length];
            Matrix4x4 matrix = transform.localToWorldMatrix;
            for (int i = 0; i < worldPoints.Length; i++)
            {
                worldPoints[i] = matrix.MultiplyPoint3x4(points[i]);
            }
        }

        shape.points = worldPoints;

        Bounds b = shape.GetBounds();

        if (b.size.y < minBoundsHeight)
        {
            b.size = new Vector3(b.size.x, minBoundsHeight, b.size.z);
        }

        GraphUpdateObject guo = new GraphUpdateObject(b);

        guo.shape                 = shape;
        guo.modifyWalkability     = modifyWalkability;
        guo.setWalkability        = setWalkability;
        guo.addPenalty            = penaltyDelta;
        guo.updatePhysics         = updatePhysics;
        guo.updateErosion         = updateErosion;
        guo.resetPenaltyOnPhysics = resetPenaltyOnPhysics;

#if ConfigureTagsAsMultiple
        guo.tags = tags;
#else
        guo.modifyTag = modifyTag;
        guo.setTag    = setTag;
#endif

        AstarPath.active.UpdateGraphs(guo);
    }
Beispiel #8
0
        /// <summary>
        /// Calculates the bounds for this component.
        /// This is a relatively expensive operation, it needs to go through all points and
        /// run matrix multiplications.
        /// </summary>
        public Bounds GetBounds()
        {
            if (points == null || points.Length == 0)
            {
                Bounds bounds;
                var    coll   = GetComponent <Collider>();
                var    coll2D = GetComponent <Collider2D>();
                var    rend   = GetComponent <Renderer>();

                if (coll != null)
                {
                    bounds = coll.bounds;
                }
                else if (coll2D != null)
                {
                    bounds      = coll2D.bounds;
                    bounds.size = new Vector3(bounds.size.x, bounds.size.y, Mathf.Max(bounds.size.z, 1f));
                }
                else if (rend != null)
                {
                    bounds = rend.bounds;
                }
                else
                {
                    return(new Bounds(Vector3.zero, Vector3.zero));
                }

                if (legacyMode && bounds.size.y < minBoundsHeight)
                {
                    bounds.size = new Vector3(bounds.size.x, minBoundsHeight, bounds.size.z);
                }
                return(bounds);
            }
            else
            {
                return(GraphUpdateShape.GetBounds(convex ? convexPoints : points,
                                                  legacyMode && legacyUseWorldSpace ? Matrix4x4.identity : transform.localToWorldMatrix,
                                                  minBoundsHeight));
            }
        }
		/** Updates graphs with a created GUO.
		 * Creates a Pathfinding.GraphUpdateObject with a Pathfinding.GraphUpdateShape
		 * representing the polygon of this object and update all graphs using AstarPath.UpdateGraphs.
		 * This will not update graphs directly. See AstarPath.UpdateGraph for more info.
		 */
		public void Apply () {
			
			if (AstarPath.active == null) {
				Debug.LogError ("There is no AstarPath object in the scene");
				return;
			}
			
			GraphUpdateObject guo;
			
			if (points == null || points.Length == 0) {
				
				Bounds b;
				if (GetComponent<Collider>() != null) b = GetComponent<Collider>().bounds;
				else if (GetComponent<Renderer>() != null) b = GetComponent<Renderer>().bounds;
				else {
					Debug.LogWarning ("Cannot apply GraphUpdateScene, no points defined and no renderer or collider attached");
					return;
				}
				
				if (b.size.y < minBoundsHeight) b.size = new Vector3(b.size.x,minBoundsHeight,b.size.z);
				
				guo = new GraphUpdateObject (b);
				
			} else {
				Pathfinding.GraphUpdateShape shape = new Pathfinding.GraphUpdateShape ();
				shape.convex = convex;
				Vector3[] worldPoints = points;
				if (!useWorldSpace) {
					worldPoints = new Vector3[points.Length];
					Matrix4x4 matrix = transform.localToWorldMatrix;
					for (int i=0;i<worldPoints.Length;i++) worldPoints[i] = matrix.MultiplyPoint3x4 (points[i]);
				}
				
				shape.points = worldPoints;
			
				Bounds b = shape.GetBounds ();
				if (b.size.y < minBoundsHeight) b.size = new Vector3(b.size.x,minBoundsHeight,b.size.z);
				guo = new GraphUpdateObject (b);
				guo.shape = shape;
			}
			
			firstApplied = true;
			
			guo.modifyWalkability = modifyWalkability;
			guo.setWalkability = setWalkability;
			guo.addPenalty = penaltyDelta;
			guo.updatePhysics = updatePhysics;
			guo.updateErosion = updateErosion;
			guo.resetPenaltyOnPhysics = resetPenaltyOnPhysics;
			
	#if ConfigureTagsAsMultiple
			guo.tags = tags;
	#else
			guo.modifyTag = modifyTag;
			guo.setTag = setTag;
	#endif
			
			AstarPath.active.UpdateGraphs (guo);
		}
Beispiel #10
0
    /** Updates graphs with a created GUO.
     * Creates a Pathfinding.GraphUpdateObject with a Pathfinding.GraphUpdateShape
     * representing the polygon of this object and update all graphs using AstarPath.UpdateGraphs.
     * This will not update graphs directly. See AstarPath.UpdateGraph for more info.
     */
    public void Apply()
    {
        if (AstarPath.active == null) {
            Debug.LogError ("There is no AstarPath object in the scene");
            return;
        }

        firstApplied = true;

        Pathfinding.GraphUpdateShape shape = new Pathfinding.GraphUpdateShape ();
        shape.convex = convex;
        Vector3[] worldPoints = points;
        if (!useWorldSpace) {
            worldPoints = new Vector3[points.Length];
            Matrix4x4 matrix = transform.localToWorldMatrix;
            for (int i=0;i<worldPoints.Length;i++) worldPoints[i] = matrix.MultiplyPoint3x4 (points[i]);
        }

        shape.points = worldPoints;

        Bounds b = shape.GetBounds ();
        if (b.size.y < minBoundsHeight) b.size = new Vector3(b.size.x,minBoundsHeight,b.size.z);

        GraphUpdateObject guo = new GraphUpdateObject (b);
        guo.shape = shape;
        guo.modifyWalkability = modifyWalkability;
        guo.setWalkability = setWalkability;
        guo.addPenalty = penaltyDelta;
        guo.updatePhysics = updatePhysics;
        guo.updateErosion = updateErosion;

        guo.modifyTag = modifyTag;
        guo.setTag = setTag;

        AstarPath.active.UpdateGraphs (guo);
    }
        // Token: 0x060022A2 RID: 8866 RVA: 0x00193A48 File Offset: 0x00191C48
        public void Apply()
        {
            if (AstarPath.active == null)
            {
                Debug.LogError("There is no AstarPath object in the scene", this);
                return;
            }
            GraphUpdateObject graphUpdateObject;

            if (this.points == null || this.points.Length == 0)
            {
                PolygonCollider2D component = base.GetComponent <PolygonCollider2D>();
                if (component != null)
                {
                    Vector2[] array  = component.points;
                    Vector3[] array2 = new Vector3[array.Length];
                    for (int i = 0; i < array2.Length; i++)
                    {
                        Vector2 vector = array[i] + component.offset;
                        array2[i] = new Vector3(vector.x, 0f, vector.y);
                    }
                    Matrix4x4        matrix = base.transform.localToWorldMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90f, 0f, 0f), Vector3.one);
                    GraphUpdateShape shape  = new GraphUpdateShape(this.points, this.convex, matrix, this.minBoundsHeight);
                    graphUpdateObject       = new GraphUpdateObject(this.GetBounds());
                    graphUpdateObject.shape = shape;
                }
                else
                {
                    Bounds bounds = this.GetBounds();
                    if (bounds.center == Vector3.zero && bounds.size == Vector3.zero)
                    {
                        Debug.LogError("Cannot apply GraphUpdateScene, no points defined and no renderer or collider attached", this);
                        return;
                    }
                    graphUpdateObject = new GraphUpdateObject(bounds);
                }
            }
            else
            {
                GraphUpdateShape graphUpdateShape;
                if (this.legacyMode && !this.legacyUseWorldSpace)
                {
                    Vector3[] array3 = new Vector3[this.points.Length];
                    for (int j = 0; j < this.points.Length; j++)
                    {
                        array3[j] = base.transform.TransformPoint(this.points[j]);
                    }
                    graphUpdateShape = new GraphUpdateShape(array3, this.convex, Matrix4x4.identity, this.minBoundsHeight);
                }
                else
                {
                    graphUpdateShape = new GraphUpdateShape(this.points, this.convex, (this.legacyMode && this.legacyUseWorldSpace) ? Matrix4x4.identity : base.transform.localToWorldMatrix, this.minBoundsHeight);
                }
                graphUpdateObject       = new GraphUpdateObject(graphUpdateShape.GetBounds());
                graphUpdateObject.shape = graphUpdateShape;
            }
            this.firstApplied = true;
            graphUpdateObject.modifyWalkability     = this.modifyWalkability;
            graphUpdateObject.setWalkability        = this.setWalkability;
            graphUpdateObject.addPenalty            = this.penaltyDelta;
            graphUpdateObject.updatePhysics         = this.updatePhysics;
            graphUpdateObject.updateErosion         = this.updateErosion;
            graphUpdateObject.resetPenaltyOnPhysics = this.resetPenaltyOnPhysics;
            graphUpdateObject.modifyTag             = this.modifyTag;
            graphUpdateObject.setTag = this.setTag;
            AstarPath.active.UpdateGraphs(graphUpdateObject);
        }
        // this is the optimized version. Other graphs cannot be optimised this way because they have irregular structures unfortunately. Still, we shouldn't miss on the advantages of this specific graph type, so I included it specifically.
        void mohogonyGrid()
        {
            nodes = new List<Node>();
            nodes.Add(node as Node);
            graph = AstarPath.active.graphs[node.graphIndex] as GridGraph;

            GraphUpdateShape gus = new GraphUpdateShape();
            if (useRealCollider.Value)
            {

                if(go.collider.GetType() == typeof(BoxCollider)) // take render bounds, then turn them into world coordinates
                {
                    Debug.Log("It's a box collider");
                    bounds.center = (go.collider as BoxCollider).center;
                    bounds.size = (go.collider as BoxCollider).size;

                    calculateBox(gus);

                }
                else if(go.collider.GetType() == typeof(MeshCollider))
                {
                    gus.points = (go.collider as MeshCollider).sharedMesh.vertices;
                    for(var i=0; i < gus.points.Count(); i++ )
                    {
                        gus.points[i] = go.transform.TransformPoint((go.collider as MeshCollider).sharedMesh.vertices[i]);
                    }
                    Debug.Log("It's a mesh collider!");
                }
                else // any other collider
                {
                    calculateBox(gus);
                    Debug.Log("This type of collider is not specifically supported. Using bounds instead...");
                }

            }

            else // get the points of the render bounds
            {
                bounds = (go.renderer.GetComponent<MeshFilter>()).sharedMesh.bounds;
                calculateBox(gus);
            }

            //gus.convex = true;
            nodes = graph.GetNodesInArea(gus);

            if(getWalkableOnly.Value)
            {
                connected = new List<Node>();
                for(var i=0; i < nodes.Count(); i++ )
                {
                    if(nodes[i].walkable)
                    {
                        connected.Add(nodes[i]); // connected is a substitute for a better named one :D There is no real sense behind the name here.
                    }
                }
                nodesOutput.Value = SetNodes(connected);
            }

            else
            {
                nodesOutput.Value = SetNodes(nodes);
            }

            Debug.Log("i" + nodes.Count);

            return;
        }
Beispiel #13
0
		/** All nodes inside the shape or if null, the bounding box.
		 * If a shape is supplied, it is assumed to be contained inside the bounding box.
		 * \see GraphUpdateShape.GetBounds
		 */
		private List<GraphNode> GetNodesInArea (Bounds b, GraphUpdateShape shape) {
			
			if (nodes == null || width*depth != nodes.Length) {
				return null;
			}
			
			List<GraphNode> inArea = Pathfinding.Util.ListPool<GraphNode>.Claim ();
			
			Vector3 min, max;
			GetBoundsMinMax (b,inverseMatrix,out min, out max);
			
			int minX = Mathf.RoundToInt (min.x-0.5F);
			int maxX = Mathf.RoundToInt (max.x-0.5F);
			
			int minZ = Mathf.RoundToInt (min.z-0.5F);
			int maxZ = Mathf.RoundToInt (max.z-0.5F);
			
			IntRect originalRect = new IntRect(minX,minZ,maxX,maxZ);
			IntRect gridRect = new IntRect(0,0,width-1,depth-1);
			
			IntRect rect = IntRect.Intersection (originalRect, gridRect);
			
			for (int x = rect.xmin; x <= rect.xmax;x++) {
				for (int z = rect.ymin;z <= rect.ymax;z++) {
					
					int index = z*width+x;
					
					GraphNode node = nodes[index];
					
					if (b.Contains ((Vector3)node.position) && (shape == null || shape.Contains ((Vector3)node.position))) {
						inArea.Add (node);
					}
				}
			}
			
			return inArea;
		}
Beispiel #14
0
		/** All nodes inside the shape or if null, the bounding box.
		 * If a shape is supplied, it is assumed to be contained inside the bounding box.
		 * \see GraphUpdateShape.GetBounds
		 */
		private List<GraphNode> GetNodesInArea (Bounds b, GraphUpdateShape shape) {
			if (nodes == null || width*depth != nodes.Length) {
				return null;
			}

			// Get a buffer we can use
			List<GraphNode> inArea = Pathfinding.Util.ListPool<GraphNode>.Claim();

			// Take the bounds and transform it using the matrix
			// Then convert that to a rectangle which contains
			// all nodes that might be inside the bounds
			Vector3 min, max;
			GetBoundsMinMax(b, inverseMatrix, out min, out max);

			int minX = Mathf.RoundToInt(min.x-0.5F);
			int maxX = Mathf.RoundToInt(max.x-0.5F);

			int minZ = Mathf.RoundToInt(min.z-0.5F);
			int maxZ = Mathf.RoundToInt(max.z-0.5F);

			var originalRect = new IntRect(minX, minZ, maxX, maxZ);

			// Rect which covers the whole grid
			var gridRect = new IntRect(0, 0, width-1, depth-1);

			// Clamp the rect to the grid
			var rect = IntRect.Intersection(originalRect, gridRect);

			// Loop through all nodes in the rectangle
			for (int x = rect.xmin; x <= rect.xmax; x++) {
				for (int z = rect.ymin; z <= rect.ymax; z++) {
					int index = z*width+x;

					GraphNode node = nodes[index];

					// If it is contained in the bounds (and optionally the shape)
					// then add it to the buffer
					if (b.Contains((Vector3)node.position) && (shape == null || shape.Contains((Vector3)node.position))) {
						inArea.Add(node);
					}
				}
			}

			return inArea;
		}
Beispiel #15
0
 public void Apply()
 {
     if (AstarPath.active == null)
     {
         Debug.LogError("There is no AstarPath object in the scene");
     }
     else
     {
         GraphUpdateObject obj2;
         if ((this.points == null) || (this.points.Length == 0))
         {
             Bounds   bounds;
             Collider component = base.GetComponent <Collider>();
             Renderer renderer  = base.GetComponent <Renderer>();
             if (component != null)
             {
                 bounds = component.bounds;
             }
             else if (renderer != null)
             {
                 bounds = renderer.bounds;
             }
             else
             {
                 Debug.LogWarning("Cannot apply GraphUpdateScene, no points defined and no renderer or collider attached");
                 return;
             }
             if (bounds.size.y < this.minBoundsHeight)
             {
                 bounds.size = new Vector3(bounds.size.x, this.minBoundsHeight, bounds.size.z);
             }
             obj2 = new GraphUpdateObject(bounds);
         }
         else
         {
             GraphUpdateShape shape = new GraphUpdateShape {
                 convex = this.convex
             };
             Vector3[] points = this.points;
             if (!this.useWorldSpace)
             {
                 points = new Vector3[this.points.Length];
                 Matrix4x4 localToWorldMatrix = base.transform.localToWorldMatrix;
                 for (int i = 0; i < points.Length; i++)
                 {
                     points[i] = localToWorldMatrix.MultiplyPoint3x4(this.points[i]);
                 }
             }
             shape.points = points;
             Bounds b = shape.GetBounds();
             if (b.size.y < this.minBoundsHeight)
             {
                 b.size = new Vector3(b.size.x, this.minBoundsHeight, b.size.z);
             }
             obj2 = new GraphUpdateObject(b)
             {
                 shape = shape
             };
         }
         this.firstApplied          = true;
         obj2.modifyWalkability     = this.modifyWalkability;
         obj2.setWalkability        = this.setWalkability;
         obj2.addPenalty            = this.penaltyDelta;
         obj2.updatePhysics         = this.updatePhysics;
         obj2.updateErosion         = this.updateErosion;
         obj2.resetPenaltyOnPhysics = this.resetPenaltyOnPhysics;
         obj2.modifyTag             = this.modifyTag;
         obj2.setTag = this.setTag;
         AstarPath.active.UpdateGraphs(obj2);
     }
 }
        public void Apply()
        {
            if (AstarPath.active == null)
            {
                Debug.LogError("There is no AstarPath object in the scene");
                return;
            }
            GraphUpdateObject graphUpdateObject;

            if (this.points == null || this.points.Length == 0)
            {
                Collider component  = base.GetComponent <Collider>();
                Renderer component2 = base.GetComponent <Renderer>();
                Bounds   bounds;
                if (component != null)
                {
                    bounds = component.bounds;
                }
                else
                {
                    if (!(component2 != null))
                    {
                        Debug.LogWarning("Cannot apply GraphUpdateScene, no points defined and no renderer or collider attached");
                        return;
                    }
                    bounds = component2.bounds;
                }
                if (bounds.size.y < this.minBoundsHeight)
                {
                    bounds.size = new Vector3(bounds.size.x, this.minBoundsHeight, bounds.size.z);
                }
                graphUpdateObject = new GraphUpdateObject(bounds);
            }
            else
            {
                GraphUpdateShape graphUpdateShape = new GraphUpdateShape();
                graphUpdateShape.convex = this.convex;
                Vector3[] array = this.points;
                if (!this.useWorldSpace)
                {
                    array = new Vector3[this.points.Length];
                    Matrix4x4 localToWorldMatrix = base.transform.localToWorldMatrix;
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = localToWorldMatrix.MultiplyPoint3x4(this.points[i]);
                    }
                }
                graphUpdateShape.points = array;
                Bounds bounds2 = graphUpdateShape.GetBounds();
                if (bounds2.size.y < this.minBoundsHeight)
                {
                    bounds2.size = new Vector3(bounds2.size.x, this.minBoundsHeight, bounds2.size.z);
                }
                graphUpdateObject       = new GraphUpdateObject(bounds2);
                graphUpdateObject.shape = graphUpdateShape;
            }
            this.firstApplied = true;
            graphUpdateObject.modifyWalkability     = this.modifyWalkability;
            graphUpdateObject.setWalkability        = this.setWalkability;
            graphUpdateObject.addPenalty            = this.penaltyDelta;
            graphUpdateObject.updatePhysics         = this.updatePhysics;
            graphUpdateObject.updateErosion         = this.updateErosion;
            graphUpdateObject.resetPenaltyOnPhysics = this.resetPenaltyOnPhysics;
            graphUpdateObject.modifyTag             = this.modifyTag;
            graphUpdateObject.setTag = this.setTag;
            AstarPath.active.UpdateGraphs(graphUpdateObject);
        }
Beispiel #17
0
 public Bounds GetBounds()
 {
     return(GraphUpdateShape.GetBounds((!this.convex) ? this.points : this._convexPoints, this.right, this.up, this.forward, this.origin, this.minimumHeight));
 }
Beispiel #18
0
		/** All nodes inside the shape.
		  * \note Be nice to the garbage collector and release the list when you have used it (optional)
		  * \see Pathfinding.Util.ListPool
		  * 
		  * \see GetNodesInArea(Bounds)
		  */
		public List<GraphNode> GetNodesInArea (GraphUpdateShape shape) {
			return GetNodesInArea (shape.GetBounds (), shape);
		}
Beispiel #19
0
        /// <summary>
        /// Updates graphs with a created GUO.
        /// Creates a Pathfinding.GraphUpdateObject with a Pathfinding.GraphUpdateShape
        /// representing the polygon of this object and update all graphs using AstarPath.UpdateGraphs.
        /// This will not update graphs immediately. See AstarPath.UpdateGraph for more info.
        /// </summary>
        public void Apply()
        {
            if (AstarPath.active == null)
            {
                Debug.LogError("There is no AstarPath object in the scene", this);
                return;
            }

            GraphUpdateObject guo;

            if (points == null || points.Length == 0)
            {
                var polygonCollider = GetComponent <PolygonCollider2D>();
                if (polygonCollider != null)
                {
                    var       points2D = polygonCollider.points;
                    Vector3[] pts      = new Vector3[points2D.Length];
                    for (int i = 0; i < pts.Length; i++)
                    {
                        var p = points2D[i] + polygonCollider.offset;
                        pts[i] = new Vector3(p.x, 0, p.y);
                    }

                    var mat   = transform.localToWorldMatrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 0, 0), Vector3.one);
                    var shape = new GraphUpdateShape(points, convex, mat, minBoundsHeight);
                    guo       = new GraphUpdateObject(GetBounds());
                    guo.shape = shape;
                }
                else
                {
                    var bounds = GetBounds();
                    if (bounds.center == Vector3.zero && bounds.size == Vector3.zero)
                    {
                        Debug.LogError("Cannot apply GraphUpdateScene, no points defined and no renderer or collider attached", this);
                        return;
                    }

                    guo = new GraphUpdateObject(bounds);
                }
            }
            else
            {
                GraphUpdateShape shape;
                if (legacyMode && !legacyUseWorldSpace)
                {
                    // Used for compatibility with older versions
                    var worldPoints = new Vector3[points.Length];
                    for (int i = 0; i < points.Length; i++)
                    {
                        worldPoints[i] = transform.TransformPoint(points[i]);
                    }
                    shape = new GraphUpdateShape(worldPoints, convex, Matrix4x4.identity, minBoundsHeight);
                }
                else
                {
                    shape = new GraphUpdateShape(points, convex, legacyMode && legacyUseWorldSpace ? Matrix4x4.identity : transform.localToWorldMatrix, minBoundsHeight);
                }
                var bounds = shape.GetBounds();
                guo       = new GraphUpdateObject(bounds);
                guo.shape = shape;
            }

            firstApplied = true;

            guo.modifyWalkability     = modifyWalkability;
            guo.setWalkability        = setWalkability;
            guo.addPenalty            = penaltyDelta;
            guo.updatePhysics         = updatePhysics;
            guo.updateErosion         = updateErosion;
            guo.resetPenaltyOnPhysics = resetPenaltyOnPhysics;

            guo.modifyTag = modifyTag;
            guo.setTag    = setTag;

            AstarPath.active.UpdateGraphs(guo);
        }
Beispiel #20
0
        /** Updates graphs with a created GUO.
         * Creates a Pathfinding.GraphUpdateObject with a Pathfinding.GraphUpdateShape
         * representing the polygon of this object and update all graphs using AstarPath.UpdateGraphs.
         * This will not update graphs directly. See AstarPath.UpdateGraph for more info.
         */
        public void Apply()
        {
            if (AstarPath.active == null)
            {
                Debug.LogError("There is no AstarPath object in the scene");
                return;
            }

            GraphUpdateObject guo;

            if (points == null || points.Length == 0)
            {
                var coll = GetComponent <Collider>();
                var rend = GetComponent <Renderer>();

                Bounds b;
                if (coll != null)
                {
                    b = coll.bounds;
                }
                else if (rend != null)
                {
                    b = rend.bounds;
                }
                else
                {
                    Debug.LogWarning("Cannot apply GraphUpdateScene, no points defined and no renderer or collider attached");
                    return;
                }

                if (b.size.y < minBoundsHeight)
                {
                    b.size = new Vector3(b.size.x, minBoundsHeight, b.size.z);
                }

                guo = new GraphUpdateObject(b);
            }
            else
            {
                var shape = new GraphUpdateShape();
                shape.convex = convex;
                Vector3[] worldPoints = points;
                if (!useWorldSpace)
                {
                    worldPoints = new Vector3[points.Length];
                    Matrix4x4 matrix = transform.localToWorldMatrix;
                    for (int i = 0; i < worldPoints.Length; i++)
                    {
                        worldPoints[i] = matrix.MultiplyPoint3x4(points[i]);
                    }
                }

                shape.points = worldPoints;

                Bounds b = shape.GetBounds();
                if (b.size.y < minBoundsHeight)
                {
                    b.size = new Vector3(b.size.x, minBoundsHeight, b.size.z);
                }
                guo       = new GraphUpdateObject(b);
                guo.shape = shape;
            }

            firstApplied = true;

            guo.modifyWalkability     = modifyWalkability;
            guo.setWalkability        = setWalkability;
            guo.addPenalty            = penaltyDelta;
            guo.updatePhysics         = updatePhysics;
            guo.updateErosion         = updateErosion;
            guo.resetPenaltyOnPhysics = resetPenaltyOnPhysics;

            guo.modifyTag = modifyTag;
            guo.setTag    = setTag;

            AstarPath.active.UpdateGraphs(guo);
        }
 void calculateBox(GraphUpdateShape gus)
 {
     gus.points = new Vector3[8];
     gus.points[0] = go.transform.TransformPoint(new Vector3(bounds.min.x, bounds.min.y, bounds.max.z));
     gus.points[1] = go.transform.TransformPoint(new Vector3(bounds.max.x, bounds.min.y, bounds.max.z));
     gus.points[2] = go.transform.TransformPoint(new Vector3(bounds.max.x, bounds.min.y, bounds.min.z));
     gus.points[3] = go.transform.TransformPoint(new Vector3(bounds.min.x, bounds.min.y, bounds.min.z));
     gus.points[7] = go.transform.TransformPoint(new Vector3(bounds.min.x, bounds.max.y, bounds.min.z));
     gus.points[4] = go.transform.TransformPoint(new Vector3(bounds.min.x, bounds.max.y, bounds.max.z));
     gus.points[5] = go.transform.TransformPoint(new Vector3(bounds.max.x, bounds.max.y, bounds.max.z));
     gus.points[6] = go.transform.TransformPoint(new Vector3(bounds.max.x, bounds.max.y, bounds.min.z));
 }