You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

88 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameAssets
{
private readonly UniQuake uq;
private readonly Dictionary<uint, Texture2D> textures = new Dictionary<uint, Texture2D>();
private BrushModel worldModel;
private readonly List<BrushModel> brushModels = new List<BrushModel>();
private readonly List<AliasModel> aliasModels = new List<AliasModel>();
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(); // TODO: reactivate when done testing in editor
}
brushModels.Clear();
foreach (var aliasModel in aliasModels)
{
// aliasModel.Dispose(); // TODO: reactivate when done testing in editor
}
aliasModels.Clear();
foreach (var texture in textures.Values)
{
// Object.Destroy(texture); // TODO: reactivate when done testing in editor
}
textures.Clear();
}
}