From 9c937e623d711848e5cf72011b399aa4986d8470 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 17 Jun 2021 21:18:07 +0900 Subject: [PATCH] =?UTF-8?q?ImporterContext.AnimationClips=20=E3=81=AB=20Ex?= =?UTF-8?q?ternal=20=E3=81=8B=E5=90=A6=E3=81=8B=E3=81=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AnimationClips は、 gltf.animations と一対一に対応する * externalObjectMap に由来する AnimationClips は、Dipspose時にDestroy しないし、TransferOwnership の対象から外す --- .../Runtime/UniGLTF/IO/ImporterContext.cs | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 9b72a9603..55b19c84f 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -123,16 +123,16 @@ namespace UniGLTF { foreach (var (key, gltfAnimation) in Enumerable.Zip(AnimationImporterUtil.EnumerateSubAssetKeys(GLTF), GLTF.animations, (x, y) => (x, y))) { - AnimationClip clip = default; + AnimationInfo animation = default; if (_externalObjectMap.TryGetValue(key, out UnityEngine.Object value)) { - clip = value as AnimationClip; + animation = new AnimationInfo(key, value as AnimationClip, true); } else { - clip = AnimationImporterUtil.ConvertAnimationClip(GLTF, gltfAnimation, InvertAxis.Create()); - AnimationClips.Add((key, clip)); + animation = new AnimationInfo(key, AnimationImporterUtil.ConvertAnimationClip(GLTF, gltfAnimation, InvertAxis.Create()), false); } + AnimationClips.Add(animation); } await awaitCaller.NextFrame(); @@ -151,7 +151,7 @@ namespace UniGLTF var animation = Root.AddComponent(); for (int i = 0; i < AnimationClips.Count; ++i) { - var (_, clip) = AnimationClips[i]; + var clip = AnimationClips[i].Clip; animation.AddClip(clip, clip.name); if (i == 0) { @@ -281,7 +281,21 @@ namespace UniGLTF public List Meshes = new List(); - public List<(SubAssetKey, AnimationClip)> AnimationClips = new List<(SubAssetKey, AnimationClip)>(); + public struct AnimationInfo + { + public readonly SubAssetKey Key; + public readonly AnimationClip Clip; + public readonly bool IsExternal; + + public AnimationInfo(SubAssetKey key, AnimationClip clip, bool isExternal) + { + Key = key; + Clip = clip; + IsExternal = isExternal; + } + } + + public List AnimationClips = new List(); #endregion /// @@ -289,9 +303,14 @@ namespace UniGLTF /// public virtual void Dispose() { - foreach (var (k, x) in AnimationClips) + foreach (var info in AnimationClips) { - UnityObjectDestoyer.DestroyRuntimeOrEditor(x); + if (info.IsExternal) + { + // external は削除不要 + continue; + } + UnityObjectDestoyer.DestroyRuntimeOrEditor(info.Clip); } AnimationClips.Clear(); @@ -320,11 +339,17 @@ namespace UniGLTF TextureFactory.TransferOwnership(take); MaterialFactory.TransferOwnership(take); - foreach (var (key, animation) in AnimationClips.ToArray()) + foreach (var info in AnimationClips) { - take(key, animation); - AnimationClips.Remove((key, animation)); + if (info.IsExternal) + { + // external は削除しないので不要 + continue; + } + take(info.Key, info.Clip); } + + AnimationClips.Clear(); } } }