Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExportRoot を animate する Animation を Export するときの挙動を修正 #775

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Assets/UniGLTF/Editor/Animation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions Assets/UniGLTF/Editor/Animation/AnimationValidator.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions Assets/UniGLTF/Editor/Animation/AnimationValidator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using MeshUtility.M17N;
using UniGLTF.Animation;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -123,6 +123,7 @@ static BeginVerticalScrollViewFunc BeginVerticalScrollView
IEnumerable<MeshUtility.Validator> ValidatorFactory()
{
yield return MeshUtility.Validators.HierarchyValidator.ValidateRoot;
yield return AnimationValidator.Validate;
if (!m_state.ExportRoot)
{
yield break;
Expand Down
2 changes: 1 addition & 1 deletion Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static Transform GetFromPath(this Transform self, string path)
{
var current = self;

var split = path.Split('/');
var split = path.Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringSplitOptions.RemoveEmptyEntries を使うオーバーロードが Split(char[], StringSplitOptions) しかなかった


foreach (var childName in split)
{
Expand Down