mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 13:54:45 -05:00
add defaultValue to EnumUtil.TryParseOrDefault
This commit is contained in:
@@ -5,15 +5,15 @@ namespace VRM
|
||||
{
|
||||
public static class EnumUtil
|
||||
{
|
||||
public static T TryParseOrDefault<T>(string src)where T: struct
|
||||
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)
|
||||
catch (Exception)
|
||||
{
|
||||
return default(T);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,28 +65,25 @@ namespace VRM
|
||||
rightLittleIntermediate,
|
||||
rightLittleDistal,
|
||||
upperChest,
|
||||
|
||||
unknown,
|
||||
}
|
||||
|
||||
public static class VRMBoneExtensions
|
||||
{
|
||||
public static VRMBone FromHumanBodyBone(this HumanBodyBones human)
|
||||
{
|
||||
return EnumUtil.TryParseOrDefault<VRMBone>(human.ToString());
|
||||
return EnumUtil.TryParseOrDefault<VRMBone>(human.ToString(), VRMBone.unknown);
|
||||
}
|
||||
public static HumanBodyBones ToHumanBodyBone(this VRMBone bone)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return EnumUtil.TryParseOrDefault<HumanBodyBones>(bone.ToString());
|
||||
#else
|
||||
if (bone == VRMBone.upperChest)
|
||||
{
|
||||
return HumanBodyBones.LastBone;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumUtil.TryParseOrDefault<HumanBodyBones>(bone.ToString());
|
||||
}
|
||||
#endif
|
||||
return EnumUtil.TryParseOrDefault<HumanBodyBones>(bone.ToString(), HumanBodyBones.LastBone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user