Ejemplo n.º 1
0
		protected void Setup (Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callback) {
			inverted = false;
			this.callback = callback;
			callbacks = callbackDelegates;
			
			targetPoints = targets;
			
			originalStartPoint = start;
			//originalEndPoint = end;
			
			startPoint = start;
			startIntPoint = (Int3)start;
			
			if (targets.Length == 0) {
				Error ();
				LogError ("No targets were assigned to the MultiTargetPath");
				return;
			}
			
			endPoint = targets[0];
			
			originalTargetPoints = new Vector3[targetPoints.Length];
			for (int i=0;i<targetPoints.Length;i++) {
				originalTargetPoints[i] = targetPoints[i];
			}
		}
Ejemplo n.º 2
0
        public RandomPath(Vector3 start, int length, OnPathDelegate callbackDelegate = null)
        {
            callTime = System.DateTime.Now;

            callback = callbackDelegate;

            searchLength = length;

            if (AstarPath.active == null || AstarPath.active.graphs == null) {
                errorLog += "No NavGraphs have been calculated yet - Don't run any pathfinding calls in Awake";
                if (AstarPath.active.logPathResults != PathLog.None) {
                    Debug.LogError (errorLog);
                }
                error = true;
                return;
            }

            pathID = AstarPath.active.GetNextPathID ();

            originalStartPoint = start;
            originalEndPoint = Vector3.zero;

            startPoint = start;
            endPoint = Vector3.zero;

            startIntPoint = (Int3)start;
            hTarget = (Int3)aim;//(Int3)(start-aim);//new Int3(0,0,0);
            rnd = new System.Random ();
        }
Ejemplo n.º 3
0
		public static FloodPath Construct (GraphNode start, OnPathDelegate callback = null) {
			if (start == null) throw new ArgumentNullException("start");

			var p = PathPool.GetPath<FloodPath>();
			p.Setup(start, callback);
			return p;
		}
Ejemplo n.º 4
0
 protected void Setup(Vector3 start, Vector3 avoid, int searchLength, OnPathDelegate callback)
 {
     Setup (start, searchLength, callback);
     aim = avoid-start;
     aim *= 10;
     aim = start - aim;
 }
Ejemplo n.º 5
0
		public new static XPath Construct (Vector3 start, Vector3 end, OnPathDelegate callback = null) {
			var p = PathPool.GetPath<XPath>();

			p.Setup(start, end, callback);
			p.endingCondition = new ABPathEndingCondition(p);
			return p;
		}
		/** Sets up a ConstantPath starting from the specified point */
		protected void Setup (Vector3 start, int maxGScore, OnPathDelegate callback) {
			this.callback = callback;
			startPoint = start;
			originalStartPoint = startPoint;

			endingCondition = new EndingConditionDistance (this,maxGScore);
		}
Ejemplo n.º 7
0
 public FloodPathTracer(Vector3 start, FloodPath flood, OnPathDelegate callbackDelegate)
     : base(start,flood.originalStartPoint,callbackDelegate)
 {
     this.flood = flood;
     if (flood == null || !flood.processed)
         throw new System.ArgumentNullException ("You must supply a calculated FloodPath to the 'flood' argument");
     hasEndPoint = false;
     nnConstraint = new PathIDConstraint ();
 }
Ejemplo n.º 8
0
		protected void Setup (Vector3 start, FloodPath flood, OnPathDelegate callback) {
			this.flood = flood;

			if (flood == null || flood.GetState () < PathState.Returned) {
				throw new System.ArgumentException ("You must supply a calculated FloodPath to the 'flood' argument");
			}

			base.Setup (start, flood.originalStartPoint, callback);
			nnConstraint = new FloodPathConstraint (flood);
		}
Ejemplo n.º 9
0
        public FleePath(Vector3 start, Vector3 avoid, int length, OnPathDelegate callbackDelegate = null)
            : base(start,length,callbackDelegate)
        {
            /*if (AstarPath.active.heuristicScale == 0) {
                heuristicScale = -1;
            } else {
                heuristicScale = System.Math.Abs (AstarPath.active.heuristicScale) * -1;
            }*/

            originalEndPoint = avoid;

            endPoint = avoid;
            searchLength = length;
            hTarget = (Int3)avoid;
        }
Ejemplo n.º 10
0
        public MultiTargetPath(Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callbackDelegate = null)
        {
            inverted = false;
            callback = callbackDelegate;
            callbacks = callbackDelegates;

            pathID = AstarPath.active.GetNextPathID ();

            if (AstarPath.active == null || AstarPath.active.graphs == null) {
                errorLog += "No NavGraphs have been calculated yet - Don't run any pathfinding calls in Awake";
                if (AstarPath.active.logPathResults != PathLog.None) {
                    Debug.LogError (errorLog);
                }
                error = true;
                return;
            }

            targetPoints = targets;

            originalStartPoint = start;
            //originalEndPoint = end;

            startPoint = start;
            startIntPoint = (Int3)start;

            if (targets.Length == 0) {
                error = true;
                errorLog += "No targets were assigned\n";
                return;
            }

            endPoint = targets[0];

            originalTargetPoints = new Vector3[targetPoints.Length];
            for (int i=0;i<targetPoints.Length;i++) {
                originalTargetPoints[i] = targetPoints[i];
            }

            //heuristic = Heuristic.Euclidean;//Heuristic.None;
            //heuristicScale = 1F;
        }
Ejemplo n.º 11
0
		/** Reset all values to their default values.
		 *
		 * \note All inheriting path types (e.g ConstantPath, RandomPath, etc.) which declare their own variables need to
		 * override this function, resetting ALL their variables to enable recycling of paths.
		 * If this is not done, trying to use that path type for pooling might result in weird behaviour.
		 * The best way is to reset to default values the variables declared in the extended path type and then
		 * call this base function in inheriting types with base.Reset ().
		 *
		 * \warning This function should not be called manually.
		  */
		public virtual void Reset () {

			if (System.Object.ReferenceEquals (AstarPath.active, null))
				throw new System.NullReferenceException ("No AstarPath object found in the scene. " +
					"Make sure there is one or do not create paths in Awake");

			hasBeenReset = true;
			state = (int)PathState.Created;
			releasedNotSilent = false;

			pathHandler = null;
			callback = null;
			_errorLog = "";
			pathCompleteState = PathCompleteState.NotCalculated;

			path = Pathfinding.Util.ListPool<GraphNode>.Claim();
			vectorPath = Pathfinding.Util.ListPool<Vector3>.Claim();

			currentR = null;

			duration = 0;
			searchIterations = 0;
			searchedNodes = 0;
			//calltime

			nnConstraint = PathNNConstraint.Default;
			next = null;

			heuristic = AstarPath.active.heuristic;
			heuristicScale = AstarPath.active.heuristicScale;

			enabledTags = -1;
			tagPenalties = null;

			callTime = System.DateTime.UtcNow;
			pathID = AstarPath.active.GetNextPathID ();

			hTarget = Int3.zero;
			hTargetNode = null;
		}
Ejemplo n.º 12
0
        /** Initializes the path. Sets up the open list and adds the first node to it */
        public virtual void Initialize()
        {
            System.DateTime startTime = System.DateTime.Now;

            //Resets the binary heap, don't clear it because that takes an awful lot of time, instead we can just change the numberOfItems in it (which is just an int)
            //Binary heaps are just like a standard array but are always sorted so the node with the lowest F value can be retrieved faster

            open = AstarPath.active.binaryHeap;
            open.numberOfItems = 1;

            if (hasEndPoint && startNode == endNode)
            {
                endNode.parent = null;
                endNode.h = 0;
                endNode.g = 0;
                Trace(endNode);
                foundEnd = true;

                return;
            }

            //Adjust the costs for the end node
            if (hasEndPoint && recalcStartEndCosts)
            {
                endNodeCosts = endNode.InitialOpen(open, hTarget, (Int3)endPoint, this, false);
                callback += ResetCosts; /** \todo Might interfere with other paths since other paths might be calculated before #callback is called */
            }

            Node.activePath = this;
            startNode.pathID = pathID;
            startNode.parent = null;
            startNode.cost = 0;
            startNode.g = startNode.penalty;
            startNode.UpdateH(hTarget, heuristic, heuristicScale);

            if (recalcStartEndCosts)
            {
                startNode.InitialOpen(open, hTarget, startIntPoint, this, true);
            }
            else
            {
                startNode.Open(open, hTarget, this);
            }

            searchedNodes++;

            //any nodes left to search?
            if (open.numberOfItems <= 1)
            {
                LogError("No open points, the start node didn't open any nodes");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            current = open.Remove();

            duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
        }
Ejemplo n.º 13
0
		public XPath (Vector3 start, Vector3 end, OnPathDelegate callbackDelegate) : base (start,end,callbackDelegate) {}
	/** Call this function to start calculating a path.
	 * \param start		The start point of the path
	 * \param end		The end point of the path
	 * \param callback	The function to call when the path has been calculated
	 * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.
	 * 
	 * \a callback will be called when the path has completed.
	 * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
	public Path StartPath (Vector3 start, Vector3 end, OnPathDelegate callback, int graphMask) {
		Path p = GetNewPath (start,end);
		return StartPath (p, callback, graphMask);
	}
		protected void Setup (Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callback) {
			inverted = false;
			this.callback = callback;
			callbacks = callbackDelegates;
			if (callbacks != null && callbacks.Length != targets.Length) throw new System.ArgumentException("The targets array must have the same length as the callbackDelegates array");
			targetPoints = targets;

			originalStartPoint = start;

			startPoint = start;
			startIntPoint = (Int3)start;

			if (targets.Length == 0) {
				FailWithError("No targets were assigned to the MultiTargetPath");
				return;
			}

			endPoint = targets[0];

			originalTargetPoints = new Vector3[targetPoints.Length];
			for (int i = 0; i < targetPoints.Length; i++) {
				originalTargetPoints[i] = targetPoints[i];
			}
		}
Ejemplo n.º 16
0
	/** Call this function to start calculating a path.
	 * \param p			The path to start calculating
	 * \param callback	The function to call when the path has been calculated
	 * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. \astarproParam
	 * 
	 * \a callback will be called when the path has completed.
	 * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
	public Path StartPath (Path p, OnPathDelegate callback = null, int graphMask = -1) {
		p.enabledTags = traversableTags.tagsChange;
		p.tagPenalties = tagPenalties;
		
#if !AstarFree && FALSE
		//In case a multi target path has been specified, call special logic
		if (p.GetType () == typeof (MultiTargetPath)) {
			return StartMultiTargetPath (p as MultiTargetPath,callback);
		}
#endif
		//Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
		if (path != null && path.GetState() <= PathState.Processing && lastPathID == path.pathID) {
			path.Error();
			path.LogError ("Canceled path because a new one was requested.\n"+
				"This happens when a new path is requested from the seeker when one was already being calculated.\n" +
				"For example if a unit got a new order, you might request a new path directly instead of waiting for the now" +
				" invalid path to be calculated. Which is probably what you want.\n" +
				"If you are getting this a lot, you might want to consider how you are scheduling path requests.");
			//No callback should be sent for the canceled path
		}
		
		path = p;
		path.callback += onPathDelegate;
		path.nnConstraint.graphMask = graphMask;
		
		tmpPathCallback = callback;
		
		//Set the Get Nearest Node hints if they have not already been set
		/*if (path.startHint == null)
			path.startHint = startHint;
			
		if (path.endHint == null) 
			path.endHint = endHint;
		*/
		
		//Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
		lastPathID = path.pathID;
		
		//Delay the path call by one frame if it was sent the same frame as the previous call
		/*if (lastPathCall == Time.frameCount) {
			StartCoroutine (DelayPathStart (path));
			return path;
		}*/
		
		//lastPathCall = Time.frameCount;
		
		//Pre process the path
		RunModifiers (ModifierPass.PreProcess, path);
		
		//Send the request to the pathfinder
		AstarPath.StartPath (path);
		
		return path;
	}
Ejemplo n.º 17
0
        // Token: 0x06000779 RID: 1913 RVA: 0x000486E4 File Offset: 0x00046AE4
        public static MultiTargetPath Construct(Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callback = null)
        {
            MultiTargetPath path = PathPool <MultiTargetPath> .GetPath();

            path.Setup(start, targets, callbackDelegates, callback);
            return(path);
        }
Ejemplo n.º 18
0
    /** Initializes a few variables
     */
    public void Awake()
    {
        onPathDelegate = OnPathComplete;

        startEndModifier.Awake(this);
    }
Ejemplo n.º 19
0
 public static Path SeekerGetPath(this Seeker seeker, [CanBeNull] GameObject self, [CanBeNull] GameObject target, OnPathDelegate callback = null)
 {
     //TODO 可以进行一些检测
     if (callback != null)
     {
         return(seeker.StartPath(self.transform.position, target.transform.position, callback));
     }
     else
     {
         return(seeker.StartPath(self.transform.position, target.transform.position, null));
     }
 }
Ejemplo n.º 20
0
 protected void Setup(ref Int3 start, ref Int3 end, OnPathDelegate callbackDelegate)
 {
     this.callback = callbackDelegate;
     this.UpdateStartEnd(ref start, ref end);
 }
Ejemplo n.º 21
0
 public static ABPath Construct(Vector3 v, Vector3 t, int l, OnPathDelegate o)
 {
     return(null);
 }
Ejemplo n.º 22
0
 public ABPath(Int3 start, Int3 end, OnPathDelegate callbackDelegate)
 {
     this.Reset();
     this.Setup(ref start, ref end, callbackDelegate);
 }
Ejemplo n.º 23
0
 public FloodPathTracer(Vector3 start, FloodPath flood, OnPathDelegate callbackDelegate)
 {
     throw new Exception("This constructor is obsolete");
 }
		public static MultiTargetPath Construct (Vector3[] startPoints, Vector3 target, OnPathDelegate[] callbackDelegates, OnPathDelegate callback = null) {
			MultiTargetPath p = Construct(target, startPoints, callbackDelegates, callback);

			p.inverted = true;
			return p;
		}
Ejemplo n.º 25
0
	/** Clears up variables and other stuff, destroys graphs.
	 * Note that when destroying an AstarPath object, all static variables such as callbacks will be cleared.
	 */
	public void OnDestroy () {
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("+++ AstarPath Component Destroyed - Cleaning Up Pathfinding Data +++");
		
		if ( active != this ) return;
		
		
		//Don't accept any more path calls to this AstarPath instance.
		//This will cause all eventual multithreading threads to exit
		pathQueue.TerminateReceivers();

		BlockUntilPathQueueBlocked();
		FlushWorkItems ();

		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Processing Eventual Work Items");
		
		// Process work items until done 
		// Nope, don't do this
		//PerformBlockingActions (true);
		
		//Resume graph update thread, will cause it to terminate
		graphUpdateAsyncEvent.Set();
		
		//Try to join pathfinding threads
		if (threads != null) {
			for (int i=0;i<threads.Length;i++) {
#if UNITY_WEBPLAYER
				if (!threads[i].Join(200)) {
					Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 200ms." +
						"Not good.\nUnity webplayer does not support Thread.Abort\nHoping that it will be terminated by Unity WebPlayer");
				}
#else
				if (!threads[i].Join (50)) {
					Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 50ms, trying Thread.Abort");
					threads[i].Abort ();
				}
#endif
			}
		}
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Returning Paths");
		
		
		//Return all paths
		ReturnPaths (false);
		//Just in case someone happened to request a path in ReturnPath() (even though they should get canceled)
		pathReturnStack.PopAll ();
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Destroying Graphs");

		
		//Clean graphs up
		astarData.OnDestroy ();
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Cleaning up variables");
		
		//Clear variables up, static variables are good to clean up, otherwise the next scene might get weird data
		floodStack = null;
		graphUpdateQueue = null;
		
		//Clear all callbacks
		OnDrawGizmosCallback	= null;
		OnAwakeSettings			= null;
		OnGraphPreScan			= null;
		OnGraphPostScan			= null;
		OnPathPreSearch			= null;
		OnPathPostSearch		= null;
		OnPreScan				= null;
		OnPostScan				= null;
		OnLatePostScan			= null;
		On65KOverflow			= null;
		OnGraphsUpdated			= null;
		OnSafeCallback			= null;
		OnThreadSafeCallback	= null;
		
		threads = null;
		threadInfos = null;
		
		PathsCompleted = 0;
		
		active = null;
		
	}
Ejemplo n.º 26
0
        protected void Setup(Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callback)
        {
            inverted      = false;
            this.callback = callback;
            callbacks     = callbackDelegates;

            targetPoints = targets;

            originalStartPoint = start;

            startPoint    = start;
            startIntPoint = (Int3)start;

            if (targets.Length == 0)
            {
                Error();
                LogError("No targets were assigned to the MultiTargetPath");
                return;
            }

            endPoint = targets[0];

            originalTargetPoints = new Vector3[targetPoints.Length];
            for (int i = 0; i < targetPoints.Length; i++)
            {
                originalTargetPoints[i] = targetPoints[i];
            }
        }
Ejemplo n.º 27
0
	/** Call this function to start calculating a path.
	 * \param start		The start point of the path
	 * \param end		The end point of the path
	 * \param callback	The function to call when the path has been calculated
	 * 
	 * \a callback will be called when the path has completed.
	 * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
	public Path StartPath (Vector3 start, Vector3 end, OnPathDelegate callback) {
		return StartPath (start,end,callback,-1);
	}
        // Token: 0x06002322 RID: 8994 RVA: 0x00193BD0 File Offset: 0x00191DD0
        private IEnumerator CalculatePaths(PathHandler pathHandler)
        {
            long maxTicks   = (long)(this.astar.maxFrameTime * 10000f);
            long targetTick = DateTime.UtcNow.Ticks + maxTicks;

            for (;;)
            {
                Path p             = null;
                bool blockedBefore = false;
                while (p == null)
                {
                    try
                    {
                        p              = this.queue.PopNoBlock(blockedBefore);
                        blockedBefore |= (p == null);
                    }
                    catch (ThreadControlQueue.QueueTerminationException)
                    {
                        yield break;
                    }
                    if (p == null)
                    {
                        yield return(null);
                    }
                }
                IPathInternals ip = p;
                maxTicks = (long)(this.astar.maxFrameTime * 10000f);
                ip.PrepareBase(pathHandler);
                ip.AdvanceState(PathState.Processing);
                Action <Path> onPathPreSearch = this.OnPathPreSearch;
                if (onPathPreSearch != null)
                {
                    onPathPreSearch(p);
                }
                long ticks      = DateTime.UtcNow.Ticks;
                long totalTicks = 0L;
                ip.Prepare();
                if (!p.IsDone())
                {
                    this.astar.debugPathData = ip.PathHandler;
                    this.astar.debugPathID   = p.pathID;
                    ip.Initialize();
                    while (!p.IsDone())
                    {
                        ip.CalculateStep(targetTick);
                        if (p.IsDone())
                        {
                            break;
                        }
                        totalTicks += DateTime.UtcNow.Ticks - ticks;
                        yield return(null);

                        ticks = DateTime.UtcNow.Ticks;
                        if (this.queue.IsTerminating)
                        {
                            p.FailWithError("AstarPath object destroyed");
                        }
                        targetTick = DateTime.UtcNow.Ticks + maxTicks;
                    }
                    totalTicks += DateTime.UtcNow.Ticks - ticks;
                    p.duration  = (float)totalTicks * 0.0001f;
                }
                ip.Cleanup();
                OnPathDelegate immediateCallback = p.immediateCallback;
                if (immediateCallback != null)
                {
                    immediateCallback(p);
                }
                Action <Path> onPathPostSearch = this.OnPathPostSearch;
                if (onPathPostSearch != null)
                {
                    onPathPostSearch(p);
                }
                this.returnQueue.Enqueue(p);
                ip.AdvanceState(PathState.ReturnQueue);
                if (DateTime.UtcNow.Ticks > targetTick)
                {
                    yield return(null);

                    targetTick = DateTime.UtcNow.Ticks + maxTicks;
                }
                p  = null;
                ip = null;
            }
            yield break;
        }
Ejemplo n.º 29
0
	/** Starts a Multi Target Path. Takes a MultiTargetPath and wires everything up for it to send callbacks to the seeker for post-processing.\n
	 * \param p				The path to start calculating
	 * \param callback		The function to call when the path has been calculated
	 * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. \astarproParam
	 * 
	 * \a callback and #pathCallback will be called when the path has completed. \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
	 * \astarpro
	 * \see Pathfinding.MultiTargetPath
	 * \see \ref MultiTargetPathExample.cs "Example of how to use multi-target-paths"
	 */
	public MultiTargetPath StartMultiTargetPath (MultiTargetPath p, OnPathDelegate callback = null, int graphMask = -1) {
			
		//Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
		if (path != null && path.GetState () <= PathState.Processing && lastPathID == path.pathID) {
			path.ForceLogError ("Canceled path because a new one was requested");
			//No callback should be sent for the canceled path
		}
		
		OnPathDelegate[] callbacks = new OnPathDelegate[p.targetPoints.Length];
		for (int i=0;i<callbacks.Length;i++) {
			callbacks[i] = onPartialPathDelegate;
		}
		
		p.callbacks = callbacks;
		p.callback += OnMultiPathComplete;
		p.nnConstraint.graphMask = graphMask;
		
		path = p;
		
		tmpPathCallback = callback;
		
		//Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
		lastPathID = path.pathID;
		
		//Delay the path call by one frame if it was sent the same frame as the previous call
		/*if (lastPathCall == Time.frameCount) {
			StartCoroutine (DelayPathStart (path));
			return p;
		}
		
		lastPathCall = Time.frameCount;*/
		
		//Pre process the path
		RunModifiers (ModifierPass.PreProcess, path);
		
		//Send the request to the pathfinder
		AstarPath.StartPath (path);
		
		return p;
	}
Ejemplo n.º 30
0
    static int StartMultiTargetPath(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                Pathfinding.MultiTargetPath arg0 = (Pathfinding.MultiTargetPath)ToLua.CheckObject <Pathfinding.MultiTargetPath>(L, 2);
                Pathfinding.MultiTargetPath o    = obj.StartMultiTargetPath(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3)
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                Pathfinding.MultiTargetPath arg0 = (Pathfinding.MultiTargetPath)ToLua.CheckObject <Pathfinding.MultiTargetPath>(L, 2);
                OnPathDelegate arg1           = (OnPathDelegate)ToLua.CheckDelegate <OnPathDelegate>(L, 3);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.Vector3[], UnityEngine.Vector3, bool>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                UnityEngine.Vector3[] arg0 = ToLua.ToStructArray <UnityEngine.Vector3>(L, 2);
                UnityEngine.Vector3   arg1 = ToLua.ToVector3(L, 3);
                bool arg2 = LuaDLL.lua_toboolean(L, 4);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <Pathfinding.MultiTargetPath, OnPathDelegate, int>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                Pathfinding.MultiTargetPath arg0 = (Pathfinding.MultiTargetPath)ToLua.ToObject(L, 2);
                OnPathDelegate arg1           = (OnPathDelegate)ToLua.ToObject(L, 3);
                int            arg2           = (int)LuaDLL.lua_tonumber(L, 4);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.Vector3, UnityEngine.Vector3[], bool>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3[] arg1 = ToLua.ToStructArray <UnityEngine.Vector3>(L, 3);
                bool arg2 = LuaDLL.lua_toboolean(L, 4);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <UnityEngine.Vector3, UnityEngine.Vector3[], bool, OnPathDelegate>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                UnityEngine.Vector3   arg0    = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3[] arg1    = ToLua.ToStructArray <UnityEngine.Vector3>(L, 3);
                bool           arg2           = LuaDLL.lua_toboolean(L, 4);
                OnPathDelegate arg3           = (OnPathDelegate)ToLua.ToObject(L, 5);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <UnityEngine.Vector3[], UnityEngine.Vector3, bool, OnPathDelegate>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                UnityEngine.Vector3[] arg0    = ToLua.ToStructArray <UnityEngine.Vector3>(L, 2);
                UnityEngine.Vector3   arg1    = ToLua.ToVector3(L, 3);
                bool           arg2           = LuaDLL.lua_toboolean(L, 4);
                OnPathDelegate arg3           = (OnPathDelegate)ToLua.ToObject(L, 5);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes <UnityEngine.Vector3, UnityEngine.Vector3[], bool, OnPathDelegate, int>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                UnityEngine.Vector3   arg0    = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3[] arg1    = ToLua.ToStructArray <UnityEngine.Vector3>(L, 3);
                bool           arg2           = LuaDLL.lua_toboolean(L, 4);
                OnPathDelegate arg3           = (OnPathDelegate)ToLua.ToObject(L, 5);
                int            arg4           = (int)LuaDLL.lua_tonumber(L, 6);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2, arg3, arg4);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes <UnityEngine.Vector3[], UnityEngine.Vector3, bool, OnPathDelegate, int>(L, 2))
            {
                Seeker obj = (Seeker)ToLua.CheckObject <Seeker>(L, 1);
                UnityEngine.Vector3[] arg0    = ToLua.ToStructArray <UnityEngine.Vector3>(L, 2);
                UnityEngine.Vector3   arg1    = ToLua.ToVector3(L, 3);
                bool           arg2           = LuaDLL.lua_toboolean(L, 4);
                OnPathDelegate arg3           = (OnPathDelegate)ToLua.ToObject(L, 5);
                int            arg4           = (int)LuaDLL.lua_tonumber(L, 6);
                Pathfinding.MultiTargetPath o = obj.StartMultiTargetPath(arg0, arg1, arg2, arg3, arg4);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Seeker.StartMultiTargetPath"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 31
0
        private IEnumerator CalculatePaths(PathThreadInfo threadInfo)
        {
            int         numPaths = 0;
            PathHandler runData  = threadInfo.runData;

            if (runData.nodes == null)
            {
                throw new NullReferenceException("NodeRuns must be assigned to the threadInfo.runData.nodes field before threads are started\nthreadInfo is an argument to the thread functions");
            }
            long maxTicks   = (long)(this.astar.maxFrameTime * 10000f);
            long targetTick = DateTime.UtcNow.Ticks + maxTicks;

            for (;;)
            {
                Path p             = null;
                bool blockedBefore = false;
                while (p == null)
                {
                    try
                    {
                        p              = this.queue.PopNoBlock(blockedBefore);
                        blockedBefore |= (p == null);
                    }
                    catch (ThreadControlQueue.QueueTerminationException)
                    {
                        yield break;
                    }
                    if (p == null)
                    {
                        yield return(null);
                    }
                }
                IPathInternals ip = p;
                maxTicks = (long)(this.astar.maxFrameTime * 10000f);
                ip.PrepareBase(runData);
                ip.AdvanceState(PathState.Processing);
                Action <Path> tmpOnPathPreSearch = this.OnPathPreSearch;
                if (tmpOnPathPreSearch != null)
                {
                    tmpOnPathPreSearch(p);
                }
                numPaths++;
                long startTicks = DateTime.UtcNow.Ticks;
                long totalTicks = 0L;
                ip.Prepare();
                if (!p.IsDone())
                {
                    this.astar.debugPathData = ip.PathHandler;
                    this.astar.debugPathID   = p.pathID;
                    ip.Initialize();
                    while (!p.IsDone())
                    {
                        ip.CalculateStep(targetTick);
                        if (p.IsDone())
                        {
                            break;
                        }
                        totalTicks += DateTime.UtcNow.Ticks - startTicks;
                        yield return(null);

                        startTicks = DateTime.UtcNow.Ticks;
                        if (this.queue.IsTerminating)
                        {
                            p.Error();
                        }
                        targetTick = DateTime.UtcNow.Ticks + maxTicks;
                    }
                    totalTicks += DateTime.UtcNow.Ticks - startTicks;
                    p.duration  = (float)totalTicks * 0.0001f;
                }
                ip.Cleanup();
                OnPathDelegate tmpImmediateCallback = p.immediateCallback;
                if (tmpImmediateCallback != null)
                {
                    tmpImmediateCallback(p);
                }
                Action <Path> tmpOnPathPostSearch = this.OnPathPostSearch;
                if (tmpOnPathPostSearch != null)
                {
                    tmpOnPathPostSearch(p);
                }
                this.returnQueue.Enqueue(p);
                ip.AdvanceState(PathState.ReturnQueue);
                if (DateTime.UtcNow.Ticks > targetTick)
                {
                    yield return(null);

                    targetTick = DateTime.UtcNow.Ticks + maxTicks;
                    numPaths   = 0;
                }
            }
            yield break;
        }
Ejemplo n.º 32
0
 protected void Setup(Vector3 start, Vector3 end, OnPathDelegate callbackDelegate)
 {
     callback = callbackDelegate;
     UpdateStartEnd(start, end);
 }
Ejemplo n.º 33
0
		protected void Setup (Vector3 start, Vector3 end, OnPathDelegate callbackDelegate) {
			callback = callbackDelegate;
			UpdateStartEnd (start,end);
		}
		public static MultiTargetPath Construct (Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callback = null) {
			var p = PathPool.GetPath<MultiTargetPath>();

			p.Setup(start, targets, callbackDelegates, callback);
			return p;
		}
Ejemplo n.º 35
0
 public virtual void Reset()
 {
     if (object.ReferenceEquals(AstarPath.active, null))
     {
         throw new NullReferenceException("No AstarPath object found in the scene. Make sure there is one or do not create paths in Awake");
     }
     this.hasBeenReset = true;
     this.state = PathState.Created;
     this.releasedNotSilent = false;
     this.pathHandler = null;
     this.callback = null;
     this._errorLog = string.Empty;
     this.pathCompleteState = PathCompleteState.NotCalculated;
     this.path = ListPool<GraphNode>.Claim();
     this.vectorPath = ListPool<Vector3>.Claim();
     this.currentR = null;
     this.duration = 0f;
     this.searchIterations = 0;
     this.searchedNodes = 0;
     this.nnConstraint = PathNNConstraint.Default;
     this.next = null;
     this.heuristic = AstarPath.active.heuristic;
     this.heuristicScale = AstarPath.active.heuristicScale;
     this.enabledTags = -1;
     this.tagPenalties = null;
     this.callTime = DateTime.UtcNow;
     this.pathID = AstarPath.active.GetNextPathID();
     this.hTarget = Int3.zero;
     this.hTargetNode = null;
 }
Ejemplo n.º 36
0
 public ABPath(Vector3 start, Vector3 end, OnPathDelegate callbackDelegate)
 {
     Reset();
     Setup(start, end, callbackDelegate);
 }
Ejemplo n.º 37
0
        public void RecalculateCosts()
        {
            if (pivots == null)
            {
                RecalculatePivots();
            }
            if (mode == HeuristicOptimizationMode.None)
            {
                return;
            }

            pivotCount = 0;

            for (int i = 0; i < pivots.Length; i++)
            {
                if (pivots[i] != null && (pivots[i].Destroyed || !pivots[i].Walkable))
                {
                    throw new System.Exception("Invalid pivot nodes (destroyed or unwalkable)");
                }
            }

            if (mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                for (int i = 0; i < pivots.Length; i++)
                {
                    if (pivots[i] == null)
                    {
                        throw new System.Exception("Invalid pivot nodes (null)");
                    }
                }
            }

            Debug.Log("Recalculating costs...");
            pivotCount = pivots.Length;

            System.Action <int> startCostCalculation = null;

            int            numComplete = 0;
            OnPathDelegate onComplete  = (Path path) => {
                numComplete++;
                if (numComplete == pivotCount)
                {
                    // Last completed path
                    Debug.Log("Grid graph special case!");
                    ApplyGridGraphEndpointSpecialCase();
                }
            };

            startCostCalculation = (int pivotIndex) => {
                GraphNode pivot = pivots[pivotIndex];

                FloodPath floodPath = null;
                floodPath = FloodPath.Construct(pivot, onComplete);
                floodPath.immediateCallback = (Path _p) => {
                    // Handle path pooling
                    _p.Claim(this);

                    // When paths are calculated on navmesh based graphs
                    // the costs are slightly modified to match the actual target and start points
                    // instead of the node centers
                    // so we have to remove the cost for the first and last connection
                    // in each path
                    var  meshNode   = pivot as MeshNode;
                    uint costOffset = 0;
                    if (meshNode != null && meshNode.connections != null)
                    {
                        for (int i = 0; i < meshNode.connections.Length; i++)
                        {
                            costOffset = System.Math.Max(costOffset, meshNode.connections[i].cost);
                        }
                    }


                    var graphs = AstarPath.active.graphs;
                    // Process graphs in reverse order to raise probability that we encounter large NodeIndex values quicker
                    // to avoid resizing the internal array too often
                    for (int j = graphs.Length - 1; j >= 0; j--)
                    {
                        graphs[j].GetNodes(node => {
                            int idx = node.NodeIndex * pivotCount + pivotIndex;
                            EnsureCapacity(idx);
                            PathNode pn = ((IPathInternals)floodPath).PathHandler.GetPathNode(node);
                            if (costOffset > 0)
                            {
                                costs[idx] = pn.pathID == floodPath.pathID && pn.parent != null ? System.Math.Max(pn.parent.G - costOffset, 0) : 0;
                            }
                            else
                            {
                                costs[idx] = pn.pathID == floodPath.pathID ? pn.G : 0;
                            }
                        });
                    }

                    if (mode == HeuristicOptimizationMode.RandomSpreadOut && pivotIndex < pivots.Length - 1)
                    {
                        // If the next pivot is null
                        // then find the node which is furthest away from the earlier
                        // pivot points
                        if (pivots[pivotIndex + 1] == null)
                        {
                            int  best      = -1;
                            uint bestScore = 0;

                            // Actual number of nodes
                            int totCount = maxNodeIndex / pivotCount;

                            // Loop through all nodes
                            for (int j = 1; j < totCount; j++)
                            {
                                // Find the minimum distance from the node to all existing pivot points
                                uint mx = 1 << 30;
                                for (int p = 0; p <= pivotIndex; p++)
                                {
                                    mx = System.Math.Min(mx, costs[j * pivotCount + p]);
                                }

                                // Pick the node which has the largest minimum distance to the existing pivot points
                                // (i.e pick the one furthest away from the existing ones)
                                GraphNode node = ((IPathInternals)floodPath).PathHandler.GetPathNode(j).node;
                                if ((mx > bestScore || best == -1) && node != null && !node.Destroyed && node.Walkable)
                                {
                                    best      = j;
                                    bestScore = mx;
                                }
                            }

                            if (best == -1)
                            {
                                Debug.LogError("Failed generating random pivot points for heuristic optimizations");
                                return;
                            }

                            pivots[pivotIndex + 1] = ((IPathInternals)floodPath).PathHandler.GetPathNode(best).node;
                        }

                        // Start next path
                        startCostCalculation(pivotIndex + 1);
                    }

                    // Handle path pooling
                    _p.Release(this);
                };

                AstarPath.StartPath(floodPath, true);
            };

            if (mode != HeuristicOptimizationMode.RandomSpreadOut)
            {
                // All calculated in parallel
                for (int i = 0; i < pivots.Length; i++)
                {
                    startCostCalculation(i);
                }
            }
            else
            {
                // Recursive and serial
                startCostCalculation(0);
            }

            dirty = false;
        }
Ejemplo n.º 38
0
 public void RequestPath(PathRequest request, OnPathDelegate callback)
 {
 }
		/** Constructs a ConstantPath starting from the specified point.
		 * \param start 			From where the path will be started from (the closest node to that point will be used)
		 * \param maxGScore			Searching will be stopped when a node has a G score greater than this
		 * \param callback			Will be called when the path has completed, leave this to null if you use a Seeker to handle calls
		 *
		 * Searching will be stopped when a node has a G score (cost to reach it) greater than \a maxGScore */
		public static ConstantPath Construct (Vector3 start, int maxGScore, OnPathDelegate callback = null) {
			ConstantPath p = PathPool<ConstantPath>.GetPath ();
			p.Setup (start,maxGScore,callback);
			return p;
		}
Ejemplo n.º 40
0
 public RandomPath(Vector3 start, int length, OnPathDelegate callback = null)
 {
     throw new System.Exception("This constructor is obsolete. Please use the pooling API and the Setup methods");
 }
Ejemplo n.º 41
0
 public MultiTargetPath(Vector3[] startPoints, Vector3 target, OnPathDelegate[] callbackDelegates, OnPathDelegate callbackDelegate = null)
     : this(target,startPoints,callbackDelegates, callbackDelegate)
 {
     inverted = true;
 }
Ejemplo n.º 42
0
 /** Call this function to start calculating a path.
  *
  * \param start		The start point of the path
  * \param end		The end point of the path
  * \param callback	The function to call when the path has been calculated
  *
  * \a callback will be called when the path has completed.
  * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
 public Path StartPath(Vector3 start, Vector3 end, OnPathDelegate callback)
 {
     return(StartPath(start, end, callback, -1));
 }
Ejemplo n.º 43
0
		/** Construct a path with a start and end point.
		 * The delegate will be called when the path has been calculated.
		 * Do not confuse it with the Seeker callback as they are sent at different times.
		 * If you are using a Seeker to start the path you can set \a callback to null.
		 *
		 * \returns The constructed path object
		 */
		public static ABPath Construct (Vector3 start, Vector3 end, OnPathDelegate callback = null) {
			ABPath p = PathPool<ABPath>.GetPath ();
			p.Setup (start, end, callback);
			return p;
		}
Ejemplo n.º 44
0
 /** Call this function to start calculating a path.
  *
  * \param start		The start point of the path
  * \param end		The end point of the path
  * \param callback	The function to call when the path has been calculated
  * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.
  *
  * \a callback will be called when the path has completed.
  * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
 public Path StartPath(Vector3 start, Vector3 end, OnPathDelegate callback, int graphMask)
 {
     return(StartPath(GetNewPath(start, end), callback, graphMask));
 }
Ejemplo n.º 45
0
 /** Create a new path with a start and end point.
  * The delegate will be called when the path has been calculated. Do not confuse it with the Seeker callback as they are sent at different times.
  * If you are using a Seeker to start the path you can set \a callbackDelegate to null */
 public Path(Vector3 start, Vector3 end, OnPathDelegate callbackDelegate)
 {
     Reset(start, end, callbackDelegate, false);
 }
Ejemplo n.º 46
0
    /** Starts a Multi Target Path from multiple start points to a single target point.
     * A Multi Target Path will search from all start points to the target point in one search and will return all paths if \a pathsForAll is true, or only the shortest one if \a pathsForAll is false.\n
     *
     * \param startPoints	The start points of the path
     * \param end			The end point of the path
     * \param pathsForAll	Indicates whether or not a path from all start points should be searched for or only to the closest one
     * \param callback		The function to call when the path has been calculated
     * \param graphMask		Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.
     *
     * \a callback and #pathCallback will be called when the path has completed. \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
     * \astarpro
     * \see Pathfinding.MultiTargetPath
     * \see \ref MultiTargetPathExample.cs "Example of how to use multi-target-paths"
     */
    public MultiTargetPath StartMultiTargetPath(Vector3[] startPoints, Vector3 end, bool pathsForAll, OnPathDelegate callback = null, int graphMask = -1)
    {
        MultiTargetPath p = MultiTargetPath.Construct(startPoints, end, null, null);

        p.pathsForAll = pathsForAll;
        StartPath(p, callback, graphMask);
        return(p);
    }
Ejemplo n.º 47
0
        public virtual void Reset(Vector3 start, Vector3 end, OnPathDelegate callbackDelegate, bool reset = true)
        {
            if (reset)
            {
                processed = false;
                vectorPath = null;
                path = null;
                next = null;
                foundEnd = false;
                error = false;
                errorLog = "";
                callback = null;
                current = null;
                duration = 0;
                searchIterations = 0;
                searchedNodes = 0;

                startHint = null;
                endHint = null;
            }

            callTime = System.DateTime.Now;

            callback = callbackDelegate;

            if (AstarPath.active == null || AstarPath.active.graphs == null)
            {
                errorLog += "No NavGraphs have been calculated yet - Don't run any pathfinding calls in Awake";
                if (AstarPath.active.logPathResults != PathLog.None)
                {
                    Debug.LogWarning(errorLog);
                }
                error = true;
                return;
            }

            pathID = AstarPath.active.GetNextPathID();

            UpdateStartEnd(start, end);

            heuristic = AstarPath.active.heuristic;
            heuristicScale = AstarPath.active.heuristicScale;
        }
Ejemplo n.º 48
0
 public MultiTargetPath StartMultiTargetPath(MultiTargetPath p, OnPathDelegate callback = null, int graphMask = -1)
 {
     StartPath(p, callback, graphMask);
     return(p);
 }
Ejemplo n.º 49
0
 public XPath(Vector3 start, Vector3 end, OnPathDelegate callbackDelegate)
 {
     Setup (start, end, callbackDelegate);
 }
Ejemplo n.º 50
0
 public FloodPath(Vector3 start, OnPathDelegate callbackDelegate)
 {
     Setup(start, callbackDelegate);
     heuristic = Heuristic.None;
 }
Ejemplo n.º 51
0
	/** Call this function to start calculating a path.
	 * \param p			The path to start calculating
	 * \param callback	The function to call when the path has been calculated
	 * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. \astarproParam
	 * 
	 * \a callback will be called when the path has completed.
	 * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
	public Path StartPath (Path p, OnPathDelegate callback = null, int graphMask = -1) {
		p.enabledTags = traversableTags.tagsChange;
		p.tagPenalties = tagPenalties;
		
		//Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
		if (path != null && path.GetState() <= PathState.Processing && lastPathID == path.pathID) {
			path.LogError ("Canceled path because a new one was requested\nGameObject: "+gameObject.name);
			//No callback should be sent for the canceled path
		}
		
		path = p;
		path.callback += onPathDelegate;
		
		tmpPathCallback = callback;
		
		//Set the Get Nearest Node hints if they have not already been set
		/*if (path.startHint == null)
			path.startHint = startHint;
			
		if (path.endHint == null) 
			path.endHint = endHint;
		*/
		
		//Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
		lastPathID = path.pathID;
		
		//Delay the path call by one frame if it was sent the same frame as the previous call
		/*if (lastPathCall == Time.frameCount) {
			StartCoroutine (DelayPathStart (path));
			return path;
		}*/
		
		//lastPathCall = Time.frameCount;
		
		//Pre process the path
		RunModifiers (ModifierPass.PreProcess, path);
		
		//Send the request to the pathfinder
		AstarPath.StartPath (path);
		
		return path;
	}
Ejemplo n.º 52
0
 public Seeker()
 {
     onPathDelegate = OnPathComplete;
 }
Ejemplo n.º 53
0
	/** Initializes a few variables
	 */
	public void Awake () {
		onPathDelegate = OnPathComplete;
		onPartialPathDelegate = OnPartialPathComplete;
		
		startEndModifier.Awake (this);
	}
Ejemplo n.º 54
0
 /// <summary>
 /// Call this function to start calculating a path.
 ///
 /// callback will be called when the path has completed.
 /// Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
 /// </summary>
 /// <param name="start">The start point of the path</param>
 /// <param name="end">The end point of the path</param>
 /// <param name="callback">The function to call when the path has been calculated</param>
 /// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.NNConstraint.graphMask. This will override #graphMask for this path request.</param>
 public Path StartPath(Vector3 start, Vector3 end, OnPathDelegate callback, GraphMask graphMask)
 {
     return(StartPath(ABPath.Construct(start, end, null), callback, graphMask));
 }
Ejemplo n.º 55
0
	/** Call this function to start calculating a path.
	 * \param start		The start point of the path
	 * \param end		The end point of the path
	 * \param callback	The function to call when the path has been calculated
	 * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.
	 * 
	 * \a callback will be called when the path has completed.
	 * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
	public Path StartPath (Vector3 start, Vector3 end, OnPathDelegate callback, int graphMask) {
		Path p = GetNewPath (start,end);
		return StartPath (p, callback, graphMask);
	}
Ejemplo n.º 56
0
 /// <summary>
 /// Call this function to start calculating a path.
 ///
 /// The callback will be called when the path has been calculated (which may be several frames into the future).
 /// The callback will not be called if a new path request is started before this path request has been calculated.
 ///
 /// Version: Since 3.8.3 this method works properly if a MultiTargetPath is used.
 /// It now behaves identically to the StartMultiTargetPath(MultiTargetPath) method.
 /// </summary>
 /// <param name="p">The path to start calculating</param>
 /// <param name="callback">The function to call when the path has been calculated</param>
 /// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.GraphMask. This will override #graphMask for this path request.</param>
 public Path StartPath(Path p, OnPathDelegate callback, GraphMask graphMask)
 {
     p.nnConstraint.graphMask = graphMask;
     StartPathInternal(p, callback);
     return(p);
 }
Ejemplo n.º 57
0
	/** Starts a Multi Target Path from multiple start points to a single target point. A Multi Target Path will search from all start points to the target point in one search and will return all paths if \a pathsForAll is true, or only the shortest one if \a pathsForAll is false.\n
	 * \param startPoints	The start points of the path
	 * \param end			The end point of the path
	 * \param pathsForAll	Indicates whether or not a path from all start points should be searched for or only to the closest one
	 * \param callback		The function to call when the path has been calculated
	 * \param graphMask		Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. \astarproParam
	 * 
	 * \a callback and #pathCallback will be called when the path has completed. \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
	 * \astarpro 
	 * \see Pathfinding.MultiTargetPath
	 * \see \ref MultiTargetPathExample.cs "Example of how to use multi-target-paths"
	 */
	public MultiTargetPath StartMultiTargetPath (Vector3[] startPoints, Vector3 end, bool pathsForAll, OnPathDelegate callback = null, int graphMask = -1) {
		MultiTargetPath p = MultiTargetPath.Construct (startPoints, end, null, null);
		p.pathsForAll = pathsForAll;
		return StartMultiTargetPath (p, callback, graphMask);
	}
Ejemplo n.º 58
0
 public ConstantPath(Vector3 start, OnPathDelegate callbackDelegate)
 {
     throw new Exception("This constructor is obsolete, please use the Construct method instead");
 }
Ejemplo n.º 59
0
 public static FloodPathTracer Construct(Vector3 start, FloodPath flood, OnPathDelegate callback = null)
 {
     FloodPathTracer path = PathPool<FloodPathTracer>.GetPath();
     path.Setup(start, flood, callback);
     return path;
 }
Ejemplo n.º 60
0
 public MultiTargetPath(Vector3 start, Vector3[] targets, OnPathDelegate[] callbackDelegates, OnPathDelegate callbackDelegate = null)
 {
 }