From 894ba1ececb410d01375a5c4ab724e8066b874ee Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Wed, 7 Sep 2022 15:42:41 +0900 Subject: [PATCH] Use CachedEnum instead of EnumUtil --- Assets/VRM10/Runtime/IO/Vrm10ImportData.cs | 4 +- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 2 +- Assets/VRM10/vrmlib/Runtime/EnumUtil.cs | 59 -------------------- Assets/VRM10/vrmlib/Runtime/EnumUtil.cs.meta | 11 ---- 4 files changed, 3 insertions(+), 73 deletions(-) delete mode 100644 Assets/VRM10/vrmlib/Runtime/EnumUtil.cs delete mode 100644 Assets/VRM10/vrmlib/Runtime/EnumUtil.cs.meta diff --git a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs index c829ffadc..37c5bd1f6 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs @@ -202,7 +202,7 @@ namespace UniVRM10 } var accessor = Gltf.accessors[accessorIndex]; var bytes = GetAccessorBytes(accessorIndex); - var vectorType = EnumUtil.Parse(accessor.type); + var vectorType = CachedEnum.Parse(accessor.type, ignoreCase: true); ba = new BufferAccessor(m_data.NativeArrayManager, bytes, (AccessorValueType)accessor.componentType, vectorType, accessor.count); return true; @@ -278,7 +278,7 @@ namespace UniVRM10 var bytes = bin.GetSubArray(start, totalCount * firstAccessor.GetStride()); return new BufferAccessor(m_data.NativeArrayManager, bytes, (AccessorValueType)firstAccessor.componentType, - EnumUtil.Parse(firstAccessor.type), + CachedEnum.Parse(firstAccessor.type, ignoreCase: true), totalCount); } else diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 265b3c2ff..bb70f4f2f 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -721,7 +721,7 @@ namespace UniVRM10 case VrmLib.HumanoidBones.rightThumbMetacarpal: return HumanBodyBones.RightThumbProximal; case VrmLib.HumanoidBones.rightThumbProximal: return HumanBodyBones.RightThumbIntermediate; } - return VrmLib.EnumUtil.Cast(bone); + return CachedEnum.Parse(bone.ToString(), ignoreCase: true); } /// diff --git a/Assets/VRM10/vrmlib/Runtime/EnumUtil.cs b/Assets/VRM10/vrmlib/Runtime/EnumUtil.cs deleted file mode 100644 index 46447797e..000000000 --- a/Assets/VRM10/vrmlib/Runtime/EnumUtil.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace VrmLib -{ - public static class EnumUtil - { - public static T Parse(string src, bool ignoreCase = true) where T : struct - { - if (string.IsNullOrEmpty(src)) - { - return default(T); - } - - return (T)Enum.Parse(typeof(T), src, ignoreCase); - } - - public static T TryParseOrDefault(string src, T defaultValue = default(T)) where T : struct - { - try - { - return (T)Enum.Parse(typeof(T), src, true); - } - catch (Exception) - { - return defaultValue; - } - } - - public static T Cast(object src, bool ignoreCase = true) where T : struct - { - if (src is null) - { - throw new ArgumentNullException(); - } - - return (T)Enum.Parse(typeof(T), src.ToString(), ignoreCase); - } - - class GenericCache where T : Enum - { - public static T[] Values = GetValues().ToArray(); - - static IEnumerable GetValues() - { - foreach (var t in Enum.GetValues(typeof(T))) - { - yield return (T)t; - } - } - } - - public static T[] Values() where T : Enum - { - return GenericCache.Values; - } - } -} diff --git a/Assets/VRM10/vrmlib/Runtime/EnumUtil.cs.meta b/Assets/VRM10/vrmlib/Runtime/EnumUtil.cs.meta deleted file mode 100644 index 28808c47e..000000000 --- a/Assets/VRM10/vrmlib/Runtime/EnumUtil.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 035afec0107099641b5bc89b84a51733 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: