/************************************************************************************************************************/ /// <summary> /// If the <see cref="CurrentEvent"/> has a float parameter above 0, this method returns that value. /// Otherwise this method calls <see cref="AnimancerEvent.GetFadeOutDuration"/> so if you aren't using an /// Animation Event with the function name "End" you can just call that method directly. /// </summary> public static float GetFadeOutDuration(float minDuration = AnimancerPlayable.DefaultFadeDuration) { if (CurrentEvent != null && CurrentEvent.floatParameter > 0) { return(CurrentEvent.floatParameter); } return(AnimancerEvent.GetFadeOutDuration(minDuration)); }
/************************************************************************************************************************/ /// <summary> /// Returns the runtime <see cref="AnimancerEvent.Sequence"/> compiled from this /// <see cref="Serializable"/>. Each call after the first will return the same value. /// <para></para> /// This method returns null if the sequence would be empty anyway and is used by the implicit /// conversion from <see cref="Serializable"/> to <see cref="AnimancerEvent.Sequence"/>. /// </summary> public Sequence GetSequenceOptional() { if (_Sequence != null || _NormalizedTimes == null) { return(_Sequence); } var timeCount = _NormalizedTimes.Length; if (timeCount == 0) { return(null); } var callbackCount = _Callbacks.Length; AnimancerEvent endEvent; if (callbackCount >= timeCount--) { endEvent = new AnimancerEvent(_NormalizedTimes[timeCount], GetInvoker(_Callbacks[timeCount])); } else { endEvent = new AnimancerEvent(_NormalizedTimes[timeCount], null); } _Sequence = new Sequence(timeCount) { endEvent = endEvent, Count = timeCount, _Names = _Names, }; for (int i = 0; i < timeCount; i++) { var callback = i < callbackCount?GetInvoker(_Callbacks[i]) : DummyCallback; _Sequence._Events[i] = new AnimancerEvent(_NormalizedTimes[i], callback); } return(_Sequence); }
/************************************************************************************************************************/ /// <summary> /// Sets the static <see cref="CurrentState"/> and <see cref="CurrentEvent"/> then invokes the <see cref="callback"/>. /// <para></para> /// This method catches and logs any exception thrown by the <see cref="callback"/>. /// </summary> /// <exception cref="NullReferenceException">The <see cref="callback"/> is null.</exception> public void Invoke(AnimancerState state) { var previousState = _CurrentState; var previousEvent = _CurrentEvent; _CurrentState = state; _CurrentEvent = this; try { callback(); } catch (Exception exception) { Debug.LogException(exception, state?.Root?.Component as Object); } _CurrentState = previousState; _CurrentEvent = previousEvent; }
/************************************************************************************************************************/ /// <summary> /// Sets the static <see cref="CurrentState"/> and <see cref="CurrentEvent"/> then invokes the <see cref="callback"/>. /// <para></para> /// This method catches and logs any exception thrown by the <see cref="callback"/>. /// </summary> /// <exception cref="NullReferenceException">Thrown if the <see cref="callback"/> is null.</exception> public void Invoke(AnimancerState state) { var previousState = _CurrentState; var previousEvent = _CurrentEvent; _CurrentState = state; _CurrentEvent = this; try { callback(); } catch (Exception ex) { Debug.LogException(ex); } _CurrentState = previousState; _CurrentEvent = previousEvent; }
/************************************************************************************************************************/ /// <summary> /// Returns the runtime <see cref="Sequence"/> compiled from this <see cref="Serializable"/>. /// Each call after the first will return the same value. /// </summary> /// <remarks> /// This method returns null if the sequence would be empty anyway and is used by the implicit /// conversion from <see cref="Serializable"/> to <see cref="Sequence"/>. /// </remarks> public Sequence GetEventsOptional() { if (_Events != null || _NormalizedTimes == null) { return(_Events); } var timeCount = _NormalizedTimes.Length; if (timeCount == 0) { return(null); } var callbackCount = _Callbacks != null ? _Callbacks.Length : 0; var callback = callbackCount >= timeCount-- ? GetInvoker(_Callbacks[timeCount]) : null; var endEvent = new AnimancerEvent(_NormalizedTimes[timeCount], callback); _Events = new Sequence(timeCount) { endEvent = endEvent, Count = timeCount, _Names = _Names, }; for (int i = 0; i < timeCount; i++) { callback = i < callbackCount?GetInvoker(_Callbacks[i]) : DummyCallback; _Events._Events[i] = new AnimancerEvent(_NormalizedTimes[i], callback); } return(_Events); }