Skip to content

Commit

Permalink
IReadOnlyList
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Jun 16, 2021
1 parent 07ce8f2 commit 73763f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ public class RuntimeGltfInstance : MonoBehaviour, IResponsibilityForDestroyObjec
/// </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;
}
Expand All @@ -47,18 +49,18 @@ public void EnableUpdateWhenOffscreen()
void OnDestroy()
{
Debug.Log("UnityResourceDestroyer.OnDestroy");
foreach (var (key, x) in Resources)
foreach (var (key, x) in m_resources)
{
UnityObjectDestoyer.DestroyRuntimeOrEditor(x);
}
}

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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void TextureExtractTest()
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)
Expand Down

0 comments on commit 73763f7

Please sign in to comment.