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); }
private void OnSurfaceDestroyed(int surfaceId) { if (surfaceId != SurfaceId) { return; } Query.Dispose(); Controller = null; }
public void AddToSurface() { var controller = SurfaceController.Current(SurfaceId); if (controller != null) { Current = GetMeshSource(); controller.AddMeshSource(ref Current); controller.MarkDirty(Current.Info.Bounds); } }
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); } }
private void OnSurfaceCreated(int surfaceId) { if (surfaceId != SurfaceId) { return; } var navSystem = EcsWorld.Active.GetExistingSystem <AiNavSystem>(); Controller = navSystem.GetSurfaceController(SurfaceId); Query = new AiNavQuery(Controller.NavMesh, 2048); Debug.Assert(Query.IsValid()); }
public CrowdController(AiNavMesh navMesh, SurfaceController surfaceController) { NavMesh = navMesh; AiNavSurfaceController = surfaceController; AiCrowd = new AiCrowd(NavMesh.DtNavMesh); Query = new AiNavQuery(NavMesh, 2048); AiCrowd.Update(Time.time); UpdateClock = new GameClock(CrowdTicksPerSecond); AgentCount = new NativeArray <int>(1, Allocator.Persistent); ReadOnlyAgents = new NativeHashMap <int, NavAgentDebug>(MaxAgents, Allocator.Persistent); Path = new NativeArray <float3>(1024, Allocator.Persistent); }
private void Start() { var navSystem = EcsWorld.Active.GetExistingSystem <AiNavSystem>(); Controller = navSystem.GetSurfaceController(SurfaceId); if (Controller == null) { Destroy(gameObject); return; } var query = new AiNavQuery(Controller.NavMesh, 2048); float3 extent = new float3(5f, 5f, 5f); float3 position = transform.position; if (!query.GetRandomPosition(ref position)) { query.Dispose(); Debug.Log("Spawn position not found"); Destroy(gameObject); return; } query.Dispose(); DtAgentParams agentParams = DtAgentParams.Default; agentParams.MaxSpeed = 6f; if (Controller.CrowdController.TryAddAgent(position, agentParams, out NavAgent agent)) { var world = EcsWorld.Active; Entity entity = world.EntityManager.CreateEntity(); world.EntityManager.AddComponentData(entity, agent); world.EntityManager.AddComponentData(entity, new AgentPathData()); world.EntityManager.AddBuffer <AgentPathBuffer>(entity); transform.position = position; CrowdIndex = agent.CrowdIndex; } else { Debug.Log("Failed adding agent"); Destroy(gameObject); return; } }
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; } } }
private static int LoadFilters(SurfaceController controller) { int surfaceId = controller.Config.SurfaceId; if (!NavMeshStoreSystem.Instance.Exists <BoxFilter>(surfaceId)) { return(0); } int boxFiltersLength = NavMeshStoreSystem.Instance.GetArrayLength <BoxFilter>(surfaceId); NativeArray <BoxFilter> boxFilters = new NativeArray <BoxFilter>(boxFiltersLength, Allocator.Temp); NavMeshStoreSystem.Instance.LoadArray(boxFilters, surfaceId); for (int i = 0; i < boxFilters.Length; i++) { controller.AddBoxFilter(boxFilters[i]); } boxFilters.Dispose(); return(boxFiltersLength); }
public static void Load(SurfaceController controller) { int nonShared = LoadNonSharedMeshSources(controller); int shared = LoadSharedMeshSources(controller); int filters = LoadFilters(controller); }