Merge pull request #775 from ichi-23/ichi/fix_export_root_animation

ExportRoot を animate する Animation を Export するときの挙動を修正
This commit is contained in:
ousttrue
2021-03-09 14:28:44 +09:00
committed by GitHub
5 changed files with 66 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 31c3691403d341e2a9b49d6eb895e013
timeCreated: 1615194750

View File

@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Linq;
using MeshUtility;
using MeshUtility.M17N;
using UnityEditor;
using UnityEngine;
namespace UniGLTF.Animation
{
public static class AnimationValidator
{
private enum ExporterValidatorMessages
{
[LangMsg(Languages.ja, "ExportRootをanimateすることはできません")]
[LangMsg(Languages.en, "ExportRoot cannot be animated")]
ROOT_ANIMATED,
}
public static IEnumerable<Validation> Validate(GameObject root)
{
if (root == null)
{
yield break;
}
var animationClips = new List<AnimationClip>();
var animator = root.GetComponent<Animator>();
var animation = root.GetComponent<UnityEngine.Animation>();
if (animator != null)
{
animationClips = AnimationExporter.GetAnimationClips(animator);
}
else if (animation != null)
{
animationClips = AnimationExporter.GetAnimationClips(animation);
}
if (!animationClips.Any())
{
yield break;
}
foreach (var animationClip in animationClips)
{
foreach (var editorCurveBinding in AnimationUtility.GetCurveBindings(animationClip))
{
// is root included in animation?
if (string.IsNullOrEmpty(editorCurveBinding.path))
{
yield return Validation.Error(ExporterValidatorMessages.ROOT_ANIMATED.Msg());
yield break;
}
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0f8cc79b14e847b6a9f12c3ff2631661
timeCreated: 1615188291

View File

@@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using MeshUtility.M17N;
using UniGLTF.Animation;
using UnityEditor;
using UnityEngine;
@@ -123,6 +123,7 @@ namespace UniGLTF
IEnumerable<MeshUtility.Validator> ValidatorFactory()
{
yield return MeshUtility.Validators.HierarchyValidator.ValidateRoot;
yield return AnimationValidator.Validate;
if (!m_state.ExportRoot)
{
yield break;

View File

@@ -213,7 +213,7 @@ namespace UniGLTF
{
var current = self;
var split = path.Split('/');
var split = path.Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries);
foreach (var childName in split)
{