unity动画指定器

using UnityEngine;
using UnityEditor;
using System.Collections;
/// <summary>
/// 模型动画 分配器
/// </summary>
public class AnimationAssigner : EditorWindow
{
    static readonly string STR_MYNAME = "模型动画2Prefab";
    static readonly string STR_TARGET = "Project中的模型";
    static readonly string STR_PREFAB = "场景中的prefab";
    static readonly string STR_OK = "开始";
    static readonly string STR_INTRODUCE = "将Project中模型的动画,直接复制到场景的某Prefab中.";

    //分离好动画的模型,Project内
    GameObject model;
    //需要指定动画的 prefab.Hierarchy内
    GameObject prefab;

    [MenuItem("Level4/AnimationTool/ModelAnimationAssign")]
    static void Init()
    {
        EditorWindow.GetWindow<AnimationAssigner>(false,STR_MYNAME);
    }

    void OnGUI()
    {
        GUILayout.Box(STR_INTRODUCE);

        model = EditorGUILayout.ObjectField(STR_TARGET, model, typeof(GameObject), true) as GameObject;
        prefab = EditorGUILayout.ObjectField(STR_PREFAB, prefab, typeof(GameObject), true) as GameObject;

        if (GUILayout.Button(STR_OK))
        {
            if (model != null && prefab != null)
            {
                if (prefab.animation == null)
                    prefab.AddComponent<Animation>();

                AnimationUtility.SetAnimationClips(prefab.animation, AnimationUtility.GetAnimationClips(model.animation));
                ShowNotification(new GUIContent("完成指定:" + prefab.animation.GetClipCount()));
            }
        }
    }

    void OnSelectionChange()
    {

    }

}

你可能感兴趣的:(unityeditor,unityengine)