Beispiel #1
0
        public static void Find(this PathfindingComponent self, Vector3 start, Vector3 target, List <Vector3> result)
        {
            if (self.NavMesh == 0)
            {
                Log.Debug("寻路| Find 失败 pathfinding ptr is zero");
                throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
            }

            self.StartPos[0] = -start.x;
            self.StartPos[1] = start.y;
            self.StartPos[2] = start.z;

            self.EndPos[0] = -target.x;
            self.EndPos[1] = target.y;
            self.EndPos[2] = target.z;
            //Log.Debug($"start find path: {self.GetParent<Unit>().Id}");
            int n = Recast.RecastFind(self.NavMesh, PathfindingComponent.extents, self.StartPos, self.EndPos, self.Result);

            for (int i = 0; i < n; ++i)
            {
                int index = i * 3;
                result.Add(new Vector3(-self.Result[index], self.Result[index + 1], self.Result[index + 2]));
            }
            //Log.Debug($"finish find path: {self.GetParent<Unit>().Id} {result.ListToString()}");
        }
Beispiel #2
0
        public static Vector3 RecastFindNearestPoint(this PathfindingComponent self, Vector3 pos)
        {
            if (self.NavMesh == 0)
            {
                throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
            }

            self.StartPos[0] = -pos.x;
            self.StartPos[1] = pos.y;
            self.StartPos[2] = pos.z;

            int ret = Recast.RecastFindNearestPoint(self.NavMesh, PathfindingComponent.extents, self.StartPos, self.EndPos);

            if (ret == 0)
            {
                throw new Exception($"RecastFindNearestPoint fail, 可能是位置配置有问题: sceneName:{self.DomainScene().Name} {pos} {self.Name} {self.GetParent<Unit>().Id} {self.GetParent<Unit>().Config.Id} {self.EndPos.ArrayToString()}");
            }

            return(new Vector3(-self.EndPos[0], self.EndPos[1], self.EndPos[2]));
        }
Beispiel #3
0
        public static long Get(this NavmeshComponent self, string name)
        {
            long ptr;

            if (self.Navmeshs.TryGetValue(name, out ptr))
            {
                return(ptr);
            }

            byte[] buffer = self.Loader(name);
            if (buffer.Length == 0)
            {
                throw new Exception($"no nav data: {name}");
            }

            ptr = Recast.RecastLoadLong(name.GetHashCode(), buffer, buffer.Length);
            self.Navmeshs[name] = ptr;

            return(ptr);
        }