UnityEditor.Animations API in a build
I've been working with mecanim scripting; switching in and out different types of animations using the Animator Override Controller. This worked fine on its own however I also needed to edit the transitions before and after using the UnityEditor.Animations API, this is due to some animations needing a longer duration or cutting them short to blend correctly dependent on the overridden animation my usage shown below:
UnityEditor.Animations.AnimatorStateTransition forwardsAttackTransitionEnter;
UnityEditor.Animations.AnimatorStateTransition backwardsAttackTransitionEnter;
animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
animator.runtimeAnimatorController = animatorOverrideController;
UnityEditor.Animations.AnimatorController animationController = animatorOverrideController.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
foreach(var anyStateTransition in animationController.layers[0].stateMachine.anyStateTransitions)
{
if (anyStateTransition.name == "forwardsAttackTransitionEnter") forwardsAttackTransitionEnter = anyStateTransition;
if (anyStateTransition.name == "backwardsAttackTransitionEnter") backwardsAttackTransitionEnter = anyStateTransition;
}
forwardsAttackTransitionEnter.hasExitTime = weaponData.weaponDictionary[currentWeapon].hasExitTimeEnter;
forwardsAttackTransitionEnter.exitTime = weaponData.weaponDictionary[currentWeapon].exitTimeEnter;
forwardsAttackTransitionEnter.duration = weaponData.weaponDictionary[currentWeapon].transitionDurationEnter;
forwardsAttackTransitionEnter.offset = weaponData.weaponDictionary[currentWeapon].transitionOffsetEnter;
animatorOverrideController["SwordSwing"] = weaponData.weaponDictionary[currentWeapon].weaponforwardAnim;
This works "okay" in the editor (the animator skips for a second as the new transition data is entered) but building this unfortunately won't work as the Unity Editor namespace isn't included for standalone builds.
Is there a way to get this code to work in a build or a similar way to get this done using the normal API, if not are there any assets that expose the animator run-time variables like this, or any other ways to implement what I'm trying to achieve?
Thanks for your time - Aaron
Answer by shrinath-kopare · Jan 30, 2018 at 03:57 PM
This might help you...have a look http://shrinath-kopare.blogspot.in/2018/01/adding-and-controlling-animator.html
Answer by Aethon · Jan 31, 2018 at 10:24 AM
@shrinath-kopare Thanks for the help, unfortunately I'm looking to edit the transition settings at run-time instead of running an animation on any game object.
Thanks for the effort though!