Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created February 22, 2012 11:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngryAnt/1884486 to your computer and use it in GitHub Desktop.
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.
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