Example #1
0
        public int CopyResult(ref FixedArrayFromEntity <PathPoint> paths, ref ComponentDataFromEntity <PathRequestData> pathRequests)
        {
            var s     = state[0];
            var count = 0;

            for (int i = 0; i < s.entitySize; ++i)
            {
                var entity  = entities[i];
                var request = requests[i];
                if (!pathRequests.Exists(entity)) //Entity 已被删除, 丢弃结果
                {
                    continue;
                }
                var originRequest = pathRequests[entity];
                if (request.status >= PathRequestStatus.Done)
                {
                    count++;
                }
                if (originRequest.status > PathRequestStatus.InProgress) //放弃寻路, 丢弃结果
                {
                    continue;
                }
                if (math.distance(originRequest.start, request.start) > 0.001f || math.distance(originRequest.end, request.end) > 0.001f)
                {
                    continue; //新的请求, 丢弃结果
                }

                pathRequests[entity] = request;
                if (request.status == PathRequestStatus.Done)
                {
                    var offset   = pathStart[i];
                    var pathSize = request.pathSize;
                    var path     = paths[entity];
                    for (var j = 0; j < pathSize; ++j)
                    {
                        path[j] = pathBuffer[offset + j];
                    }
                }
            }
            return(count);
        }