Skip to content

Instantly share code, notes, and snippets.

@ryanmillerca
Created May 18, 2020 16:16
Show Gist options
  • Save ryanmillerca/cce9dcbda554ce81c7b6b46df5668f7f to your computer and use it in GitHub Desktop.
Save ryanmillerca/cce9dcbda554ce81c7b6b46df5668f7f to your computer and use it in GitHub Desktop.
AnimatorTransitionHelper for setting animator state transitions to Exit Time 1 etc quickly
// Animator transition helper
// Gives you shortcuts to set Animator Transitions (in Mecanim/State Machines)
// to an immediate trigger transition, or an exit time 1 trigger
// useful for people who don't want any blending but still want to use Mecanim!
// made by Ryan Miller https://www.ryanmiller.ca
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
public class AnimatorTransitionHelper : MonoBehaviour {
[MenuItem("Animator/Set Transition(s) to Continue &0")]
public static void ConvertTransitionToContinue(){
foreach (Object obj in Selection.objects){
if (obj.GetType() == typeof(AnimatorStateTransition)){
Undo.RecordObject(obj, "Set Continue Transition");
AnimatorStateTransition transition = obj as AnimatorStateTransition;
transition.hasExitTime = false;
transition.exitTime = 0;
transition.hasFixedDuration = false;
transition.duration = 0;
transition.offset = 0;
AnimatorCondition continueCondition = new AnimatorCondition();
continueCondition.mode = AnimatorConditionMode.If;
continueCondition.parameter = "Continue"; // replace with whatever trigger you like
transition.conditions = new AnimatorCondition[1] { continueCondition };
}
}
}
[MenuItem("Animator/Set Transition(s) to Exit Time &9")]
public static void ConvertTransitionToExitTime(){
foreach (Object obj in Selection.objects){
if (obj.GetType() == typeof(AnimatorStateTransition)){
ConvertTransitionToExitTime(obj as AnimatorStateTransition);
}
}
}
public static void ConvertTransitionToExitTime(AnimatorStateTransition transition){
Undo.RecordObject(transition, "Set Exit Time Transition");
transition.hasExitTime = true;
transition.exitTime = 1;
transition.hasFixedDuration = false;
transition.duration = 0;
transition.offset = 0;
transition.conditions = new AnimatorCondition[0] { };
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment