mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-12 05:48:47 -05:00
fix for ImporterContext.Load
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user