diff --git a/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef b/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef index 8298fa473..bad546150 100644 --- a/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef +++ b/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef @@ -5,7 +5,8 @@ "GUID:8d76e605759c3f64a957d63ef96ada7c", "GUID:da3e51d19d51a544fa14d43fee843098", "GUID:7da8a75dcade2144aab699032d7d7987", - "GUID:1cd941934d098654fa21a13f28346412" + "GUID:1cd941934d098654fa21a13f28346412", + "GUID:b7aa47b240b57de44a4b2021c143c9bf" ], "includePlatforms": [ "Editor" diff --git a/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs index 1d1b36a7e..10f7c504f 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using UniGLTF.M17N; @@ -21,6 +22,10 @@ namespace UniGLTF [LangMsg(Languages.en, "No Animator in ExportRoot")] NO_ANIMATOR, + [LangMsg(Languages.ja, "ExportRootに Animator と Humanoid がありません")] + [LangMsg(Languages.en, "No Animator and Humanoid in ExportRoot")] + NO_HUMANOID, + [LangMsg(Languages.ja, "Z+ 向きにしてください")] [LangMsg(Languages.en, "The model needs to face the positive Z-axis")] FACE_Z_POSITIVE_DIRECTION, @@ -126,34 +131,44 @@ namespace UniGLTF // // animator // - var animator = ExportRoot.GetComponent(); - if (animator == null) + Func getBoneTransform = null; + + if (ExportRoot.GetComponent() is UniHumanoid.Humanoid humanoid) { - yield return Validation.Critical(ValidationMessages.NO_ANIMATOR.Msg()); + getBoneTransform = humanoid.GetBoneTransform; + } + else if (ExportRoot.GetComponent() is Animator animator) + { + getBoneTransform = animator.GetBoneTransform; + + // avatar + var avatar = animator.avatar; + if (avatar == null) + { + yield return Validation.Critical(ValidationMessages.NO_AVATAR_IN_ANIMATOR.Msg()); + yield break; + } + if (!avatar.isValid) + { + yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_VALID.Msg()); + yield break; + } + if (!avatar.isHuman) + { + yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_HUMANOID.Msg()); + yield break; + } + } + else + { + yield return Validation.Critical(ValidationMessages.NO_HUMANOID.Msg()); yield break; } - // avatar - var avatar = animator.avatar; - if (avatar == null) - { - yield return Validation.Critical(ValidationMessages.NO_AVATAR_IN_ANIMATOR.Msg()); - yield break; - } - if (!avatar.isValid) - { - yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_VALID.Msg()); - yield break; - } - if (!avatar.isHuman) - { - yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_HUMANOID.Msg()); - yield break; - } // direction { - var l = animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg); - var r = animator.GetBoneTransform(HumanBodyBones.RightUpperLeg); + var l = getBoneTransform(HumanBodyBones.LeftUpperLeg); + var r = getBoneTransform(HumanBodyBones.RightUpperLeg); var f = GetForward(l, r); if (Vector3.Dot(f, Vector3.forward) < 0.8f) { @@ -163,10 +178,10 @@ namespace UniGLTF } { - var lu = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm); - var ll = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm); - var ru = animator.GetBoneTransform(HumanBodyBones.RightUpperArm); - var rl = animator.GetBoneTransform(HumanBodyBones.RightLowerArm); + var lu = getBoneTransform(HumanBodyBones.LeftUpperArm); + var ll = getBoneTransform(HumanBodyBones.LeftLowerArm); + var ru = getBoneTransform(HumanBodyBones.RightUpperArm); + var rl = getBoneTransform(HumanBodyBones.RightLowerArm); if (Vector3.Dot((ll.position - lu.position).normalized, Vector3.left) < 0.8f || Vector3.Dot((rl.position - ru.position).normalized, Vector3.right) < 0.8f) { @@ -174,7 +189,7 @@ namespace UniGLTF } } - var jaw = animator.GetBoneTransform(HumanBodyBones.Jaw); + var jaw = getBoneTransform(HumanBodyBones.Jaw); if (jaw != null) { yield return Validation.Warning(ValidationMessages.JAW_BONE_IS_INCLUDED.Msg(), ValidationContext.Create(jaw));