Exemple #1
0
        //从池子里面获取路径(目前都是在NavAgent里面处理的)
        public NavPaths GetPath()
        {
            if (mPaths.Count > 0)
            {
                NavPaths aPath = mPaths.Pop();
                return(aPath);
            }

            return(new NavPaths(mMaxPathSize, mMaxStraightPathSize));
        }
Exemple #2
0
        //回收这个路径(目前都是在NavAgent里面处理的)
        public void ReturnPath(NavPaths path)
        {
            if (mPaths.Count >= mMaxPaths || path == null ||
                path.path.Length != mMaxPathSize ||
                (path.straightPath != null && path.straightPath.Length != mMaxStraightPathSize)
                )
            {
                return;
            }

            //清理过去存过的内存
            path.pathCount     = 0;
            path.straightCount = 0;
            //这句话非常重要,这里不仅仅是释放内存,也是外边的一个重要的标记
            path.straightPath = null;

            mPaths.Push(path);
        }
Exemple #3
0
        public void SetPathAssets(bool enabled)
        {
            if (enabled)
            {
                if (path == null)
                {
                    path = agentGroup.GetPath();
                }

                flags |= NavFlag.PathInUse;
            }
            else
            {
                agentGroup.ReturnPath(path);

                path   = null;
                flags &= ~NavFlag.PathInUse;
            }
        }