本文所用到的插件下载地址:
http://www.manew.com/forum.php?mod=viewthread&tid=100227&page=1#pid1322573
使用此脚本即可在unity中选中多个动画文件夹右键自动生成为预制
文件夹层级如下图:
public class AnimPrefabCreatorNew
{
private static string ProjectPath = "D:/Project/Desinty/Engineer/Desinty/Desinty";
private static string AnimationPath = "Animation";
private static string AnimationControllerPath = "Animation";
private static string PrefabPath = "Assets/Resources/RolePrefabs";
private static string towerAmmoName = "飞行物";
private static string spellRenderLayer = "mapSpell"; // 1
private static string roleRenderLayer = "mapRole"; // 2
private static string towerRenderLayer = "mapTower"; // 3
// 法术 >人 >塔
private static string animationAssetPath = "";
private static void Create(DirectoryInfo dictorys, string renderLayer, string prefabName = "")
{
string rp = dictorys.FullName;
rp = rp.Replace("\\", "/");
rp = rp.Replace(Application.dataPath, "Assets");
List<AnimationClip> clips = new List<AnimationClip>();
EditorUtility.DisplayProgressBar("create units...", dictorys.Name, 0.5f);
SpriteAnimationAsset prefabAsset = null;
BuildAnimationAsset(rp, dictorys, animationAsset =>
{
foreach (DirectoryInfo directoryInfo in dictorys.GetDirectories())
{
// 若文件夹名字是飞行物(单位的子弹) 跳过 子弹预制需要单独生成
if (directoryInfo.Name.Equals(towerAmmoName) || directoryInfo.Name.Equals(AnimationPath))
{
continue;
}
var sprites = GetAllSprites(directoryInfo);
var animationProperty = BuildAnimationProperty(animationAsset.animations, directoryInfo.Name.StrToPinyin());
BuildAnimation(animationProperty, sprites);
}
//BuildAnimationProperty(animationAsset.animations, "Normal");
prefabAsset = animationAsset;
EditorUtility.DisplayProgressBar("create Animation...", dictorys.Name, 0.8f);
});
BuildPrefab(dictorys, prefabAsset, renderLayer, prefabName);
EditorUtility.DisplayPr