Created
September 8, 2020 08:40
-
-
Save sapphire-al2o3/e3f0e96db0ab4202a73badc539076f39 to your computer and use it in GitHub Desktop.
UnityでAnimationClipに設定されているAnimationEventの一覧を表示する
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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
public class AnimationEventView : EditorWindow | |
{ | |
[MenuItem("Editor/Animation Event View")] | |
public static void Open() | |
{ | |
EditorWindow.GetWindow<AnimationEventView>().Show(); | |
} | |
void OnSelectionChange() | |
{ | |
var clip = Selection.activeObject as AnimationClip; | |
if (clip == null) | |
{ | |
return; | |
} | |
Repaint(); | |
} | |
AnimationClip _clip; | |
int _fps = 30; | |
bool _lock = false; | |
enum TimeView | |
{ | |
Time, | |
Frame | |
} | |
enum ParameterView | |
{ | |
Float, | |
Int, | |
String | |
} | |
TimeView _timeView = TimeView.Frame; | |
ParameterView _paramView = ParameterView.Int; | |
string _functionName; | |
float _floatParam; | |
int _intParam; | |
void DrawAnimationEvent(AnimationClip clip) | |
{ | |
_lock = EditorGUILayout.Toggle("Lock", _lock); | |
_timeView = (TimeView)EditorGUILayout.EnumPopup("Time/Frame", _timeView); | |
if (_timeView == TimeView.Frame) | |
{ | |
using (new EditorGUI.IndentLevelScope()) | |
{ | |
_fps = EditorGUILayout.IntField("Frame Rate", _fps); | |
} | |
} | |
_paramView = (ParameterView)EditorGUILayout.EnumPopup("Parameter Type", _paramView); | |
if (clip == null) | |
{ | |
return; | |
} | |
EditorGUILayout.Space(); | |
EditorGUILayout.LabelField(clip.name); | |
var events = clip.events; | |
if (events.Length > 0) | |
{ | |
EditorGUILayout.BeginVertical("box"); | |
foreach (var e in events) | |
{ | |
using (new EditorGUILayout.HorizontalScope()) | |
{ | |
if (_timeView == TimeView.Frame) | |
{ | |
int frame = (int)(e.time * _fps); | |
EditorGUILayout.IntField("time", frame); | |
} | |
else | |
{ | |
EditorGUILayout.FloatField("time", e.time); | |
} | |
e.functionName = EditorGUILayout.TextField(e.functionName); | |
if (_paramView == ParameterView.Float) | |
{ | |
EditorGUILayout.FloatField("float", e.floatParameter); | |
} | |
else if (_paramView == ParameterView.Int) | |
{ | |
EditorGUILayout.IntField("int", e.intParameter); | |
} | |
else if (_paramView == ParameterView.String) | |
{ | |
EditorGUILayout.TextField("string", e.stringParameter); | |
} | |
} | |
} | |
EditorGUILayout.EndVertical(); | |
} | |
} | |
private void OnGUI() | |
{ | |
if (!_lock) | |
{ | |
_clip = Selection.activeObject as AnimationClip; | |
} | |
DrawAnimationEvent(_clip); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment