Beispiel #1
0
        /*
         * <summary>Recalculates all nodes to build a path from a given starting position</summary>
         * <param name = "startPosition">The position to start from</param>
         * <param name = "maxNodeDistance">If >0, the maximum allowed distance between two nodes</param>
         */
        public void RecalculateToCenter(Vector3 startPosition, float maxNodeDistance = -1f)
        {
            Vector3[] pointArray;
            Vector3   targetPosition = startPosition;

            if (SceneSettings.ActInScreenSpace())
            {
                targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
            }

            if (KickStarter.navigationManager != null)
            {
                pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(transform.position, targetPosition);
            }
            else
            {
                List <Vector3> pointList = new List <Vector3>();
                pointList.Add(targetPosition);
                pointArray = pointList.ToArray();
            }

            pointArray = SetMaxDistances(pointArray, maxNodeDistance);

            BuildNavPath(pointArray);
            pathType = AC_PathType.ReverseOnly;
        }
Beispiel #2
0
        /**
         * <summary>Rebuilds the nodes List from an array of points. The first point on the new path will be the GameObject's current position.</summary>
         * <param name = "pointData">An array of position vectors that dictate the new path</param>
         */
        public void BuildNavPath(Vector3[] pointData)
        {
            if (pointData != null && pointData.Length > 0)
            {
                pathType  = AC_PathType.ForwardOnly;
                affectY   = false;
                nodePause = 0;

                List <Vector3> newNodes = new List <Vector3>();

                newNodes.Clear();
                newNodes.Add(this.transform.position);

                nodeCommands.Clear();

                for (int i = 0; i < pointData.Length; i++)
                {
                    if (i == 0)
                    {
                        // If first point, ignore if same as position
                        if (SceneSettings.IsUnity2D())
                        {
                            Vector2 testPoint  = new Vector2(transform.position.x, transform.position.y);
                            Vector2 testPoint2 = new Vector2(pointData[0].x, pointData[0].y);
                            if ((testPoint - testPoint2).magnitude < 0.001f)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            Vector3 testPoint = new Vector3(transform.position.x, pointData[0].y, transform.position.z);
                            if ((testPoint - pointData[0]).magnitude < 0.001f)
                            {
                                continue;
                            }
                        }
                    }
                    newNodes.Add(pointData[i]);
                }

                nodes = newNodes;
            }
        }
Beispiel #3
0
		public void BuildNavPath (Vector3[] pointData)
		{
			if (pointData.Length > 0)
			{
				pathType = AC_PathType.ForwardOnly;
				affectY = false;
				nodePause = 0;
				
				nodes.Clear ();
				nodes.Add (this.transform.position);

				nodeCommands.Clear ();
				
				foreach (Vector3 point in pointData)
				{
					nodes.Add (point);
				}
			}
		}
Beispiel #4
0
        public void BuildNavPath(Vector3[] pointData)
        {
            if (pointData.Length > 0)
            {
                pathType  = AC_PathType.ForwardOnly;
                affectY   = false;
                nodePause = 0;

                nodes.Clear();
                nodes.Add(this.transform.position);

                nodeCommands.Clear();

                foreach (Vector3 point in pointData)
                {
                    nodes.Add(point);
                }
            }
        }
Beispiel #5
0
        /**
         * <summary>Rebuilds the nodes List from an array of points. The first point on the new path will be the GameObject's current position.</summary>
         * <param name = "pointData">An array of position vectors that dictate the new path</param>
         */
        public void BuildNavPath(Vector3[] pointData)
        {
            if (pointData.Length > 0)
            {
                pathType = AC_PathType.ForwardOnly;
                affectY = false;
                nodePause = 0;

                List<Vector3> newNodes = new List<Vector3>();

                newNodes.Clear ();
                newNodes.Add (this.transform.position);

                nodeCommands.Clear ();

                for (int i=0; i<pointData.Length; i++)
                {
                    if (i==0)
                    {
                        // If first point, ignore if same as position
                        if (KickStarter.settingsManager.IsUnity2D ())
                        {
                            Vector2 testPoint = new Vector2 (transform.position.x, transform.position.y);
                            Vector2 testPoint2 = new Vector2 (pointData[0].x, pointData[0].y);
                            if ((testPoint - testPoint2).magnitude < 0.001f)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            Vector3 testPoint = new Vector3 (transform.position.x, pointData[0].y, transform.position.z);
                            if ((testPoint - pointData[0]).magnitude < 0.001f)
                            {
                                continue;
                            }
                        }

                    }
                    newNodes.Add (pointData[i]);
                }

                nodes = newNodes;
            }
        }