Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
public class CustomAnimatorWindow : EditorWindow
string savePath = "Assets/Animations/";
RuntimeAnimatorController runtimeAnimCtrl = null;
static void Open()
void OnGUI()
printCustomLabel("Stateと同じ名前のAnimationClipを生成", Color.white,, 18);
savePath = EditorGUILayout.TextField("保存するディレクトリ", savePath);
runtimeAnimCtrl = (RuntimeAnimatorController)EditorGUILayout.ObjectField("Stateを取得する対象のAnimationController", runtimeAnimCtrl, typeof(RuntimeAnimatorController), false);
if (GUILayout.Button("Clip生成"))
AnimatorController animCtrl = runtimeAnimCtrl as AnimatorController;
AnimatorControllerLayer layer = animCtrl.layers[0]; //todo 複数レイヤー
AnimatorStateMachine stateMachine = layer.stateMachine;
foreach (var state in stateMachine.states)
AnimatorState animState = state.state;
AnimationClip animclip = new AnimationClip();
state.state.motion = (Motion)animclip; //空のClipをセット
AssetDatabase.CreateAsset(animclip, AssetDatabase.GenerateUniqueAssetPath(savePath + + ".anim"));
void printCustomLabel(string text, Color textColor, Color backColor, int fontSize, FontStyle fontStyle = FontStyle.Bold)
Color beforeBackColor = GUI.backgroundColor;
GUIStyle guiStyle = new GUIStyle();
GUIStyleState styleState = new GUIStyleState();
styleState.textColor = textColor;
styleState.background = Texture2D.whiteTexture;
GUI.backgroundColor = backColor;
guiStyle.normal = styleState;
guiStyle.fontSize = fontSize;
GUILayout.Label(text, guiStyle); //labelFieldだとうまくいかない?
GUI.backgroundColor = beforeBackColor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.