Use CachedEnum

This commit is contained in:
Masataka SUMI
2022-09-07 15:38:02 +09:00
parent 85a3f0fe3a
commit 29163a43b1
12 changed files with 20 additions and 19 deletions

View File

@@ -149,7 +149,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)
{

View File

@@ -28,7 +28,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 +57,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 +107,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);
}

View File

@@ -129,7 +129,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>();

View File

@@ -171,8 +171,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)

View File

@@ -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)
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UniGLTF;
using UniGLTF.MeshUtility;
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)

View File

@@ -1,4 +1,5 @@
using System;
using UniGLTF;
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)

View File

@@ -136,7 +136,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)
{

View File

@@ -40,7 +40,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))

View File

@@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UniGLTF;
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);
}

View File

@@ -115,10 +115,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

View File

@@ -276,7 +276,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)
{