void Awake() { Init(); if (StartInOutState) { if (!_outStateSet) { if (Application.isPlaying) { Debug.LogWarning("Trying to start in out state, but no out state is set."); } } else { Snap(false); } } else { if (!_inStateSet) { SetIn(); State = TweenableState.In; } Snap(true); } }
private IEnumerator RunAnimateProperties(bool toIn) { // Wait for the delay if the delay isn't being controlled by a tweenable group, and if the delay mode criterium is met. if ((IgnoreInTweenableGroup || !IsControlledByTweenableGroup) && Delay > 0 && (DelayMode == DelayModes.Both || DelayMode == DelayModes.InOnly && toIn || DelayMode == DelayModes.OutOnly && !toIn)) { yield return(new WaitForSecondsRealtime(Delay)); } // Init the values to start the interpolation from. GetStartingValues(toIn); // Determine duratiom. float duration = CalculateDuration(); // Run the animation on all tweenables. while (_erpPos < 1) { SetInterpolation(ApplyEasing(_erpPos), toIn); _erpPos = Mathf.MoveTowards(_erpPos, 1, 1f / duration * Time.unscaledDeltaTime); yield return(null); } // Finish at 1. SetInterpolation(1, toIn); _erpPos = 1; // Update the state. State = toIn ? TweenableState.In : TweenableState.Out; // Alert listeners that the animation completed. if (OnCompleted != null) { OnCompleted.Invoke(toIn); } }
public override void Snap(bool toIn) { if (_animateRoutine != null) { StopCoroutine(_animateRoutine); } base.Snap(toIn); _erpPos = 0; State = toIn ? TweenableState.In : TweenableState.Out; if (OnCompleted != null) { OnCompleted.Invoke(toIn); } }
public void TweenToState(bool toIn) { if (toIn && !_inStateSet) { Debug.LogWarning("Trying to move to in state, but the state has not been defined."); return; } else if (!toIn && !_outStateSet) { Debug.LogWarning("Trying to move to out state, but the state has not been defined."); return; } if (toIn && (State == TweenableState.In || State == TweenableState.BetweenToIn) || !toIn && (State == TweenableState.Out || State == TweenableState.BetweenToOut)) { return; } if (Application.isPlaying) { // Stop any previous tweens. if (_animateRoutine != null) { StopCoroutine(_animateRoutine); } // Start the animation. State = toIn ? TweenableState.BetweenToIn : TweenableState.BetweenToOut; // 1 - x interpolation time if the previous animation was interrupted. if (_erpPos != 0) { _erpPos = 1 - _erpPos; } _animateRoutine = RunAnimateProperties(toIn); StartCoroutine(_animateRoutine); if (OnStarted != null) { OnStarted.Invoke(toIn); } } else { // Snap in the editor. Potentially animate in the editor in the future, using EditorApplication.update. Snap(toIn); } }