Created
February 22, 2012 11:53
-
-
Save AngryAnt/1884486 to your computer and use it in GitHub Desktop.
An old example of how to easily preview animations on objects in-scene.
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 UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.Collections.Generic; | |
[CustomEditor (typeof (Animation))] | |
public class CustomAnimationEditor : Editor | |
{ | |
AnimationClip m_SampleClip; | |
float m_SampleTime = 0.0f; | |
List <AnimationClip> m_ClipList; | |
List <string> m_ClipNameList; | |
public List <AnimationClip> ClipList | |
{ | |
get | |
{ | |
if (m_ClipList == null) | |
{ | |
Animation animation; | |
animation = target as Animation; | |
if (animation != null) | |
{ | |
m_ClipList = new List <AnimationClip> (); | |
foreach (AnimationState state in animation) | |
{ | |
m_ClipList.Add (state.clip); | |
} | |
} | |
} | |
return m_ClipList; | |
} | |
} | |
public List <string> ClipNameList | |
{ | |
get | |
{ | |
if (m_ClipNameList == null) | |
{ | |
List <AnimationClip> clipList; | |
clipList = ClipList; | |
if (clipList != null) | |
{ | |
m_ClipNameList = new List <string> (); | |
foreach (AnimationClip clip in clipList) | |
{ | |
m_ClipNameList.Add (clip.name); | |
} | |
} | |
} | |
return m_ClipNameList; | |
} | |
} | |
public override void OnInspectorGUI () | |
{ | |
DrawDefaultInspector (); | |
Animation animation; | |
animation = target as Animation; | |
if (animation == null) | |
{ | |
return; | |
} | |
int clipIndex, newClipIndex; | |
float newSampleTime; | |
clipIndex = m_SampleClip == null ? 0 : ClipList.IndexOf (m_SampleClip); | |
newClipIndex = EditorGUILayout.Popup (clipIndex, ClipNameList.ToArray ()); | |
if (clipIndex != newClipIndex) | |
{ | |
m_SampleTime = 0.0f; | |
} | |
m_SampleClip = ClipList [newClipIndex]; | |
newSampleTime = EditorGUILayout.Slider ("Sample time", m_SampleTime, 0.0f, m_SampleClip.length); | |
if (m_SampleTime != newSampleTime) | |
{ | |
animation.gameObject.SampleAnimation (m_SampleClip, newSampleTime); | |
} | |
m_SampleTime = newSampleTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment