mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-23 00:31:47 -05:00
Fix memory leaks in roads
This commit is contained in:
parent
0c2094fa53
commit
23d0931fbf
1 changed files with 16 additions and 1 deletions
|
@ -8,11 +8,14 @@ using OpenTS2.Content.DBPF;
|
||||||
using OpenTS2.Content.DBPF.Scenegraph;
|
using OpenTS2.Content.DBPF.Scenegraph;
|
||||||
using OpenTS2.Files.Formats.DBPF;
|
using OpenTS2.Files.Formats.DBPF;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using OpenTS2.Components;
|
||||||
|
using OpenTS2.Engine;
|
||||||
|
|
||||||
namespace OpenTS2.Scenes
|
namespace OpenTS2.Scenes
|
||||||
{
|
{
|
||||||
public class NeighborhoodDecorations : MonoBehaviour
|
public class NeighborhoodDecorations : AssetReferenceComponent
|
||||||
{
|
{
|
||||||
|
private List<Material> _roadMaterials = new List<Material>();
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
var decorations = NeighborhoodManager.CurrentNeighborhood.Decorations;
|
var decorations = NeighborhoodManager.CurrentNeighborhood.Decorations;
|
||||||
|
@ -43,6 +46,15 @@ namespace OpenTS2.Scenes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up the road materials we created. Textures should get garbage collected.
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
foreach(var mat in _roadMaterials)
|
||||||
|
{
|
||||||
|
mat.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RenderRoad(RoadDecoration road)
|
private void RenderRoad(RoadDecoration road)
|
||||||
{
|
{
|
||||||
var roadObject = new GameObject("road", typeof(MeshFilter), typeof(MeshRenderer))
|
var roadObject = new GameObject("road", typeof(MeshFilter), typeof(MeshRenderer))
|
||||||
|
@ -74,6 +86,9 @@ namespace OpenTS2.Scenes
|
||||||
{
|
{
|
||||||
mainTexture = texture.GetSelectedImageAsUnityTexture(ContentProvider.Get())
|
mainTexture = texture.GetSelectedImageAsUnityTexture(ContentProvider.Get())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_roadMaterials.Add(material);
|
||||||
|
AddReference(texture);
|
||||||
roadObject.GetComponent<MeshRenderer>().material = material;
|
roadObject.GetComponent<MeshRenderer>().material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue