最近再研究Unity的UI动效果,过程中发现一个小细节:在使用UGUI的Button时,如果设置Transition过渡方式为Animation
和其他FBX
看着明显不如Button自动生成的那种要整洁!
后来在Unity论坛上发现了一篇讨论这个问题的帖子:https://forum.unity.com/threads/embedding-motion-clips-in-the-controller-asset.379885/,其中提供了一个Editor脚本实现了此功能,我测试了一下发现有个小bug(不能在已有内嵌Clip的Controller中
// ==================================================================================================================
// NestAnimClips.cs - Nesting AnimationClips inside an AnimationContoller.
// ZombieGorilla for Unity Forums, Modified by K-Res.
// 1.0
// 2016-02-14
// ==================================================================================================================
using UnityEngine;
using UnityEditor;
public class NestAnimClips : MonoBehaviour
{
[MenuItem("Assets/Nest AnimClips in Controller")]
static public void nestAnimClips()
{
UnityEditor.Animations.AnimatorController anim_controller = null;
AnimationClip[] clips = null;
if (Selection.activeObject.GetType() == typeof(UnityEditor.Animations.AnimatorController))
{
anim_controller = (UnityEditor.Animations.AnimatorController)Selection.activeObject;
clips = anim_controller.animationClips;
if (anim_controller != null && clips.Length > 0)
{
foreach (AnimationClip ac in clips)
{
var acAssetPath = AssetDatabase.GetAssetPath(ac);
// Check if this ac is not in the controller
if (acAssetPath.EndsWith(".anim"))
{
var new_ac = Object.Instantiate(ac) as AnimationClip;
new_ac.name = ac.name;
AssetDatabase.AddObjectToAsset(new_ac, anim_controller);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(new_ac));
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(ac));
}
}
Debug.Log("Added " + clips.Length.ToString() + " clips to controller: " + anim_controller.name + "");
}
else
{
Debug.Log("Nothing done. Select a controller that has anim clips to nest.");
}
}
}
}
使用方法很简单,选中Animator Controller资源,然后右键菜单中选”Nest AnimClips in Controller”,即可将此Controller中所有外部Clip都
文字加密小工具v3
请输入要加密的内容
博主友情提示:
如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用