using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameAssets { private readonly UniQuake uq; private readonly Dictionary textures = new Dictionary(); private BrushModel worldModel; private readonly List brushModels = new List(); private readonly List aliasModels = new List(); private uint nextTexNum = 0x10001; public GameAssets(UniQuake uniQuake) { uq = uniQuake; } public uint SetTexture(uint texNum, Texture2D texture) { if (texNum == 0) { // Assign a new texture number while (textures.ContainsKey(nextTexNum)) ++nextTexNum; texNum = nextTexNum++; } textures[texNum] = texture; return texNum; } public bool TryGetTexture(uint texNum, out Texture2D texture) { texture = null; return texNum > 0 && textures.TryGetValue(texNum, out texture); } public void AddAliasModel(AliasModel aliasModel) { aliasModels.Add(aliasModel); } public void AddBrushModel(BrushModel brushModel) { brushModels.Add(brushModel); } public void SetWorldModel(BrushModel brushModel) { worldModel?.Dispose(); // TODO: also need to clean up any GameObjects made from this worldModel = brushModel; } public void Destroy() { if (worldModel != null) { worldModel.Dispose(); worldModel = null; } foreach (var brushModel in brushModels) { brushModel.Dispose(); } brushModels.Clear(); foreach (var aliasModel in aliasModels) { aliasModel.Dispose(); } aliasModels.Clear(); foreach (var texture in textures.Values) { Object.Destroy(texture); } textures.Clear(); } }