diff --git a/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef b/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef index 7d8718ed4..8298fa473 100644 --- a/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef +++ b/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef @@ -1,9 +1,11 @@ { "name": "UniGLTF.Editor", + "rootNamespace": "", "references": [ "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:da3e51d19d51a544fa14d43fee843098", - "GUID:7da8a75dcade2144aab699032d7d7987" + "GUID:7da8a75dcade2144aab699032d7d7987", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [ "Editor" diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/InternalTPose.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/InternalTPose.cs index 703068203..3536ef1a1 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/InternalTPose.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/InternalTPose.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using UniGLTF.M17N; +using UniGLTF.Utils; using UnityEngine; namespace UniGLTF @@ -149,7 +150,7 @@ namespace UniGLTF var existingMappings = new Dictionary(); var animator = go.GetComponent(); - foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones))) + foreach (var bone in CachedEnum.GetValues()) { if (bone == HumanBodyBones.LastBone) { diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/M17N.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/M17N.cs index 69e8c2fb7..aebb5d545 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/M17N.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/M17N.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using UniGLTF.Utils; using UnityEditor; namespace UniGLTF.M17N @@ -28,7 +29,7 @@ namespace UniGLTF.M17N } } - public static class MsgCache where T : Enum + public static class MsgCache where T : struct, Enum { static Dictionary> s_cache = new Dictionary>(); @@ -57,7 +58,7 @@ namespace UniGLTF.M17N map = new Dictionary(); var t = typeof(T); - foreach (T value in Enum.GetValues(t)) + foreach (T value in CachedEnum.GetValues()) { var match = GetAttribute(value, language); // Attribute。無かったら enum の ToString @@ -107,7 +108,7 @@ namespace UniGLTF.M17N } } - public static string Msg(this T key) where T : Enum + public static string Msg(this T key) where T : struct, Enum { return MsgCache.Get(Lang, key); } diff --git a/Assets/UniGLTF/Editor/UniGLTF/Gizmo/BoneInfo.cs b/Assets/UniGLTF/Editor/UniGLTF/Gizmo/BoneInfo.cs index 09cb3a798..c29c62ff1 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/Gizmo/BoneInfo.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/Gizmo/BoneInfo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using UniGLTF.Utils; using UnityEngine; namespace UniGLTF @@ -129,7 +130,7 @@ namespace UniGLTF throw new ArgumentException("not humanoid"); } - var validBones = ((HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones))) + var validBones = CachedEnum.GetValues() .Where(x => x != HumanBodyBones.LastBone) .ToArray(); var headSelectedBones = new HashSet(); diff --git a/Assets/UniGLTF/Runtime/UniGLTF.asmdef b/Assets/UniGLTF/Runtime/UniGLTF.asmdef index 7932fb6b1..b0a6d0090 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF.asmdef +++ b/Assets/UniGLTF/Runtime/UniGLTF.asmdef @@ -1,8 +1,10 @@ { "name": "UniGLTF", + "rootNamespace": "", "references": [ "GUID:da3e51d19d51a544fa14d43fee843098", - "GUID:60c8346e00a8ddd4cafc5a02eceeec57" + "GUID:60c8346e00a8ddd4cafc5a02eceeec57", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs b/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs index 09e8de3fe..57b9cefe2 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/RuntimeGltfInstance.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using System.Linq; +using UniGLTF.Utils; using UnityEngine; using VRMShaders; diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Util/CacheEnum.cs b/Assets/UniGLTF/Runtime/UniGLTF/Util/CacheEnum.cs deleted file mode 100644 index 5c90f6282..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/Util/CacheEnum.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace UniGLTF -{ - public sealed class CacheEnum - { - public static T Parse(string name, bool ignoreCase = false) where T : struct, Enum - { - if(ignoreCase) - { - return CacheParse.ParseIgnoreCase(name); - } - else - { - return CacheParse.Parse(name); - } - } - - public static T TryParseOrDefault(string name, bool ignoreCase = false, T defaultValue=default(T)) where T : struct, Enum - { - try - { - if(ignoreCase) - { - return CacheParse.ParseIgnoreCase(name); - } - else - { - return CacheParse.Parse(name); - } - } - catch - { - return defaultValue; - } - } - - public static T[] GetValues() where T : struct, Enum - { - return CacheValues.Values; - } - - private static class CacheParse where T : struct, Enum - { - private static Dictionary _values = new Dictionary(); - private static Dictionary _ignoreCaseValues = new Dictionary(StringComparer.OrdinalIgnoreCase); - - static CacheParse() - { - } - - public static T ParseIgnoreCase(string name) - { - if(_ignoreCaseValues.TryGetValue(name, out var value)) - { - return value; - } - else - { - T result; - value = Enum.TryParse(name, true, out result) - ? result - : throw new ArgumentException(nameof(result)); - _ignoreCaseValues.Add(name, value); - return value; - } - } - - public static T Parse(string name) - { - if(_values.TryGetValue(name, out var value)) - { - return value; - } - else - { - T result; - value = Enum.TryParse(name, false, out result) - ? result - : throw new ArgumentException(nameof(result)); - _values.Add(name, value); - return value; - } - } - } - - private static class CacheValues where T : struct, Enum - { - public static readonly T[] Values; - - static CacheValues() - { - Values = Enum.GetValues(typeof(T)) as T[]; - } - } - } -} - diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/BoneMapping.cs b/Assets/UniGLTF/Runtime/UniHumanoid/BoneMapping.cs index f9233e664..a3c9446ea 100644 --- a/Assets/UniGLTF/Runtime/UniHumanoid/BoneMapping.cs +++ b/Assets/UniGLTF/Runtime/UniHumanoid/BoneMapping.cs @@ -1,6 +1,6 @@ using UnityEngine; using System.Linq; -using System; +using UniGLTF.Utils; namespace UniHumanoid { @@ -26,7 +26,7 @@ namespace UniHumanoid { if (animator.avatar != null) { - foreach (HumanBodyBones key in Enum.GetValues(typeof(HumanBodyBones))) + foreach (var key in CachedEnum.GetValues()) { if (key == HumanBodyBones.LastBone) { diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/Humanoid.cs b/Assets/UniGLTF/Runtime/UniHumanoid/Humanoid.cs index 2b099488e..247e020b7 100644 --- a/Assets/UniGLTF/Runtime/UniHumanoid/Humanoid.cs +++ b/Assets/UniGLTF/Runtime/UniHumanoid/Humanoid.cs @@ -1,7 +1,7 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; +using UniGLTF.Utils; using UnityEngine; namespace UniHumanoid @@ -424,7 +424,7 @@ namespace UniHumanoid return false; } - var keys = (UnityEngine.HumanBodyBones[])Enum.GetValues(typeof(UnityEngine.HumanBodyBones)); + var keys = CachedEnum.GetValues(); AssignBones(keys.Select(x => { diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/SkeletonMeshUtility.cs b/Assets/UniGLTF/Runtime/UniHumanoid/SkeletonMeshUtility.cs index 053a36dd1..3ad55a440 100644 --- a/Assets/UniGLTF/Runtime/UniHumanoid/SkeletonMeshUtility.cs +++ b/Assets/UniGLTF/Runtime/UniHumanoid/SkeletonMeshUtility.cs @@ -186,7 +186,6 @@ namespace UniHumanoid public static SkinnedMeshRenderer CreateRenderer(Animator animator) { - //var bodyBones = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones)); var bones = animator.transform.Traverse().ToList(); var builder = new MeshBuilder(); diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/UniHumanoid.asmdef b/Assets/UniGLTF/Runtime/UniHumanoid/UniHumanoid.asmdef index b66a78290..825f3bbc2 100644 --- a/Assets/UniGLTF/Runtime/UniHumanoid/UniHumanoid.asmdef +++ b/Assets/UniGLTF/Runtime/UniHumanoid/UniHumanoid.asmdef @@ -1,6 +1,9 @@ { "name": "UniHumanoid", - "references": [], + "rootNamespace": "", + "references": [ + "GUID:1cd941934d098654fa21a13f28346412" + ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Util.meta b/Assets/UniGLTF/Runtime/Utils.meta similarity index 77% rename from Assets/UniGLTF/Runtime/UniGLTF/Util.meta rename to Assets/UniGLTF/Runtime/Utils.meta index 84a19a442..db945a3ee 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Util.meta +++ b/Assets/UniGLTF/Runtime/Utils.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1595b81f792ed7b469e4391dcc7d335f +guid: b6b7c2110b314bf4cbe36f2e16bb44a8 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/UniGLTF/Runtime/Utils/CachedEnum.meta b/Assets/UniGLTF/Runtime/Utils/CachedEnum.meta new file mode 100644 index 000000000..45099b92f --- /dev/null +++ b/Assets/UniGLTF/Runtime/Utils/CachedEnum.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bca6484928e42dc46a2d05b11bbc2d75 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs new file mode 100644 index 000000000..7bf4bd131 --- /dev/null +++ b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs @@ -0,0 +1,31 @@ +using System; + +namespace UniGLTF.Utils +{ + public static class CachedEnum + { + public static T Parse(string name, bool ignoreCase = false) where T : struct, Enum + { + return CachedEnumType.Parse(name, ignoreCase); + } + + public static T TryParseOrDefault(string name, bool ignoreCase = false, T defaultValue = default) + where T : struct, Enum + { + try + { + return Parse(name, ignoreCase: ignoreCase); + } + catch + { + return defaultValue; + } + } + + public static T[] GetValues() where T : struct, Enum + { + return CachedEnumType.Values; + } + } +} + diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Util/CacheEnum.cs.meta b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs.meta similarity index 100% rename from Assets/UniGLTF/Runtime/UniGLTF/Util/CacheEnum.cs.meta rename to Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs.meta diff --git a/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs new file mode 100644 index 000000000..8133d2a8e --- /dev/null +++ b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; + +namespace UniGLTF.Utils +{ + internal static class CachedEnumType where T : struct, Enum + { + private static readonly Dictionary _values = new Dictionary(); + private static readonly Dictionary _ignoreCaseValues = new Dictionary(StringComparer.OrdinalIgnoreCase); + private static T[] _allValues; + + public static T[] Values + { + get + { + if (_allValues == null) + { + _allValues = Enum.GetValues(typeof(T)) as T[]; + } + + return _allValues; + } + } + + public static T Parse(string name, bool ignoreCase) + { + var caches = ignoreCase ? _ignoreCaseValues : _values; + + if (caches.TryGetValue(name, out var ignoreCaseValue)) + { + return ignoreCaseValue; + } + + if (Enum.TryParse(name, ignoreCase, out var result)) + { + caches.Add(name, result); + return result; + } + + throw new ArgumentException(name); + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs.meta b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs.meta new file mode 100644 index 000000000..3d3336cf6 --- /dev/null +++ b/Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 439fd6a452234eeca5105e5591e8f9aa +timeCreated: 1662528509 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Util/TransformState.cs b/Assets/UniGLTF/Runtime/Utils/TransformState.cs similarity index 98% rename from Assets/UniGLTF/Runtime/UniGLTF/Util/TransformState.cs rename to Assets/UniGLTF/Runtime/Utils/TransformState.cs index 7e31b2f32..17b2d54f0 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Util/TransformState.cs +++ b/Assets/UniGLTF/Runtime/Utils/TransformState.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace UniGLTF +namespace UniGLTF.Utils { public readonly struct TransformState { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Util/TransformState.cs.meta b/Assets/UniGLTF/Runtime/Utils/TransformState.cs.meta similarity index 71% rename from Assets/UniGLTF/Runtime/UniGLTF/Util/TransformState.cs.meta rename to Assets/UniGLTF/Runtime/Utils/TransformState.cs.meta index f32750195..29ef11d81 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Util/TransformState.cs.meta +++ b/Assets/UniGLTF/Runtime/Utils/TransformState.cs.meta @@ -1,3 +1,3 @@ -fileFormatVersion: 2 -guid: 172d698f753e4e59bf65a75014016221 +fileFormatVersion: 2 +guid: 172d698f753e4e59bf65a75014016221 timeCreated: 1657022395 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef b/Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef new file mode 100644 index 000000000..57d5bdce8 --- /dev/null +++ b/Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef @@ -0,0 +1,14 @@ +{ + "name": "UniGLTF.Utils", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef.meta b/Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef.meta new file mode 100644 index 000000000..c62d0915a --- /dev/null +++ b/Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1cd941934d098654fa21a13f28346412 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef b/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef index e1ebdd170..bf3839155 100644 --- a/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef +++ b/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef @@ -1,12 +1,14 @@ { "name": "UniGLTF.Tests", + "rootNamespace": "", "references": [ "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:5f875fdc81c40184c8333b9d63c6ddd5", "GUID:da3e51d19d51a544fa14d43fee843098", "GUID:7da8a75dcade2144aab699032d7d7987", "GUID:27619889b8ba8c24980f49ee34dbb44a", - "GUID:0acc523941302664db1f4e527237feb3" + "GUID:0acc523941302664db1f4e527237feb3", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [ "Editor" diff --git a/Assets/UniGLTF/Tests/UniGLTF/CacheEnumTest.cs b/Assets/UniGLTF/Tests/UniGLTF/CacheEnumTest.cs index a1e3a2ac0..e14ee7919 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/CacheEnumTest.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/CacheEnumTest.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using UniGLTF.Utils; using UnityEngine; @@ -9,13 +10,8 @@ namespace UniGLTF [Test] public void CacheEnumTestSimplePasses() { - Assert.AreEqual(default(HumanBodyBones), CacheEnum.TryParseOrDefault("xxx")); - -#if UNITY_5_6_OR_NEWER - Assert.AreEqual(HumanBodyBones.UpperChest, CacheEnum.TryParseOrDefault("upperchest", true)); -#else - Assert.AreEqual(default(HumanBodyBones), CacheEnum.TryParseOrDefault("upperchest")); -#endif + Assert.AreEqual(default(HumanBodyBones), CachedEnum.TryParseOrDefault("xxx")); + Assert.AreEqual(HumanBodyBones.UpperChest, CachedEnum.TryParseOrDefault("upperchest", true)); } } } diff --git a/Assets/VRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/Editor/Format/VRMEditorExporter.cs index 4c2755d82..b8fdce6fb 100644 --- a/Assets/VRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/Editor/Format/VRMEditorExporter.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using UniGLTF; using UniGLTF.MeshUtility; +using UniGLTF.Utils; using UnityEngine; using VRMShaders; @@ -171,8 +172,7 @@ namespace VRM // copy先 var afterTransforms = target.GetComponentsInChildren(); // copy先のhumanoidBoneのリストを得る - var bones = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones)); - var humanTransforms = bones + var humanTransforms = CachedEnum.GetValues() .Where(x => x != HumanBodyBones.LastBone) .Select(x => animator.GetBoneTransform(x)) .Where(x => x != null) diff --git a/Assets/VRM/Editor/VRM.Editor.asmdef b/Assets/VRM/Editor/VRM.Editor.asmdef index 88f69347e..1f917e647 100644 --- a/Assets/VRM/Editor/VRM.Editor.asmdef +++ b/Assets/VRM/Editor/VRM.Editor.asmdef @@ -1,5 +1,6 @@ { "name": "UniVRM.Editor", + "rootNamespace": "", "references": [ "GUID:05dd262a0c0a2f841b8252c8c3815582", "GUID:b7aa47b240b57de44a4b2021c143c9bf", @@ -8,7 +9,7 @@ "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:5f875fdc81c40184c8333b9d63c6ddd5", "GUID:301b251fd9834274c9228e0532f444f7", - "GUID:bc66ece0f33b52446a0830c05781d4db" + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [ "Editor" diff --git a/Assets/VRM/Runtime/BlendShape/BlendShapeAvatar.cs b/Assets/VRM/Runtime/BlendShape/BlendShapeAvatar.cs index a5a416569..743ef2001 100644 --- a/Assets/VRM/Runtime/BlendShape/BlendShapeAvatar.cs +++ b/Assets/VRM/Runtime/BlendShape/BlendShapeAvatar.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using UniGLTF; using System.IO; +using UniGLTF.Utils; #if UNITY_EDITOR using UnityEditor; #endif @@ -61,7 +62,7 @@ namespace VRM /// public void CreateDefaultPreset() { - var presets = CacheEnum.GetValues(); + var presets = CachedEnum.GetValues(); foreach (var preset in presets) { diff --git a/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs b/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs index 1b600df6b..b3d050087 100644 --- a/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs +++ b/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using UniGLTF; using UniGLTF.MeshUtility; +using UniGLTF.Utils; using UnityEngine; @@ -126,7 +127,7 @@ namespace VRM { if (x.mesh == index) { - return CacheEnum.TryParseOrDefault(x.firstPersonFlag, true); + return CachedEnum.TryParseOrDefault(x.firstPersonFlag, true); } } diff --git a/Assets/VRM/Runtime/Format/glTF_VRM_FirstPerson.cs b/Assets/VRM/Runtime/Format/glTF_VRM_FirstPerson.cs index f1ab7e968..82a7c3799 100644 --- a/Assets/VRM/Runtime/Format/glTF_VRM_FirstPerson.cs +++ b/Assets/VRM/Runtime/Format/glTF_VRM_FirstPerson.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using UniGLTF; +using UniGLTF.Utils; using UnityEngine; -using UniJSON; namespace VRM @@ -72,7 +72,7 @@ namespace VRM { get { - return CacheEnum.TryParseOrDefault(lookAtTypeName, true); + return CachedEnum.TryParseOrDefault(lookAtTypeName, true); } set { lookAtTypeName = value.ToString(); } } diff --git a/Assets/VRM/Runtime/Format/glTF_VRM_Humanoid.cs b/Assets/VRM/Runtime/Format/glTF_VRM_Humanoid.cs index 27e1051f7..6477818ba 100644 --- a/Assets/VRM/Runtime/Format/glTF_VRM_Humanoid.cs +++ b/Assets/VRM/Runtime/Format/glTF_VRM_Humanoid.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using UniGLTF; +using UniGLTF.Utils; using UnityEngine; namespace VRM @@ -139,7 +140,7 @@ namespace VRM } get { - return CacheEnum.Parse(bone, true); + return CachedEnum.Parse(bone, true); } } diff --git a/Assets/VRM/Runtime/Format/glTF_VRM_Meta.cs b/Assets/VRM/Runtime/Format/glTF_VRM_Meta.cs index c1036ebc7..ac668008c 100644 --- a/Assets/VRM/Runtime/Format/glTF_VRM_Meta.cs +++ b/Assets/VRM/Runtime/Format/glTF_VRM_Meta.cs @@ -1,6 +1,6 @@ using System; using UniGLTF; -using UniJSON; +using UniGLTF.Utils; namespace VRM { @@ -36,7 +36,7 @@ namespace VRM { static UssageLicense FromString(string src) { - return CacheEnum.TryParseOrDefault(src, true); + return CachedEnum.TryParseOrDefault(src, true); } [JsonSchema(Description = "Title of VRM model")] @@ -69,7 +69,7 @@ namespace VRM { get { - return CacheEnum.TryParseOrDefault(allowedUserName, true); + return CachedEnum.TryParseOrDefault(allowedUserName, true); } set { @@ -135,7 +135,7 @@ namespace VRM { get { - return CacheEnum.TryParseOrDefault(licenseName, true); + return CachedEnum.TryParseOrDefault(licenseName, true); } set { diff --git a/Assets/VRM/Runtime/IO/VRMExporter.cs b/Assets/VRM/Runtime/IO/VRMExporter.cs index 1b5c06422..907b1aad9 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -1,10 +1,10 @@ using System; using System.Linq; using UniGLTF; +using UniGLTF.Utils; using UniJSON; using UnityEngine; using VRMShaders; -using ColorSpace = VRMShaders.ColorSpace; namespace VRM { @@ -72,7 +72,7 @@ namespace VRM { // set humanoid bone mapping var avatar = animator.avatar; - foreach (HumanBodyBones key in Enum.GetValues(typeof(HumanBodyBones))) + foreach (HumanBodyBones key in CachedEnum.GetValues()) { if (key == HumanBodyBones.LastBone) { diff --git a/Assets/VRM/Runtime/IO/VRMImporterContext.cs b/Assets/VRM/Runtime/IO/VRMImporterContext.cs index f48a19309..669f6991e 100644 --- a/Assets/VRM/Runtime/IO/VRMImporterContext.cs +++ b/Assets/VRM/Runtime/IO/VRMImporterContext.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Collections.Generic; using UniGLTF; using UnityEngine; -using UniJSON; using System.Threading.Tasks; +using UniGLTF.Utils; using VRMShaders; using Object = UnityEngine.Object; @@ -147,12 +147,12 @@ namespace VRM if (group != null) { asset.BlendShapeName = groupName; - asset.Preset = CacheEnum.TryParseOrDefault(group.presetName, true); + asset.Preset = CachedEnum.TryParseOrDefault(group.presetName, true); asset.IsBinary = group.isBinary; if (asset.Preset == BlendShapePreset.Unknown) { // fallback - asset.Preset = CacheEnum.TryParseOrDefault(group.name, true); + asset.Preset = CachedEnum.TryParseOrDefault(group.name, true); } asset.Values = group.binds.Select(x => { diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs index 8d9154692..f3fe1dca7 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using UniGLTF.MeshUtility; +using UniGLTF.Utils; using UniHumanoid; using UnityEngine; @@ -71,8 +72,7 @@ namespace VRM { var src = _src.GetComponent(); - var srcHumanBones = Enum.GetValues(typeof(HumanBodyBones)) - .Cast() + var srcHumanBones = CachedEnum.GetValues() .Where(x => x != HumanBodyBones.LastBone) .Select(x => new { Key = x, Value = src.GetBoneTransform(x) }) .Where(x => x.Value != null) diff --git a/Assets/VRM/Runtime/VRM.asmdef b/Assets/VRM/Runtime/VRM.asmdef index c89f8bc23..0a3337f3e 100644 --- a/Assets/VRM/Runtime/VRM.asmdef +++ b/Assets/VRM/Runtime/VRM.asmdef @@ -1,12 +1,14 @@ { "name": "VRM", + "rootNamespace": "", "references": [ "GUID:b7aa47b240b57de44a4b2021c143c9bf", "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:da3e51d19d51a544fa14d43fee843098", "GUID:301b251fd9834274c9228e0532f444f7", "GUID:a9bc101fb0471f94a8f99fd242fdd934", - "GUID:ac229b552c3025545b074203f857547c" + "GUID:ac229b552c3025545b074203f857547c", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/VRM10/Editor/Components/Expression/ReorderableMaterialColorBindingList.cs b/Assets/VRM10/Editor/Components/Expression/ReorderableMaterialColorBindingList.cs index 2a190975e..aab93c0d4 100644 --- a/Assets/VRM10/Editor/Components/Expression/ReorderableMaterialColorBindingList.cs +++ b/Assets/VRM10/Editor/Components/Expression/ReorderableMaterialColorBindingList.cs @@ -1,4 +1,5 @@ using System; +using UniGLTF.Utils; using UnityEditor; using UnityEditorInternal; using UnityEngine; @@ -52,7 +53,7 @@ namespace UniVRM10 // 対象のプロパティを enum から選択する var bindTypeProp = property.FindPropertyRelative("BindType"); - var bindTypes = (UniGLTF.Extensions.VRMC_vrm.MaterialColorType[])Enum.GetValues(typeof(UniGLTF.Extensions.VRMC_vrm.MaterialColorType)); + var bindTypes = CachedEnum.GetValues(); var bindType = bindTypes[bindTypeProp.enumValueIndex]; var newBindType = ExpressionEditorHelper.EnumPopup(rect, bindType); if (newBindType != bindType) diff --git a/Assets/VRM10/Editor/VRM10.Editor.asmdef b/Assets/VRM10/Editor/VRM10.Editor.asmdef index 1e347d844..ad3c9fdc3 100644 --- a/Assets/VRM10/Editor/VRM10.Editor.asmdef +++ b/Assets/VRM10/Editor/VRM10.Editor.asmdef @@ -1,5 +1,6 @@ { "name": "VRM10.Editor", + "rootNamespace": "", "references": [ "GUID:e47c917724578cc43b5506c17a27e9a0", "GUID:2ef84b520212e174a94668c7a0862d3b", @@ -7,7 +8,8 @@ "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:da3e51d19d51a544fa14d43fee843098", "GUID:7da8a75dcade2144aab699032d7d7987", - "GUID:b7aa47b240b57de44a4b2021c143c9bf" + "GUID:b7aa47b240b57de44a4b2021c143c9bf", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [ "Editor" diff --git a/Assets/VRM10/Editor/Vrm10InstanceEditor.cs b/Assets/VRM10/Editor/Vrm10InstanceEditor.cs index e51dc38dc..878bbf029 100644 --- a/Assets/VRM10/Editor/Vrm10InstanceEditor.cs +++ b/Assets/VRM10/Editor/Vrm10InstanceEditor.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using UniGLTF; +using UniGLTF.Utils; using UnityEditor; using UnityEngine; @@ -136,7 +137,7 @@ namespace UniVRM10 if (!string.IsNullOrEmpty(dir)) { var expressions = new Dictionary(); - foreach (ExpressionPreset expression in System.Enum.GetValues(typeof(ExpressionPreset))) + foreach (ExpressionPreset expression in CachedEnum.GetValues()) { if (expression == ExpressionPreset.custom) { diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index 6383f8f51..1138f08ee 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using UniGLTF; +using UniGLTF.Utils; using UnityEngine; using UniVRM10.FastSpringBones.Blittables; using UniVRM10.FastSpringBones.System; diff --git a/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs b/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs index 899537002..dd9e3d044 100644 --- a/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs +++ b/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs @@ -3,9 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using UniGLTF; -using Unity.Collections; +using UniGLTF.Utils; using UnityEngine; -using VrmLib; namespace UniVRM10 { @@ -40,7 +39,7 @@ namespace UniVRM10 humanoid.AssignBonesFromAnimator(); } - foreach (HumanBodyBones humanBoneType in Enum.GetValues(typeof(HumanBodyBones))) + foreach (HumanBodyBones humanBoneType in CachedEnum.GetValues()) { var transform = humanoid.GetBoneTransform(humanBoneType); if (transform != null && Nodes.TryGetValue(transform.gameObject, out VrmLib.Node node)) diff --git a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs index c829ffadc..ead32ffbe 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs @@ -4,6 +4,7 @@ using System.Runtime.InteropServices; using UniGLTF; using VrmLib; using System.Collections.Generic; +using UniGLTF.Utils; using Unity.Collections; using UnityEngine; @@ -202,7 +203,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 +279,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..0d6a2b495 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using UniGLTF; +using UniGLTF.Utils; using UnityEngine; using VRMShaders; @@ -721,7 +722,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/Runtime/VRM10.asmdef b/Assets/VRM10/Runtime/VRM10.asmdef index e8a38f04c..9c5174d79 100644 --- a/Assets/VRM10/Runtime/VRM10.asmdef +++ b/Assets/VRM10/Runtime/VRM10.asmdef @@ -1,5 +1,6 @@ { "name": "VRM10", + "rootNamespace": "", "references": [ "GUID:2ef84b520212e174a94668c7a0862d3b", "GUID:a9bc101fb0471f94a8f99fd242fdd934", @@ -9,7 +10,8 @@ "GUID:0aaf403bd13871a44b7127aef2695ff8", "GUID:b7aa47b240b57de44a4b2021c143c9bf", "GUID:f2ca1407928ebdc4bbe7765cc278be44", - "GUID:2665a8d13d1b3f18800f46e256720795" + "GUID:2665a8d13d1b3f18800f46e256720795", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [], "excludePlatforms": [], 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: diff --git a/Assets/VRM10/vrmlib/Runtime/Humanoid/Humanoid.cs b/Assets/VRM10/vrmlib/Runtime/Humanoid/Humanoid.cs index 8f21319be..332a5c9bf 100644 --- a/Assets/VRM10/vrmlib/Runtime/Humanoid/Humanoid.cs +++ b/Assets/VRM10/vrmlib/Runtime/Humanoid/Humanoid.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Collections; using System.Collections.Generic; +using UniGLTF.Utils; using UnityEngine; @@ -457,7 +458,7 @@ namespace VrmLib public void Clear() { - foreach (HumanoidBones key in Enum.GetValues(typeof(HumanoidBones))) + foreach (HumanoidBones key in CachedEnum.GetValues()) { Add(key, null); } diff --git a/Assets/VRM10/vrmlib/Runtime/Model.cs b/Assets/VRM10/vrmlib/Runtime/Model.cs index 0cb16a501..2df1be094 100644 --- a/Assets/VRM10/vrmlib/Runtime/Model.cs +++ b/Assets/VRM10/vrmlib/Runtime/Model.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using UniGLTF; +using UniGLTF.Utils; using Unity.Collections; using UnityEngine; @@ -115,10 +116,10 @@ namespace VrmLib // HumanoidBonesでBoneRequiredAttributeが定義されているものすべてが使われているかどうかを判断 var boneattributes - = Enum.GetValues(typeof(HumanoidBones)).Cast() - .Select(bone => bone.GetType().GetField(bone.ToString())) - .Select(info => info.GetCustomAttributes(typeof(BoneRequiredAttribute), false) as BoneRequiredAttribute[]) - .Where(attributes => attributes.Length > 0); + = CachedEnum.GetValues() + .Select(bone => bone.GetType().GetField(bone.ToString())) + .Select(info => info.GetCustomAttributes(typeof(BoneRequiredAttribute), false) as BoneRequiredAttribute[]) + .Where(attributes => attributes.Length > 0); var nodeHumanoids = vrmhumanoids diff --git a/Assets/VRM10/vrmlib/Runtime/VrmLib.asmdef b/Assets/VRM10/vrmlib/Runtime/VrmLib.asmdef index 0e41a1f25..308107e1e 100644 --- a/Assets/VRM10/vrmlib/Runtime/VrmLib.asmdef +++ b/Assets/VRM10/vrmlib/Runtime/VrmLib.asmdef @@ -1,7 +1,9 @@ { "name": "VrmLib", + "rootNamespace": "", "references": [ - "GUID:8d76e605759c3f64a957d63ef96ada7c" + "GUID:8d76e605759c3f64a957d63ef96ada7c", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10.Samples.VRM10Viewer.asmdef b/Assets/VRM10_Samples/VRM10Viewer/VRM10.Samples.VRM10Viewer.asmdef index 1082f824b..dc15df086 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10.Samples.VRM10Viewer.asmdef +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10.Samples.VRM10Viewer.asmdef @@ -1,10 +1,12 @@ { "name": "VRM10.Samples.VRM10Viewer", + "rootNamespace": "", "references": [ "GUID:b7aa47b240b57de44a4b2021c143c9bf", "GUID:da3e51d19d51a544fa14d43fee843098", "GUID:8d76e605759c3f64a957d63ef96ada7c", - "GUID:e47c917724578cc43b5506c17a27e9a0" + "GUID:e47c917724578cc43b5506c17a27e9a0", + "GUID:1cd941934d098654fa21a13f28346412" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index d29896e85..b99f1e17e 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Threading; using UniGLTF; +using UniGLTF.Utils; using UniHumanoid; using UnityEngine; using UnityEngine.UI; @@ -276,7 +277,7 @@ namespace UniVRM10.VRM10Viewer { var controlRig = m_controller.Runtime.ControlRig; - foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones))) + foreach (HumanBodyBones bone in CachedEnum.GetValues()) { if (bone == HumanBodyBones.LastBone) { diff --git a/Assets/VRM_Samples/SimpleViewer/VRM.Samples.SimpleViewer.asmdef b/Assets/VRM_Samples/SimpleViewer/VRM.Samples.SimpleViewer.asmdef index 34e7e556d..6db561b0b 100644 --- a/Assets/VRM_Samples/SimpleViewer/VRM.Samples.SimpleViewer.asmdef +++ b/Assets/VRM_Samples/SimpleViewer/VRM.Samples.SimpleViewer.asmdef @@ -1,5 +1,6 @@ { "name": "VRM.Samples.SimpleViewer", + "rootNamespace": "", "references": [ "GUID:da3e51d19d51a544fa14d43fee843098", "GUID:b7aa47b240b57de44a4b2021c143c9bf",