仿照 雨松MOMO 写了一个自动生成动画的脚本 原地址 http://www.xuanyusong.com/archives/3243
添加菜单Tools/CreateAnimation,弹出窗口
你需要设置动画名、是否循环及动画播放帧率,拖入一张待生成动画的图片。
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.IO;
using UnityEditor.Animations;
public class CreateAnimation : EditorWindow {
string AnimationName = "";
Texture2D ImageName;
//图片所在文件夹位置
string ImagePath = "";
//动画存放位置
string AnimationPath = "";
//预制体存放位置
string PrefabPath = "";
//动画是否循环
bool showBtn = true;
//动画帧率
string frameRate = "";
//定义弹出当前窗口的菜单位置
[MenuItem("Tools/CreateAnimation")]
static void Init()
{
//弹出窗口
EditorWindow.GetWindow(typeof(CreateAnimation));
}
void OnGUI()
{
AnimationName = EditorGUILayout.TextField("待生成的动画名:", AnimationName);
EditorGUILayout.BeginHorizontal();
ImageName = (Texture2D)EditorGUILayout.ObjectField("待用第一张图片:", ImageName, typeof(Texture2D));
EditorGUILayout.EndHorizontal();
showBtn = EditorGUILayout.Toggle("是否循环", showBtn);
frameRate = EditorGUILayout.TextField("动画帧率(默认30):", frameRate);
ImagePath = EditorGUILayout.TextField("图片获取路径:", ImagePath);
AnimationPath = EditorGUILayout.TextField("动画生成位置:", AnimationPath);
PrefabPath = EditorGUILayout.TextField("预制体生成位置:", PrefabPath);
if (GUI.Button(new Rect(Screen.width / 4, 200, Screen.width / 2, 30), "生成动画"))
{
BuildAnimation();
}
}
void BuildAnimation()
{
if (AnimationName ==