Example #1
0
        private void CleanupMeshes()
        {
            using (var missing = new NativeHashMap <int, bool>(_meshById.Count, Allocator.Temp))
                using (var chunks = _spriteWithMesh.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    foreach (var meshId in _meshById.Keys)
                    {
                        missing.TryAdd(meshId, true);
                    }

                    var chunkSpriteMeshType = GetArchetypeChunkComponentType <ChunkSpriteMeshComponent>(true);
                    for (int i = 0; i < chunks.Length; i++)
                    {
                        var mesh = chunks[i].GetChunkComponentData(chunkSpriteMeshType);
                        missing.Remove(mesh.ChunkMeshId);
                    }

                    using (var keys = missing.GetKeyArray(Allocator.Temp))
                    {
                        for (int i = 0; i < keys.Length; i++)
                        {
                            if (_meshById.TryGetValue(keys[i], out var mesh))
                            {
                                UnityEngine.Object.Destroy(mesh.Mesh);
                            }
                            int renderIndex = _meshIds.IndexOf(keys[i]);
                            _renderGroup.RemoveBatch(renderIndex);
                            _meshIds.RemoveAtSwapBack(renderIndex);
                            _meshById.Remove(keys[i]);
                        }
                    }
                }
        }
Example #2
0
    private void OnDestroy()
    {
        if (m_initialized)
        {
            m_BatchRendererGroup.RemoveBatch(m_batchID);
            if (m_material)
            {
                m_BatchRendererGroup.UnregisterMaterial(m_materialID);
            }
            if (m_mesh)
            {
                m_BatchRendererGroup.UnregisterMesh(m_meshID);
            }

            m_BatchRendererGroup.Dispose();
            m_GPUPersistentInstanceData.Dispose();
            m_sysmemBuffer.Dispose();
        }
    }