User talk:Dannyskim
From Unify Community Wiki
Author: Daniel Kim (dannyskim)
Description
Gives easy access to playing imported Animations on a Game Object. Utilizes the keyboard 1 - 0 keys for fast viewing.
Usage
This is a simple editor script. You must place this in the Editor folder of your project.
Press Play.
Select on a Game Object in the hierarchy.
Press 1 - 0 to play corresponding animation.
C# - AnimationShortcuts.cs
using UnityEngine; using UnityEditor; using System.Collections; public class AnimationShortcuts : Editor { [MenuItem ("Animation Shortcuts/Play Element 1 _1")] public static void playElement1() { playAnimInSelected(0); } [MenuItem ("Animation Shortcuts/Play Element 1 _2")] public static void playElement2() { playAnimInSelected(1); } [MenuItem ("Animation Shortcuts/Play Element 1 _3")] public static void playElement3() { playAnimInSelected(2); } [MenuItem ("Animation Shortcuts/Play Element 1 _4")] public static void playElement4() { playAnimInSelected(3); } [MenuItem ("Animation Shortcuts/Play Element 1 _5")] public static void playElement5() { playAnimInSelected(4); } [MenuItem ("Animation Shortcuts/Play Element 1 _6")] public static void playElement6() { playAnimInSelected(5); } [MenuItem ("Animation Shortcuts/Play Element 1 _7")] public static void playElement7() { playAnimInSelected(6); } [MenuItem ("Animation Shortcuts/Play Element 1 _8")] public static void playElement8() { playAnimInSelected(7); } [MenuItem ("Animation Shortcuts/Play Element 1 _9")] public static void playElement9() { playAnimInSelected(8); } [MenuItem ("Animation Shortcuts/Play Element 1 _0")] public static void playElement10() { playAnimInSelected(9); } private static Animation getSelectedGameObjectAnimation() { if( Selection.activeGameObject.animation != null ) return Selection.activeGameObject.animation; else return null; } private static void playAnimInSelected( int index ){ AnimationClip[] clips; if( getSelectedGameObjectAnimation() != null ) clips = AnimationUtility.GetAnimationClips( getSelectedGameObjectAnimation() ); else { Debug.LogError( "Animation Shortcut: GameObject does not have an Animation Component attached." ); return; } Animation s = getSelectedGameObjectAnimation(); if( (index + 1) <= s.GetClipCount() ) { Debug.Log( "Animation Shortcut Play: " + clips[index].name ); s.clip = clips[index]; s.Play(); } else Debug.LogError( "Animation Shortcut: Animation Element " + index + " Does Not Exist. Index out of range." ); } }