using System; using System.Collections.Generic; using UnityEngine; namespace UnityGLTF.Cache { /// /// Caches data in order to construct a unity object /// public class AssetCache : IDisposable { /// /// Raw loaded images /// public Texture2D[] ImageCache { get; private set; } /// /// Textures to be used for assets. Textures from image cache with samplers applied /// public Texture[] TextureCache { get; private set; } /// /// Cache for materials to be applied to the meshes /// public MaterialCacheData[] MaterialCache { get; private set; } /// /// Byte buffers that represent the binary contents that get parsed /// public Dictionary BufferCache { get; private set; } /// /// Cache of loaded meshes /// public List MeshCache { get; private set; } /// /// Creates an asset cache which caches objects used in scene /// /// /// /// /// /// public AssetCache(int imageCacheSize, int textureCacheSize, int materialCacheSize, int bufferCacheSize, int meshCacheSize) { // todo: add optimization to set size to be the JSON size ImageCache = new Texture2D[imageCacheSize]; TextureCache = new Texture[textureCacheSize]; MaterialCache = new MaterialCacheData[materialCacheSize]; BufferCache = new Dictionary(bufferCacheSize); MeshCache = new List(meshCacheSize); for(int i = 0; i < meshCacheSize; ++i) { MeshCache.Add(null); } } public void Dispose() { ImageCache = null; TextureCache = null; MaterialCache = null; BufferCache.Clear(); MeshCache = null; } } }