Пример #1
0
        private static int LoadNonSharedMeshSources(SurfaceController controller)
        {
            int surfaceId = controller.Config.SurfaceId;

            if (!NavMeshStoreSystem.Instance.Exists <MeshSourceInfo>(surfaceId, NonShared))
            {
                return(0);
            }

            NativeArray <BlobAssetReference <MeshSourceData> > datas = NavMeshStoreSystem.Instance.LoadSources(surfaceId);
            int infosLength = NavMeshStoreSystem.Instance.GetArrayLength <MeshSourceInfo>(surfaceId, NonShared);
            NativeArray <MeshSourceInfo> infos = new NativeArray <MeshSourceInfo>(infosLength, Allocator.Temp);

            NavMeshStoreSystem.Instance.LoadArray(infos, surfaceId, NonShared);

            for (int i = 0; i < infos.Length; i++)
            {
                MeshSource source = new MeshSource {
                    Info = infos[i], Value = datas[i]
                };
                controller.AddMeshSource(ref source);
            }
            infos.Dispose();
            datas.Dispose();
            return(infosLength);
        }
Пример #2
0
        public void AddToSurface()
        {
            var controller = SurfaceController.Current(SurfaceId);

            if (controller != null)
            {
                Current = GetMeshSource();
                controller.AddMeshSource(ref Current);
                controller.MarkDirty(Current.Info.Bounds);
            }
        }
Пример #3
0
 public bool TryGetByCustomData(int customData, out MeshSource source)
 {
     source = default;
     if (CustomIdToIdIndex.TryGetValue(customData, out int id))
     {
         if (IdIndex.TryGetValue(id, out source))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
        public static MeshSource Create(float4x4 localToWorld, Mesh mesh, int layer, byte area, byte flag, int customData = 0)
        {
            MeshSource     source = new MeshSource();
            MeshSourceInfo info   = new MeshSourceInfo {
                Layer = layer, Area = area, Flag = flag, CustomData = customData
            };

            source.Value = MeshSourceData.Create(mesh, localToWorld);
            info.Bounds  = MeshSourceData.CalculateBounds(source.Value);

            source.Info = info;

            return(source);
        }
Пример #5
0
        // Assigns unique id.  So if you add/remove multiple times make sure to use the same copy.
        public void AddMeshSource(ref MeshSource source)
        {
            if (Building)
            {
                throw new InvalidOperationException("Building");
            }

            if (source.Id == 0)
            {
                source.Id = NextMeshSourceId;
                NextMeshSourceId++;
            }

            MeshSourceMap.Add(source);
        }
Пример #6
0
        public void RemoveFromSurface()
        {
            if (Current.Id <= 0)
            {
                return;
            }
            var controller = SurfaceController.Current(SurfaceId);

            if (controller != null)
            {
                if (controller.RemoveMeshSource(Current.Id))
                {
                    controller.MarkDirty(Current.Info.Bounds);
                    Current = default;
                }
            }
        }
Пример #7
0
        public void Add(MeshSource source)
        {
            if (IdIndex.TryGetValue(source.Id, out MeshSource existing))
            {
                existing.Dispose();
                IdIndex.Remove(source.Id);
                CustomIdToIdIndex.Remove(source.Info.CustomData);
            }

            IdIndex.TryAdd(source.Id, source);
            CustomIdToIdIndex.TryAdd(source.Info.CustomData, source.Id);

            NativeList <int2> tileCoords = NativeBuildUtitls.GetOverlappingTiles(BuildSettings, source.Info.Bounds);

            for (int i = 0; i < tileCoords.Length; i++)
            {
                int2 coord = tileCoords[i];
                TileSources.Add(coord, source.Id);
            }
            tileCoords.Dispose();
        }
Пример #8
0
        public MeshSource GetMeshSource()
        {
            float4x4 localToWorld = float4x4.TRS(transform.position, transform.rotation, transform.localScale);

            if (Shared)
            {
                int sharedId  = SharedMeshId;
                var navSystem = EcsWorld.Active.GetExistingSystem <AiNavSystem>();
                if (navSystem.TryGetSharedBlobRef(sharedId, out BlobAssetReference <MeshSourceData> data))
                {
                    return(MeshSource.CreateShared(localToWorld, data, Layer, Area, Flag, sharedId));
                }
                else
                {
                    throw new InvalidOperationException(string.Format("shared mesh not found {0}", sharedId));
                }
            }
            else
            {
                return(MeshSource.Create(localToWorld, MeshFilter.sharedMesh, Layer, Area, Flag));
            }
        }
Пример #9
0
            public void Execute()
            {
                NativeList <MeshSource> sources = MeshSourceMap.GetSources(TileBounds.Coord);

                for (int i = 0; i < sources.Length; i++)
                {
                    MeshSource source = sources[i];

                    if (!IncludeMask.HasLayer(source.Info.Layer))
                    {
                        continue;
                    }

                    NativeArray <int>    indices;
                    NativeArray <float3> vertices;

                    if (source.Info.Shared)
                    {
                        if (!SharedMeshSources.TryGetValue(source.Info.SharedMeshId, out BlobAssetReference <MeshSourceData> data))
                        {
                            continue;
                        }

                        MeshSourceData.GetData(data, out indices, out vertices);
                        MeshSourceData.TransformInPlace(source.Info.TRS, vertices);
                        InputBuilder.Append(vertices, indices, source.Info.Area);
                    }
                    else
                    {
                        MeshSourceData.GetData(source.Value, out indices, out vertices);
                        InputBuilder.Append(vertices, indices, source.Info.Area);
                    }

                    vertices.Dispose();
                    indices.Dispose();
                }
            }
Пример #10
0
 public bool TryGetMeshSourceByCustomData(int customData, out MeshSource source)
 {
     return(MeshSourceMap.TryGetByCustomData(customData, out source));
 }