From 5238767ca7a05fbe5bfdc7e73a2d7da7054d2fc8 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 6 Sep 2018 15:34:31 +0900 Subject: [PATCH] Added BlendShapeAvatar.Restore --- Scripts/BlendShape/BlendShapeAvatar.cs | 29 +++++++++++++++++++++++++- Scripts/BlendShape/BlendShapeKey.cs | 12 ++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Scripts/BlendShape/BlendShapeAvatar.cs b/Scripts/BlendShape/BlendShapeAvatar.cs index e39cefab2..fe1779552 100644 --- a/Scripts/BlendShape/BlendShapeAvatar.cs +++ b/Scripts/BlendShape/BlendShapeAvatar.cs @@ -2,7 +2,7 @@ using System.Linq; using System; using System.Collections.Generic; - +using UniGLTF; namespace VRM { @@ -12,6 +12,33 @@ namespace VRM [SerializeField] public List Clips = new List(); +#if UNITY_EDITOR + [ContextMenu("Restore")] + void Restore() + { + var assetPath = UnityPath.FromAsset(this); + if (assetPath.IsNull) + { + return; + } + + + foreach(var x in assetPath.Parent.ChildFiles) + { + var clip = UnityEditor.AssetDatabase.LoadAssetAtPath(x.Value); + if (clip == null) continue; + + if (!Clips.Contains(clip)) + { + Clips.Add(clip); + } + + Debug.LogFormat("{0}", clip.name); + } + Clips = Clips.OrderBy(x => BlendShapeKey.CreateFrom(x)).ToList(); + } +#endif + /// /// Unknown以外で存在しないものを全て作る /// diff --git a/Scripts/BlendShape/BlendShapeKey.cs b/Scripts/BlendShape/BlendShapeKey.cs index 0fda3b811..3b3bc5228 100644 --- a/Scripts/BlendShape/BlendShapeKey.cs +++ b/Scripts/BlendShape/BlendShapeKey.cs @@ -4,7 +4,7 @@ namespace VRM { [Serializable] - public struct BlendShapeKey : IEquatable + public struct BlendShapeKey : IEquatable, IComparable { public string Name; public BlendShapePreset Preset; @@ -91,5 +91,15 @@ namespace VRM { return this.Equals(CreateFrom(clip)); } + + public int CompareTo(BlendShapeKey other) + { + if (Preset != other.Preset) + { + return Preset - other.Preset; + } + + return 0; + } } }