Last active
November 4, 2017 03:57
-
-
Save gologius/31d0b33762a1b5d88b9b8bb9eedd6dc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
using UnityEditor.Animations; | |
#endif | |
public class CustomAnimatorWindow : EditorWindow | |
{ | |
string savePath = "Assets/Animations/"; | |
RuntimeAnimatorController runtimeAnimCtrl = null; | |
//WIndow設定 | |
[MenuItem("Window/CustomAnimatorWindow")] | |
static void Open() | |
{ | |
EditorWindow.GetWindow<CustomAnimatorWindow>("CustomAnimator"); | |
} | |
void OnGUI() | |
{ | |
printCustomLabel("Stateと同じ名前のAnimationClipを生成", Color.white, Color.black, 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; | |
//Stateを取得し、State名がついたClipファイルを生成+Stateにセットする | |
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 + animState.name + ".anim")); | |
} | |
AssetDatabase.SaveAssets(); | |
AssetDatabase.Refresh(); | |
} | |
} | |
//Label装飾用のラッパー | |
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