Exemple #1
0
        public bool EnsureSurfaceAdded()
        {
            var navSystem = NavSystem;

            if (navSystem == null)
            {
                return(false);
            }

            if (!navSystem.HasSurface(SurfaceId))
            {
                SurfaceControllerConfig config = new SurfaceControllerConfig
                {
                    SurfaceId      = SurfaceId,
                    BuildSettings  = BuildSettings,
                    AgentSettings  = AgentSettings,
                    BatchSize      = BatchSize,
                    CrowdEnabled   = CrowdEnabled,
                    GeometryFilter = GeometryFilter,
                    IncludeMask    = UnityPhysicsHelper.LayerMaskToFilter(IncludeMask),
                    IncludeUnityPhysicsGeometry = IncludeUnityPhysicsGeometry
                };
                navSystem.SetSurface(config);
            }
            return(true);
        }
Exemple #2
0
        public void SetSurface(SurfaceControllerConfig config)
        {
            RemoveSurface(config.SurfaceId);

            if (!Surfaces.TryGetValue(config.SurfaceId, out SurfaceController surfaceManager))
            {
                surfaceManager             = new SurfaceController(config, this);
                Surfaces[config.SurfaceId] = surfaceManager;

                OnSurfaceCreated?.Invoke(config.SurfaceId);
            }
        }
Exemple #3
0
        public SurfaceController(SurfaceControllerConfig config, AiNavSystem system)
        {
            Config      = config;
            AiNavSystem = system;

            Builder = new NavMeshBuilder(Config.BuildSettings, Config.AgentSettings);

            Colliders         = new NativeList <PhysicsCollider>(Allocator.Persistent);
            TilesToBuild      = new NativeQueue <NavMeshTileBounds>(Allocator.Persistent);
            BuildInputs       = new NativeQueue <NavMeshBuildInput>(Allocator.Persistent);
            CurrentTileStatus = new NativeArray <int>(1, Allocator.Persistent);
            BoxFilters        = new NativeList <BoxFilter>(Allocator.Persistent);
            MeshSourceMap     = new MeshSourceMap(Builder.BuildSettings);
            TilesSavedStatus  = new NativeArray <int>(1, Allocator.Persistent);

            TilesHandle = GCHandle.Alloc(Tiles);
            TilesPtr    = GCHandle.ToIntPtr(TilesHandle);

            RebuiltTilesHandle = GCHandle.Alloc(RebuiltTiles);
            RebuiltTilesPtr    = GCHandle.ToIntPtr(RebuiltTilesHandle);

            NavMesh = new AiNavMesh(Builder.BuildSettings.TileSize, Builder.BuildSettings.CellSize);

            bool loaded = NavMeshStoreSystem.Instance.LoadTiles(Config.SurfaceId, Tiles);

            foreach (NavMeshTile tile in Tiles.Values)
            {
                NavMesh.AddOrReplaceTile(tile.Data);
            }

            if (Config.CrowdEnabled)
            {
                CrowdController = new CrowdController(NavMesh, this);
            }

            HandlesToWaitFor = new NativeList <JobHandle>(Allocator.Persistent);

            SurfaceData.Load(this);
        }