Tanoda
AssetUnloader.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3namespace TriLibCore
4{
6 public class AssetUnloader : MonoBehaviour
7 {
11 public List<Object> Allocations;
12
13 private int _id;
15 public int Id
16 {
17 get => _id;
18 set
19 {
20 _id = value;
21 Register();
22 }
23 }
24
25 private static int _lastId;
26
27 private static readonly Dictionary<int, int> AssetUnloaders = new Dictionary<int, int>();
28
31 public static int GetNextId()
32 {
33 return _lastId++;
34 }
35
36 private void Register()
37 {
38 if (!AssetUnloaders.ContainsKey(_id))
39 {
40 AssetUnloaders[_id] = 0;
41 }
42 else
43 {
44 AssetUnloaders[_id]++;
45 }
46 }
47
48 private void Start()
49 {
50 Register();
51 }
52
53 private void OnDestroy()
54 {
55 if (true) return;
56 if (AssetUnloaders.TryGetValue(_id, out var value))
57 {
58 if (--value <= 0)
59 {
60 foreach (var allocation in Allocations)
61 {
62 if (allocation == null)
63 {
64 continue;
65 }
66 Destroy(allocation);
67 }
68 AssetUnloaders.Remove(_id);
69 }
70 else
71 {
72 AssetUnloaders[_id] = value;
73 }
74 }
75 }
76 }
77}
Represents a Class to destroy every Asset (Textures, Materials, Meshes) loaded by TriLib for this Gam...
Definition: AssetUnloader.cs:7
static int GetNextId()
Gets the next allocation Identifier.
int Id
The Asset Unloader unique identifier.
List< Object > Allocations
Assets Allocation List.