mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-13 22:39:39 -05:00
Use CachedEnum instead of EnumUtil
This commit is contained in:
@@ -202,7 +202,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 +278,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
|
||||
|
||||
@@ -721,7 +721,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,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:
|
||||
Reference in New Issue
Block a user