mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 22:50:08 -05:00
Merge pull request #1778 from Santarh/enumFast
Caching Enum.GetValues with implementation of CachedEnum class
This commit is contained in:
commit
6b41e34071
|
|
@ -1,9 +1,11 @@
|
|||
{
|
||||
"name": "UniGLTF.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:7da8a75dcade2144aab699032d7d7987"
|
||||
"GUID:7da8a75dcade2144aab699032d7d7987",
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
|
|
|||
|
|
@ -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<string, string>();
|
||||
|
||||
var animator = go.GetComponent<Animator>();
|
||||
foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones)))
|
||||
foreach (var bone in CachedEnum.GetValues<HumanBodyBones>())
|
||||
{
|
||||
if (bone == HumanBodyBones.LastBone)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<T> where T : Enum
|
||||
public static class MsgCache<T> where T : struct, Enum
|
||||
{
|
||||
static Dictionary<Languages, Dictionary<T, string>> s_cache = new Dictionary<Languages, Dictionary<T, string>>();
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ namespace UniGLTF.M17N
|
|||
map = new Dictionary<T, string>();
|
||||
|
||||
var t = typeof(T);
|
||||
foreach (T value in Enum.GetValues(t))
|
||||
foreach (T value in CachedEnum.GetValues<T>())
|
||||
{
|
||||
var match = GetAttribute(value, language);
|
||||
// Attribute。無かったら enum の ToString
|
||||
|
|
@ -107,7 +108,7 @@ namespace UniGLTF.M17N
|
|||
}
|
||||
}
|
||||
|
||||
public static string Msg<T>(this T key) where T : Enum
|
||||
public static string Msg<T>(this T key) where T : struct, Enum
|
||||
{
|
||||
return MsgCache<T>.Get(Lang, key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>()
|
||||
.Where(x => x != HumanBodyBones.LastBone)
|
||||
.ToArray();
|
||||
var headSelectedBones = new HashSet<HumanBodyBones>();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
{
|
||||
"name": "UniGLTF",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:60c8346e00a8ddd4cafc5a02eceeec57"
|
||||
"GUID:60c8346e00a8ddd4cafc5a02eceeec57",
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF.Utils;
|
||||
using UnityEngine;
|
||||
using VRMShaders;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,100 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public sealed class CacheEnum
|
||||
{
|
||||
public static T Parse<T>(string name, bool ignoreCase = false) where T : struct, Enum
|
||||
{
|
||||
if(ignoreCase)
|
||||
{
|
||||
return CacheParse<T>.ParseIgnoreCase(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CacheParse<T>.Parse(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static T TryParseOrDefault<T>(string name, bool ignoreCase = false, T defaultValue=default(T)) where T : struct, Enum
|
||||
{
|
||||
try
|
||||
{
|
||||
if(ignoreCase)
|
||||
{
|
||||
return CacheParse<T>.ParseIgnoreCase(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CacheParse<T>.Parse(name);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] GetValues<T>() where T : struct, Enum
|
||||
{
|
||||
return CacheValues<T>.Values;
|
||||
}
|
||||
|
||||
private static class CacheParse<T> where T : struct, Enum
|
||||
{
|
||||
private static Dictionary<string, T> _values = new Dictionary<string, T>();
|
||||
private static Dictionary<string, T> _ignoreCaseValues = new Dictionary<string, T>(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<T>(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<T>(name, false, out result)
|
||||
? result
|
||||
: throw new ArgumentException(nameof(result));
|
||||
_values.Add(name, value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class CacheValues<T> where T : struct, Enum
|
||||
{
|
||||
public static readonly T[] Values;
|
||||
|
||||
static CacheValues()
|
||||
{
|
||||
Values = Enum.GetValues(typeof(T)) as T[];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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<HumanBodyBones>())
|
||||
{
|
||||
if (key == HumanBodyBones.LastBone)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>();
|
||||
|
||||
AssignBones(keys.Select(x =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"name": "UniHumanoid",
|
||||
"references": [],
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1595b81f792ed7b469e4391dcc7d335f
|
||||
guid: b6b7c2110b314bf4cbe36f2e16bb44a8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
8
Assets/UniGLTF/Runtime/Utils/CachedEnum.meta
Normal file
8
Assets/UniGLTF/Runtime/Utils/CachedEnum.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bca6484928e42dc46a2d05b11bbc2d75
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs
Normal file
31
Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnum.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
|
||||
namespace UniGLTF.Utils
|
||||
{
|
||||
public static class CachedEnum
|
||||
{
|
||||
public static T Parse<T>(string name, bool ignoreCase = false) where T : struct, Enum
|
||||
{
|
||||
return CachedEnumType<T>.Parse(name, ignoreCase);
|
||||
}
|
||||
|
||||
public static T TryParseOrDefault<T>(string name, bool ignoreCase = false, T defaultValue = default)
|
||||
where T : struct, Enum
|
||||
{
|
||||
try
|
||||
{
|
||||
return Parse<T>(name, ignoreCase: ignoreCase);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] GetValues<T>() where T : struct, Enum
|
||||
{
|
||||
return CachedEnumType<T>.Values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs
Normal file
43
Assets/UniGLTF/Runtime/Utils/CachedEnum/CachedEnumType.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniGLTF.Utils
|
||||
{
|
||||
internal static class CachedEnumType<T> where T : struct, Enum
|
||||
{
|
||||
private static readonly Dictionary<string, T> _values = new Dictionary<string, T>();
|
||||
private static readonly Dictionary<string, T> _ignoreCaseValues = new Dictionary<string, T>(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<T>(name, ignoreCase, out var result))
|
||||
{
|
||||
caches.Add(name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
throw new ArgumentException(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 439fd6a452234eeca5105e5591e8f9aa
|
||||
timeCreated: 1662528509
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
namespace UniGLTF.Utils
|
||||
{
|
||||
public readonly struct TransformState
|
||||
{
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 172d698f753e4e59bf65a75014016221
|
||||
fileFormatVersion: 2
|
||||
guid: 172d698f753e4e59bf65a75014016221
|
||||
timeCreated: 1657022395
|
||||
14
Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef
Normal file
14
Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "UniGLTF.Utils",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef.meta
Normal file
7
Assets/UniGLTF/Runtime/Utils/UniGLTF.Utils.asmdef.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1cd941934d098654fa21a13f28346412
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>("xxx"));
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Assert.AreEqual(HumanBodyBones.UpperChest, CacheEnum.TryParseOrDefault<HumanBodyBones>("upperchest", true));
|
||||
#else
|
||||
Assert.AreEqual(default(HumanBodyBones), CacheEnum.TryParseOrDefault<HumanBodyBones>("upperchest"));
|
||||
#endif
|
||||
Assert.AreEqual(default(HumanBodyBones), CachedEnum.TryParseOrDefault<HumanBodyBones>("xxx"));
|
||||
Assert.AreEqual(HumanBodyBones.UpperChest, CachedEnum.TryParseOrDefault<HumanBodyBones>("upperchest", true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Transform>();
|
||||
// copy先のhumanoidBoneのリストを得る
|
||||
var bones = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones));
|
||||
var humanTransforms = bones
|
||||
var humanTransforms = CachedEnum.GetValues<HumanBodyBones>()
|
||||
.Where(x => x != HumanBodyBones.LastBone)
|
||||
.Select(x => animator.GetBoneTransform(x))
|
||||
.Where(x => x != null)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// </summary>
|
||||
public void CreateDefaultPreset()
|
||||
{
|
||||
var presets = CacheEnum.GetValues<BlendShapePreset>();
|
||||
var presets = CachedEnum.GetValues<BlendShapePreset>();
|
||||
|
||||
foreach (var preset in presets)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<FirstPersonFlag>(x.firstPersonFlag, true);
|
||||
return CachedEnum.TryParseOrDefault<FirstPersonFlag>(x.firstPersonFlag, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<LookAtType>(lookAtTypeName, true);
|
||||
return CachedEnum.TryParseOrDefault<LookAtType>(lookAtTypeName, true);
|
||||
}
|
||||
set { lookAtTypeName = value.ToString(); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<VRMBone>(bone, true);
|
||||
return CachedEnum.Parse<VRMBone>(bone, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<UssageLicense>(src, true);
|
||||
return CachedEnum.TryParseOrDefault<UssageLicense>(src, true);
|
||||
}
|
||||
|
||||
[JsonSchema(Description = "Title of VRM model")]
|
||||
|
|
@ -69,7 +69,7 @@ namespace VRM
|
|||
{
|
||||
get
|
||||
{
|
||||
return CacheEnum.TryParseOrDefault<AllowedUser>(allowedUserName, true);
|
||||
return CachedEnum.TryParseOrDefault<AllowedUser>(allowedUserName, true);
|
||||
}
|
||||
set
|
||||
{
|
||||
|
|
@ -135,7 +135,7 @@ namespace VRM
|
|||
{
|
||||
get
|
||||
{
|
||||
return CacheEnum.TryParseOrDefault<LicenseType>(licenseName, true);
|
||||
return CachedEnum.TryParseOrDefault<LicenseType>(licenseName, true);
|
||||
}
|
||||
set
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>())
|
||||
{
|
||||
if (key == HumanBodyBones.LastBone)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<BlendShapePreset>(group.presetName, true);
|
||||
asset.Preset = CachedEnum.TryParseOrDefault<BlendShapePreset>(group.presetName, true);
|
||||
asset.IsBinary = group.isBinary;
|
||||
if (asset.Preset == BlendShapePreset.Unknown)
|
||||
{
|
||||
// fallback
|
||||
asset.Preset = CacheEnum.TryParseOrDefault<BlendShapePreset>(group.name, true);
|
||||
asset.Preset = CachedEnum.TryParseOrDefault<BlendShapePreset>(group.name, true);
|
||||
}
|
||||
asset.Values = group.binds.Select(x =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<Animator>();
|
||||
|
||||
var srcHumanBones = Enum.GetValues(typeof(HumanBodyBones))
|
||||
.Cast<HumanBodyBones>()
|
||||
var srcHumanBones = CachedEnum.GetValues<HumanBodyBones>()
|
||||
.Where(x => x != HumanBodyBones.LastBone)
|
||||
.Select(x => new { Key = x, Value = src.GetBoneTransform(x) })
|
||||
.Where(x => x.Value != null)
|
||||
|
|
|
|||
|
|
@ -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": [],
|
||||
|
|
|
|||
|
|
@ -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<UniGLTF.Extensions.VRMC_vrm.MaterialColorType>();
|
||||
var bindType = bindTypes[bindTypeProp.enumValueIndex];
|
||||
var newBindType = ExpressionEditorHelper.EnumPopup(rect, bindType);
|
||||
if (newBindType != bindType)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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<ExpressionPreset, VRM10Expression>();
|
||||
foreach (ExpressionPreset expression in System.Enum.GetValues(typeof(ExpressionPreset)))
|
||||
foreach (ExpressionPreset expression in CachedEnum.GetValues<ExpressionPreset>())
|
||||
{
|
||||
if (expression == ExpressionPreset.custom)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>())
|
||||
{
|
||||
var transform = humanoid.GetBoneTransform(humanBoneType);
|
||||
if (transform != null && Nodes.TryGetValue(transform.gameObject, out VrmLib.Node node))
|
||||
|
|
|
|||
|
|
@ -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<AccessorVectorType>(accessor.type);
|
||||
var vectorType = CachedEnum.Parse<AccessorVectorType>(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<AccessorVectorType>(firstAccessor.type),
|
||||
CachedEnum.Parse<AccessorVectorType>(firstAccessor.type, ignoreCase: true),
|
||||
totalCount);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>(bone);
|
||||
return CachedEnum.Parse<HumanBodyBones>(bone.ToString(), ignoreCase: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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": [],
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VrmLib
|
||||
{
|
||||
public static class EnumUtil
|
||||
{
|
||||
public static T Parse<T>(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<T>(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<T>(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<T> where T : Enum
|
||||
{
|
||||
public static T[] Values = GetValues().ToArray();
|
||||
|
||||
static IEnumerable<T> GetValues()
|
||||
{
|
||||
foreach (var t in Enum.GetValues(typeof(T)))
|
||||
{
|
||||
yield return (T)t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] Values<T>() where T : Enum
|
||||
{
|
||||
return GenericCache<T>.Values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 035afec0107099641b5bc89b84a51733
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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<HumanoidBones>())
|
||||
{
|
||||
Add(key, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HumanoidBones>()
|
||||
.Select(bone => bone.GetType().GetField(bone.ToString()))
|
||||
.Select(info => info.GetCustomAttributes(typeof(BoneRequiredAttribute), false) as BoneRequiredAttribute[])
|
||||
.Where(attributes => attributes.Length > 0);
|
||||
= CachedEnum.GetValues<HumanoidBones>()
|
||||
.Select(bone => bone.GetType().GetField(bone.ToString()))
|
||||
.Select(info => info.GetCustomAttributes(typeof(BoneRequiredAttribute), false) as BoneRequiredAttribute[])
|
||||
.Where(attributes => attributes.Length > 0);
|
||||
|
||||
var nodeHumanoids
|
||||
= vrmhumanoids
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
{
|
||||
"name": "VrmLib",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c"
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
{
|
||||
"name": "VRM10.Samples.VRM10Viewer",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:b7aa47b240b57de44a4b2021c143c9bf",
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:e47c917724578cc43b5506c17a27e9a0"
|
||||
"GUID:e47c917724578cc43b5506c17a27e9a0",
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
|||
|
|
@ -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<HumanBodyBones>())
|
||||
{
|
||||
if (bone == HumanBodyBones.LastBone)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "VRM.Samples.SimpleViewer",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:b7aa47b240b57de44a4b2021c143c9bf",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user