fix for ImporterContext.Load

This commit is contained in:
ousttrue
2021-06-16 18:41:12 +09:00
parent 3181dd6c90
commit 07ce8f2112
2 changed files with 19 additions and 12 deletions

View File

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

View File

@@ -91,15 +91,22 @@ namespace UniGLTF
parser.ParsePath(path.FullName);
// load
var context = new ImporterContext(parser);
context.Load();
using (var context = new ImporterContext(parser))
{
var instance = context.Load();
var textureMap = instance.Resources
.Select(kv => (kv.Item1, kv.Item2 as Texture))
.Where(kv => kv.Item2 != null)
.ToDictionary(kv => kv.Item1, kv => kv.Item2)
;
// extractor
var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), context.TextureFactory.ConvertedTextures);
var m = context.TextureDescriptorGenerator.Get().GetEnumerable()
.FirstOrDefault(x => x.SubAssetKey.Name == "texture_1.standard");
// extractor
var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), textureMap);
var m = context.TextureDescriptorGenerator.Get().GetEnumerable()
.FirstOrDefault(x => x.SubAssetKey.Name == "texture_1.standard");
Assert.Catch<NotImplementedException>(() => extractor.Extract(m.SubAssetKey, m));
Assert.Catch<NotImplementedException>(() => extractor.Extract(m.SubAssetKey, m));
}
}
}
}