IReadOnlyList

This commit is contained in:
ousttrue
2021-06-16 18:55:10 +09:00
parent 07ce8f2112
commit 73763f713b
2 changed files with 8 additions and 6 deletions

View File

@@ -16,14 +16,16 @@ namespace UniGLTF
/// </summary>
public GameObject Root => this.gameObject;
public List<(SubAssetKey, UnityEngine.Object)> Resources = new List<(SubAssetKey, UnityEngine.Object)>();
List<(SubAssetKey, UnityEngine.Object)> m_resources = new List<(SubAssetKey, UnityEngine.Object)>();
public IReadOnlyList<(SubAssetKey, UnityEngine.Object)> OwnedResources => m_resources;
public static RuntimeGltfInstance AttachTo(GameObject go, ImporterContext context)
{
var loaded = go.AddComponent<RuntimeGltfInstance>();
context.TransferOwnership((k, o) =>
{
loaded.Resources.Add((k, o));
loaded.m_resources.Add((k, o));
});
return loaded;
}
@@ -47,7 +49,7 @@ namespace UniGLTF
void OnDestroy()
{
Debug.Log("UnityResourceDestroyer.OnDestroy");
foreach (var (key, x) in Resources)
foreach (var (key, x) in m_resources)
{
UnityObjectDestoyer.DestroyRuntimeOrEditor(x);
}
@@ -55,10 +57,10 @@ namespace UniGLTF
public void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take)
{
foreach (var (key, x) in Resources.ToArray())
foreach (var (key, x) in m_resources.ToArray())
{
take(key, x);
Resources.Remove((key, x));
m_resources.Remove((key, x));
}
}

View File

@@ -94,7 +94,7 @@ namespace UniGLTF
using (var context = new ImporterContext(parser))
{
var instance = context.Load();
var textureMap = instance.Resources
var textureMap = instance.RuntimeResources
.Select(kv => (kv.Item1, kv.Item2 as Texture))
.Where(kv => kv.Item2 != null)
.ToDictionary(kv => kv.Item1, kv => kv.Item2)