From 4a3f4c354838edd18f610faca8276cd8b72cd95b Mon Sep 17 00:00:00 2001 From: hiroj Date: Fri, 29 May 2020 15:33:25 +0900 Subject: [PATCH] EnumUtil to CacheEnum --- .../Scripts/BlendShape/BlendShapeAvatar.cs | 18 +++++++++++++++--- .../Scripts/FirstPerson/VRMFirstPerson.cs | 2 +- .../Scripts/Format/VRMImporterContext.cs | 4 ++-- .../Scripts/Format/glTF_VRM_FirstPerson.cs | 2 +- .../UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs | 6 +++--- .../VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs | 6 +++--- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs b/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs index 60df90e52..62b164b5c 100644 --- a/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs +++ b/Assets/VRM/UniVRM/Scripts/BlendShape/BlendShapeAvatar.cs @@ -79,17 +79,29 @@ namespace VRM /// public void CreateDefaultPreset() { - foreach (var preset in ((BlendShapePreset[])Enum.GetValues(typeof(BlendShapePreset))) - .Where(x => x != BlendShapePreset.Unknown)) + var presets = CacheEnum.GetValues(); + + foreach (var preset in presets) { + if (preset == BlendShapePreset.Unknown) continue; CreateDefaultPreset(preset); } } void CreateDefaultPreset(BlendShapePreset preset) { - var clip = GetClip(preset); + BlendShapeClip clip = null; + + foreach (var c in Clips) + { + if (c.Preset == preset) + { + clip = c; + break; + } + } if (clip != null) return; + clip = ScriptableObject.CreateInstance(); clip.name = preset.ToString(); clip.BlendShapeName = preset.ToString(); diff --git a/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs b/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs index 5e9b1d076..c5bf7ac2e 100644 --- a/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs +++ b/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs @@ -128,7 +128,7 @@ namespace VRM { if (x.mesh == index) { - return EnumUtil.TryParseOrDefault(x.firstPersonFlag); + return CacheEnum.TryParseOrDefault(x.firstPersonFlag, true); } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs index a4d092286..a13629540 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs @@ -158,12 +158,12 @@ namespace VRM if (group != null) { asset.BlendShapeName = groupName; - asset.Preset = EnumUtil.TryParseOrDefault(group.presetName); + asset.Preset = CacheEnum.TryParseOrDefault(group.presetName, true); asset.IsBinary = group.isBinary; if (asset.Preset == BlendShapePreset.Unknown) { // fallback - asset.Preset = EnumUtil.TryParseOrDefault(group.name); + asset.Preset = CacheEnum.TryParseOrDefault(group.name, true); } asset.Values = group.binds.Select(x => { diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs index 57bcf85a0..d376478fa 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_FirstPerson.cs @@ -87,7 +87,7 @@ namespace VRM { get { - return EnumUtil.TryParseOrDefault(lookAtTypeName); + return CacheEnum.TryParseOrDefault(lookAtTypeName, true); } set { lookAtTypeName = value.ToString(); } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs index 5061ff7e2..6065a38da 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Humanoid.cs @@ -73,7 +73,7 @@ namespace VRM { public static VRMBone FromHumanBodyBone(this HumanBodyBones human) { - return EnumUtil.TryParseOrDefault(human.ToString(), VRMBone.unknown); + return human.ToVrmBone(); } public static HumanBodyBones ToHumanBodyBone(this VRMBone bone) @@ -85,7 +85,7 @@ namespace VRM return HumanBodyBones.LastBone; } #endif - return EnumUtil.TryParseOrDefault(bone.ToString(), HumanBodyBones.LastBone); + return bone.ToUnityBone(); } } @@ -161,7 +161,7 @@ namespace VRM } get { - return EnumUtil.TryParseOrDefault(bone); + return CacheEnum.Parse(bone, true); } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs index c88c22dc0..7610142ff 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs @@ -36,7 +36,7 @@ namespace VRM { static UssageLicense FromString(string src) { - return EnumUtil.TryParseOrDefault(src); + return CacheEnum.TryParseOrDefault(src, true); } [JsonSchema(Description = "Title of VRM model")] @@ -69,7 +69,7 @@ namespace VRM { get { - return EnumUtil.TryParseOrDefault(allowedUserName); + return CacheEnum.TryParseOrDefault(allowedUserName, true); } set { @@ -135,7 +135,7 @@ namespace VRM { get { - return EnumUtil.TryParseOrDefault(licenseName); + return CacheEnum.TryParseOrDefault(licenseName, true); } set {