public void Tick() { if (ActiveCamera == null || !_batcher.IsCreated) { return; } //share component id can only be visited by architypechunks, //so we iterate over architypechunks here //https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/8f94d72d1fd9b8db896646d9d533055917dc265a/Documentation/reference/chunk_iteration.md _batcher.Clear(); UnityEngine.Profiling.Profiler.BeginSample("gather chunks"); NativeArray <ArchetypeChunk> chunks = EntityManager.CreateArchetypeChunkArray(_query, Allocator.TempJob); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("start cull"); var cullJob = new CullJob() { EntityType = GetArchetypeChunkEntityType(), Chunks = chunks, RenderTypes = GetArchetypeChunkSharedComponentType <InstanceRendererData>(), LocalToWorldType = GetArchetypeChunkComponentType <LocalToWorld>(true), Batcher = _batcher.ToConcurrent(), CamPos = ActiveCamera.transform.position, CullDistance = _cullDistance }; var deps = cullJob.Schedule(chunks.Length, 1); deps.Complete(); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("start render"); Render(); UnityEngine.Profiling.Profiler.EndSample(); }
protected override void OnUpdate() { if (ActiveCamera == null) { return; } _batcher.Clear(); NativeArray <ArchetypeChunk> chunks = EntityManager.CreateArchetypeChunkArray(_query, Allocator.TempJob); var cullJob = new CullJob() { EntityType = GetArchetypeChunkEntityType(), Chunks = chunks, RenderTypes = GetArchetypeChunkSharedComponentType <InstanceRendererData>(), LocalToWorldType = GetArchetypeChunkComponentType <LocalToWorld>(true), Batcher = _batcher.ToConcurrent(), CamPos = ActiveCamera.transform.position, CullDistance = _cullDistance }; var deps = cullJob.Schedule(chunks.Length, 32); deps.Complete(); Render(); }