User talk:Dannyskim
From Unify Community Wiki
(Difference between revisions)
(Created page with "Author: Daniel Kim (dannyskim) == Description == Gives easy access to playing imported Animations on a Game Object. Utilizes the keyboard 1 - 0 keys for...") |
|||
Line 28: | Line 28: | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 2 _2")] |
public static void playElement2() { | public static void playElement2() { | ||
playAnimInSelected(1); | playAnimInSelected(1); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 3 _3")] |
public static void playElement3() { | public static void playElement3() { | ||
playAnimInSelected(2); | playAnimInSelected(2); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 4 _4")] |
public static void playElement4() { | public static void playElement4() { | ||
playAnimInSelected(3); | playAnimInSelected(3); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 5 _5")] |
public static void playElement5() { | public static void playElement5() { | ||
playAnimInSelected(4); | playAnimInSelected(4); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 6 _6")] |
public static void playElement6() { | public static void playElement6() { | ||
playAnimInSelected(5); | playAnimInSelected(5); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 7 _7")] |
public static void playElement7() { | public static void playElement7() { | ||
playAnimInSelected(6); | playAnimInSelected(6); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 8 _8")] |
public static void playElement8() { | public static void playElement8() { | ||
playAnimInSelected(7); | playAnimInSelected(7); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 9 _9")] |
public static void playElement9() { | public static void playElement9() { | ||
playAnimInSelected(8); | playAnimInSelected(8); | ||
} | } | ||
− | [MenuItem ("Animation Shortcuts/Play Element | + | [MenuItem ("Animation Shortcuts/Play Element 10 _0")] |
public static void playElement10() { | public static void playElement10() { | ||
playAnimInSelected(9); | playAnimInSelected(9); |
Latest revision as of 19:24, 23 April 2012
Author: Daniel Kim (dannyskim)
[edit] Description
Gives easy access to playing imported Animations on a Game Object. Utilizes the keyboard 1 - 0 keys for fast viewing.
[edit] 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.
[edit] 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 2 _2")] public static void playElement2() { playAnimInSelected(1); } [MenuItem ("Animation Shortcuts/Play Element 3 _3")] public static void playElement3() { playAnimInSelected(2); } [MenuItem ("Animation Shortcuts/Play Element 4 _4")] public static void playElement4() { playAnimInSelected(3); } [MenuItem ("Animation Shortcuts/Play Element 5 _5")] public static void playElement5() { playAnimInSelected(4); } [MenuItem ("Animation Shortcuts/Play Element 6 _6")] public static void playElement6() { playAnimInSelected(5); } [MenuItem ("Animation Shortcuts/Play Element 7 _7")] public static void playElement7() { playAnimInSelected(6); } [MenuItem ("Animation Shortcuts/Play Element 8 _8")] public static void playElement8() { playAnimInSelected(7); } [MenuItem ("Animation Shortcuts/Play Element 9 _9")] public static void playElement9() { playAnimInSelected(8); } [MenuItem ("Animation Shortcuts/Play Element 10 _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." ); } }