public override float ActionAnimRun(ActionAnim action) { if (!action.isRunning) { action.isRunning = true; if (action.runtimeAnimator && !string.IsNullOrEmpty(action.clip2D)) { if (action.method == AnimMethod.PlayCustom) { #if UNITY_EDITOR int hash = Animator.StringToHash(action.clip2D); if (!action.runtimeAnimator.HasState(action.layerInt, hash)) { action.ReportWarning("Cannot play clip " + action.clip2D + " on " + action.runtimeAnimator.name, action.runtimeAnimator.gameObject); } #endif action.runtimeAnimator.CrossFade(action.clip2D, action.fadeTime, action.layerInt); if (action.willWait) { // In 2019, sometimes more than 1 frame is necessary for the transition to kick in #if UNITY_2019_1_OR_NEWER return(Time.fixedDeltaTime * 2f); #else return(action.defaultPauseTime); #endif } } else if (action.method == AnimMethod.BlendShape) { action.ReportWarning("BlendShapes not available for 2D animation."); return(0f); } } } else { if (action.runtimeAnimator && !string.IsNullOrEmpty(action.clip2D)) { if (action.runtimeAnimator.GetCurrentAnimatorStateInfo(action.layerInt).normalizedTime < 1f) { return(action.defaultPauseTime / 6f); } else { action.isRunning = false; return(0f); } } } return(0f); }
public override float ActionAnimRun(ActionAnim action) { if (!action.isRunning) { action.isRunning = true; if (action.runtimeAnim2D != null && !string.IsNullOrEmpty(action.clip2D)) { if (action.method == AnimMethod.PlayCustom) { if (action.wrapMode2D == ActionAnim.WrapMode2D.Loop) { tk2DIntegration.PlayAnimation(action.runtimeAnim2D, action.clip2D, true, WrapMode.Loop); } else if (action.wrapMode2D == ActionAnim.WrapMode2D.PingPong) { tk2DIntegration.PlayAnimation(action.runtimeAnim2D, action.clip2D, true, WrapMode.PingPong); } else { tk2DIntegration.PlayAnimation(action.runtimeAnim2D, action.clip2D, true, WrapMode.Once); } if (action.willWait) { return(action.defaultPauseTime); } } else if (action.method == AnimMethod.StopCustom) { tk2DIntegration.StopAnimation(action.runtimeAnim2D); } else if (action.method == AnimMethod.BlendShape) { action.ReportWarning("BlendShapes are not available for 2D animation."); return(0f); } } } else { if (action.runtimeAnim2D != null && !string.IsNullOrEmpty(action.clip2D)) { if (!tk2DIntegration.IsAnimationPlaying(action.runtimeAnim2D, action.clip2D)) { action.isRunning = false; } else { return(Time.deltaTime); } } } return(0f); }
protected float ActionAnimProcess(ActionAnim action, bool isSkipping) { if (!action.isRunning) { action.isRunning = true; switch (action.methodMecanim) { case AnimMethodMecanim.ChangeParameterValue: if (action.runtimeAnimator && !string.IsNullOrEmpty(action.parameterName)) { if (action.mecanimParameterType == MecanimParameterType.Float) { action.runtimeAnimator.SetFloat(action.parameterName, action.parameterValue); } else if (action.mecanimParameterType == MecanimParameterType.Int) { action.runtimeAnimator.SetInteger(action.parameterName, (int)action.parameterValue); } else if (action.mecanimParameterType == MecanimParameterType.Bool) { bool paramValue = (action.parameterValue > 0f) ? true : false; action.runtimeAnimator.SetBool(action.parameterName, paramValue); } else if (action.mecanimParameterType == MecanimParameterType.Trigger) { if (!isSkipping || action.parameterValue < 1f) { action.runtimeAnimator.SetTrigger(action.parameterName); } } return(0f); } break; case AnimMethodMecanim.PlayCustom: if (action.runtimeAnimator && !string.IsNullOrEmpty(action.clip2D)) { #if UNITY_EDITOR int hash = Animator.StringToHash(action.clip2D); if (action.runtimeAnimator.HasState(0, hash)) { action.runtimeAnimator.CrossFade(hash, action.fadeTime, action.layerInt); } else { action.ReportWarning("Cannot play clip " + action.clip2D + " on " + action.runtimeAnimator.name, action.runtimeAnimator); } #else try { action.runtimeAnimator.CrossFade(action.clip2D, action.fadeTime, action.layerInt); } catch {} #endif if (action.willWait) { // In 2019, sometimes more than 1 frame is necessary for the transition to kick in #if UNITY_2019_1_OR_NEWER return(Time.fixedDeltaTime * 2f); #else return(action.defaultPauseTime); #endif } } break; case AnimMethodMecanim.BlendShape: if (action.methodMecanim == AnimMethodMecanim.BlendShape && action.shapeKey > -1) { if (action.runtimeShapeObject) { action.runtimeShapeObject.Change(action.shapeKey, action.shapeValue, action.fadeTime); if (action.willWait) { return(action.fadeTime); } } } break; default: break; } } else { switch (action.methodMecanim) { case AnimMethodMecanim.BlendShape: action.isRunning = false; return(0f); case AnimMethodMecanim.PlayCustom: if (action.runtimeAnimator.GetCurrentAnimatorStateInfo(action.layerInt).normalizedTime < 1f) { return(action.defaultPauseTime / 6f); } else { action.isRunning = false; return(0f); } default: return(0f); } } return(0f); }
protected float ActionAnimProcess(ActionAnim action, bool isSkipping) { if (!action.isRunning) { action.isRunning = true; if (action.methodMecanim == AnimMethodMecanim.ChangeParameterValue && action.runtimeAnimator && !string.IsNullOrEmpty(action.parameterName)) { if (action.mecanimParameterType == MecanimParameterType.Float) { action.runtimeAnimator.SetFloat(action.parameterName, action.parameterValue); } else if (action.mecanimParameterType == MecanimParameterType.Int) { action.runtimeAnimator.SetInteger(action.parameterName, (int)action.parameterValue); } else if (action.mecanimParameterType == MecanimParameterType.Bool) { bool paramValue = (action.parameterValue > 0f) ? true : false; action.runtimeAnimator.SetBool(action.parameterName, paramValue); } else if (action.mecanimParameterType == MecanimParameterType.Trigger) { if (!isSkipping || action.parameterValue < 1f) { action.runtimeAnimator.SetTrigger(action.parameterName); } } return(0f); } else if (action.methodMecanim == AnimMethodMecanim.PlayCustom && action.runtimeAnimator) { if (!string.IsNullOrEmpty(action.clip2D)) { #if UNITY_EDITOR int hash = Animator.StringToHash(action.clip2D); if (action.runtimeAnimator.HasState(0, hash)) { action.runtimeAnimator.CrossFade(hash, action.fadeTime, action.layerInt); } else { action.ReportWarning("Cannot play clip " + action.clip2D + " on " + action.runtimeAnimator.name, action.runtimeAnimator); } #else try { action.runtimeAnimator.CrossFade(action.clip2D, action.fadeTime, action.layerInt); } catch {} #endif if (action.willWait) { return(action.defaultPauseTime); } } } else if (action.methodMecanim == AnimMethodMecanim.BlendShape && action.shapeKey > -1) { if (action.runtimeShapeObject != null) { action.runtimeShapeObject.Change(action.shapeKey, action.shapeValue, action.fadeTime); if (action.willWait) { return(action.fadeTime); } } } } else { if (action.methodMecanim == AnimMethodMecanim.BlendShape && action.runtimeShapeObject != null) { action.isRunning = false; return(0f); } else if (action.methodMecanim == AnimMethodMecanim.PlayCustom) { if (action.runtimeAnimator && !string.IsNullOrEmpty(action.clip2D)) { if (action.runtimeAnimator.GetCurrentAnimatorStateInfo(action.layerInt).normalizedTime < 1f) { return(action.defaultPauseTime / 6f); } else { action.isRunning = false; return(0f); } } } } return(0f); }