public void HideElements(TweenCallback actionOnCompleted) { var listAnimation = new List <UIAnimation>(); for (int i = 0; i < transform.childCount; i++) { var a = transform.GetChild(i).gameObject.GetComponent <UIAnimation>(); if (a != null && !a.dontPlayWithParent) { listAnimation.Add(a); } } if (listAnimation.Any()) { for (int i = 0; i < listAnimation.Count; i++) { if (i == listAnimation.Count - 1) { listAnimation[i].Play(listAnimation[i].animationOut, false, null, null, actionOnCompleted); } else { listAnimation[i].Play(listAnimation[i].animationOut); } } } else { if (actionOnCompleted != null) { actionOnCompleted.Invoke(); } } }
public static void DoNumber(Text text, int startValue, int endValue, string fomat, float timeAnimationScale = 0.01f, string soundCount = "", string soundCompleted = "", TweenCallback onDone = null) { int nextValue = startValue; int tempValue = startValue; text.text = nextValue.ToString(); DOVirtual.Float(startValue, endValue, Mathf.Clamp(endValue * timeAnimationScale, 0.25f, 1.5f), (e) => { tempValue = Mathf.FloorToInt(e); if (tempValue != nextValue) { if (!string.IsNullOrEmpty(soundCount)) { SoundManager.Play(soundCount); } nextValue = tempValue; text.text = string.Format(fomat, nextValue); } }) .OnComplete(() => { if (!string.IsNullOrEmpty(soundCompleted)) { SoundManager.Play(soundCompleted); } text.text = string.Format(fomat, endValue); if (onDone != null) { onDone.Invoke(); } }); }
public void Close(TweenCallback onComplete = null) { if (!isOpen) { if (onComplete != null) onComplete.Invoke(); } isOpen = false; float delay = content == null || instantHideContent ? 0 : exitTime * 0.75f; //Le content se fade-out en premier if (content != null) { content.DOKill(); if (instantHideContent) content.alpha = 0; else content.DOFade(0, exitTime * 0.75f).SetEase(exitEase).SetUpdate(true); content.blocksRaycasts = false; } //Le reste a du délai (potentiellement) if (bgImage != null) { bgImage.DOKill(); bgImage.DOFade(fadeStart, exitTime).SetDelay(delay).SetUpdate(true); } if (backBg != null) { backBg.DOKill(); backBg.DOFade(0, exitTime + delay).SetUpdate(true);//.SetDelay(delay); } bgTr.DOKill(); bgTr.DOSizeDelta(smallV, exitTime).SetDelay(delay).SetEase(exitEase).OnComplete(delegate () { bgTr.gameObject.SetActive(false); if (onComplete != null) onComplete.Invoke(); }).SetUpdate(true); }
void OnUpdate() { originalUpdateAction?.Invoke(); if (!cancellationToken.IsCancellationRequested) { return; } switch (this.cancelBehaviour) { case TweenCancelBehaviour.Kill: default: this.tween.Kill(false); break; case TweenCancelBehaviour.KillAndCancelAwait: this.canceled = true; this.tween.Kill(false); break; case TweenCancelBehaviour.KillWithCompleteCallback: this.tween.Kill(true); break; case TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait: this.canceled = true; this.tween.Kill(true); break; case TweenCancelBehaviour.Complete: this.tween.Complete(false); break; case TweenCancelBehaviour.CompleteAndCancelAwait: this.canceled = true; this.tween.Complete(false); break; case TweenCancelBehaviour.CompleteWithSeqeunceCallback: this.tween.Complete(true); break; case TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait: this.canceled = true; this.tween.Complete(true); break; case TweenCancelBehaviour.CancelAwait: this.tween.onKill = EmptyTweenCallback; // replace to empty(avoid callback after Canceled(instance is returned to pool.) this.core.TrySetCanceled(this.cancellationToken); break; } }
private static IEnumerator WaitEndFrameCoRoutine(TweenCallback callback, int numOfFrame) { int i = 0; while (i < numOfFrame) { yield return(new WaitForEndOfFrame()); i++; } callback.Invoke(); }
private void FadeMesh(MeshRenderer target, float amount, float time, TweenCallback action) { if (target == null) { return; } target.material.DOFloat(amount, "_Disslove", time).SetDelay(0.1f).OnComplete(() => { if (action != null) { action.Invoke(); } }); }
public static void DoJump(this Transform transform, float timeAnimation = 0.5f, int loop = -1, float detalY = 0.35f, TweenCallback onAnimationDone = null, bool resetLocal = false) { if (transform) { transform.DOKill(); if (resetLocal) { transform.SetLocalY(0); transform.SetLocalRotation2D(0); } transform.DOLocalMoveY(detalY, timeAnimation) .SetLoops(loop, LoopType.Yoyo) .OnComplete(() => onAnimationDone?.Invoke()); } }
public static void DoRotate(this Transform transform, float timeAnimation = 0.5f, int loop = -1, TweenCallback onAnimationDone = null, bool resetLocal = false) { if (transform) { transform.DOKill(); if (resetLocal) { transform.SetLocalY(0); transform.SetLocalRotation2D(0); } transform.DOLocalRotate(-1 * Vector3.forward * 360, timeAnimation, RotateMode.FastBeyond360) .SetEase(Ease.Linear).SetLoops(loop, LoopType.Incremental) .OnComplete(() => onAnimationDone?.Invoke()); } }
protected override Tween DoTweenProcess(BuildTweenData item, TweenCallback callback) { if (_scheme.PunchData.EndTween) { callback?.Invoke(); return(null); } var data = _scheme.PunchData; return(item.Element.DOPunchScale(data.Strength, data.Duration, data.Vibrato, data.Elasticity) .SetId($"{_tweenName}{item.Element.GetInstanceID()}") .SetAutoKill(true) .Play() .OnComplete(callback)); }
/// <summary> /// Instantiates a game object on the main canvas with an animation /// </summary> /// <param name="obj"></param> /// <param name="destroyOnLoad">check whether to be destroyed on load</param> /// <param name="targetAlpha">target alpha of the animation</param> /// <param name="animationDuration">optional</param> /// <param name="onAnimationEnd">optional event</param> /// <param name="animationEase">animation style</param> /// <returns></returns> public GameObject InstantiateUI(GameObject obj, bool destroyOnLoad, float targetAlpha = 1f, float animationDuration = 0.5f, TweenCallback onAnimationEnd = null, Ease animationEase = Ease.Unset) { GameObject instance = InstantiateUIInstantly(obj, destroyOnLoad); var canvasGroup = instance.GetComponent <CanvasGroup>(); if (canvasGroup) { AnimateAlpha(canvasGroup, targetAlpha, animationDuration, onAnimationEnd, animationEase); } else { onAnimationEnd?.Invoke(); } return(instance); }
public void Open(TweenCallback onComplete) { if (isOpen) { return; } isOpen = true; bgTr.gameObject.SetActive(true); if (bgImage != null) { bgImage.DOKill(); bgImage.DOFade(bgImageAlpha, openTime * 0.75f).SetUpdate(true); } if (backBg != null) { backBg.gameObject.SetActive(true); backBg.DOKill(); backBg.DOFade(backBgAlpha, openTime).SetUpdate(true); } if (content != null) { content.gameObject.SetActive(true); bgTr.DOKill(); bgTr.DOSizeDelta(bigV, openTime).SetEase(openEase).SetUpdate(true); content.DOKill(); content.DOFade(1, openTime).SetDelay(openTime * 0.75f).SetEase(openEase).OnComplete(delegate() { content.blocksRaycasts = true; if (onComplete != null) { onComplete.Invoke(); } }).SetUpdate(true); } else { bgTr.DOKill(); bgTr.DOSizeDelta(bigV, openTime).SetEase(openEase).OnComplete(onComplete).SetUpdate(true); } }
public static void DoRotateZ(Transform tran, float to = 90f, float timeAnimation = 0.25f, float delayTime = 0.01f, TweenCallback onDone = null) { if (tran == null) { Debug.LogError("[UIAnimation] DoRotateZ: " + tran.name + " NULL"); return; } tran.DOKill(); tran.DORotate(new Vector3(0, 0, to), timeAnimation * 0.7f).OnComplete(() => { if (onDone != null) { onDone.Invoke(); } }) .SetEase(Ease.InOutCubic) .SetDelay(delayTime); }
public void FadeIn(float duration = -1, TweenCallback callback = null) { if (duration < 0) { duration = defaultFadeDuration; } fadeImage.gameObject.SetActive(true); fadeImage.DOKill(); fadeImage.DOFade(1, 0).SetUpdate(true).OnComplete(() => { fadeImage.DOFade(0, duration).SetUpdate(true).OnComplete(() => { fadeImage.gameObject.SetActive(false); callback?.Invoke(); }).Play(); }).Play(); }
/// <summary> /// is user is false then the onComplete method won't be invoked /// </summary> public virtual void SelectButton(int which, bool user = true, TweenCallback onComplete = null) { if (which == selectedButton) { // Same button is selected as the one we want to select so completion is immedaite if (onComplete != null && user) { onComplete.Invoke(); } return; } selectedButton = which; // user pressed so do tween and do callback if (user) { for (int i = 1; i <= 3; i++) { if (buttons[i].localScale != new Vector3(1f, 1f, 1f)) { buttons[i].DOScale(1f, 0.1f); } } buttons[which].DOScale(1.1f, 0.2f).OnComplete(onComplete); } else // we just called it but the user didn't press so don't do tween and don't call callback { for (int i = 1; i <= 3; i++) { if (buttons[i].localScale != new Vector3(1f, 1f, 1f)) { buttons[i].localScale = new Vector3(1f, 1f, 1f); } } buttons[which].localScale = new Vector3(1.1f, 1.1f, 1.1f); } }
private void FaceIn(RectTransform rectTransform, float timeAnimation, float timeDelay, float end = 1f, TweenCallback actionOnStart = null, TweenCallback actionOnComplete = null, Ease ease = Ease.OutCubic) { if (canvasGroup == null) { canvasGroup = rectTransform.GetComponent <CanvasGroup>(); } if (canvasGroup == null) { canvasGroup = rectTransform.gameObject.AddComponent <CanvasGroup>(); } canvasGroup.alpha = 0f; gameObject.SetActive(true); canvasGroup.DOKill(true); rectTransform.DOKill(true); rectTransform .DOAnchorPos(UIManager.startAnchoredPosition2D, 0).OnComplete(() => { canvasGroup .DOFade(end, timeAnimation) .SetDelay(timeDelay) .SetEase(ease) .SetUpdate(UpdateType.Normal, true) .OnStart(() => { actionOnStart?.Invoke(); OnStart?.Invoke(); }) .OnComplete(() => { ShowElements(() => { Status = UIAnimStatus.IsShow; actionOnComplete?.Invoke(); OnShowCompleted?.Invoke(); }); }); }).SetUpdate(UpdateType.Normal, true); }
void OnCompleteCallbackDelegate() { if (cancellationToken.IsCancellationRequested) { if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait || this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait || this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait || this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait || this.cancelBehaviour == TweenCancelBehaviour.CancelAwait) { canceled = true; } } if (canceled) { core.TrySetCanceled(cancellationToken); } else { originalCompleteAction?.Invoke(); core.TrySetResult(AsyncUnit.Default); } }
public static void StopMusic(bool faded = false, TweenCallback onComplete = null) { if (instance == null) { Debug.LogError("SoundManager instance is null"); return; } if (faded) { DOTween.To(() => instance.musicSource.volume, x => instance.musicSource.volume = x, 0, 0.5f).OnComplete(delegate() { StopMusic(false, onComplete); }); } else { instance.musicSource.Stop(); if (onComplete != null) { onComplete.Invoke(); } } }
/// <summary> /// Shows or hides the street mesh. /// </summary> /// <param name="_isOn">if true, the street will show up, if false, the street will dissolve</param> /// <param name="_onComplete">will be called after completion of the transition</param> public void ToggleAppearance(bool _isOn, TweenCallback _onComplete) { // if there is nothing to turn off, skip if (!IsOn && !_isOn) { m_renderer.material.SetFloat(DISSOLVE_ID, 0f); _onComplete?.Invoke(); return; } IsOn = _isOn; // tween on the material float endvalue = _isOn ? 1.1f : 0f; // reset value to zero because material has changed if (_isOn) { m_renderer.material.SetFloat(DISSOLVE_ID, 0f); } m_renderer.material.DOFloat(endvalue, DISSOLVE_ID, m_dissolveDuration) .OnComplete(_onComplete); }
public override void SelectButton(int which, bool user = true, TweenCallback onComplete = null) { // Hwe first dismiss the panel and only after that should we invoke the oncomplete TweenCallback dismissPanel = () => { // After that we need to dismiss the panel DOTween.Sequence() .Insert(0f, smallPanel.DOScale(0f, animTime)) .Insert(animTime * 0.3f, wholeScreenPanel.DOFade(0f, animTime)) .OnComplete( new TweenCallback(() => { if (onComplete != null) { onComplete.Invoke(); } wholeScreenPanel.gameObject.SetActive(false); // Set the one in settingspanel to the current one FindObjectOfType <AIDifficultyPanel>().SelectButton(selectedButton, false); } )); }; base.SelectButton(which, user, dismissPanel); }
private void SlideOut(RectTransform rectTransform, Vector2 toPosition, float timeAnimation, float timeDelay, TweenCallback actionOnComplete = null, Ease ease = Ease.InCubic) { //Debug.Log("SlideOut start " + name); rectTransform.DOKill(true); rectTransform .DOAnchorPos(toPosition, timeAnimation, false) .SetDelay(timeDelay) .SetEase(ease) .SetUpdate(UpdateType.Normal, true) .OnComplete(() => { //Debug.Log("SlideOut end " + name); Status = UIAnimStatus.IsHide; actionOnComplete?.Invoke(); OnHideCompleted?.Invoke(); if (onHideCompleted != null) { onHideCompleted.Invoke(); onHideCompleted = null; } gameObject.SetActive(!hideAtEnd); }); HideElements(null); }
/// <summary> /// Animates a transformation to a given Vector2 /// </summary> /// <param name="gameObject"> The GameObject being animated </param> /// <param name="endValue"> The Vector2 to reach </param> /// <param name="duration"> The duration of the animation </param> public static void AnimateTransform(this GameObject gameObject, Vector2 endValue, float duration, TweenCallback callback = null) { gameObject.transform.DOLocalMove(endValue, duration).OnComplete(() => callback?.Invoke()); }
/// <summary> /// Animates the scale Y /// </summary> /// <param name="gameObject"> The GameObject being animated </param> /// <param name="endValue"> The endvalue to reach </param> /// <param name="duration"> The duration of the animation </param> /// <param name="callback"> The method to call after the animation is complete </param> public static void AnimateScaleY(this GameObject gameObject, float endValue, float duration, TweenCallback callback = null) { gameObject.transform.DOScaleY(endValue, duration).OnComplete(() => callback?.Invoke()); }
/// <summary> /// Animates the graphic component of the image's color /// </summary> /// <param name="gameObject"> The GameObject being animated </param> /// <param name="endValue"> The endvalue to reach </param> /// <param name="duration"> The duration of the animation </param> /// <param name="callback"> The method to call after the animation is complete </param> public static void AnimateGraphic(this GameObject gameObject, float endValue, float duration, TweenCallback callback = null) { gameObject.GetComponent <Graphic>().DOFade(endValue, duration).OnComplete(() => callback?.Invoke()); }
public static void AnimateColor(this GameObject gameObject, Color endColor, float duration, TweenCallback callback = null) { gameObject.GetComponent <Graphic>().DOColor(endColor, duration).OnComplete(() => callback?.Invoke()); }
void OnUpdate() { originalUpdateAction?.Invoke(); if (!cancellationToken.IsCancellationRequested) { return; } switch (this.cancelBehaviour) { case TweenCancelBehaviour.Kill: default: this.tween.Kill(false); break; case TweenCancelBehaviour.KillAndCancelAwait: this.canceled = true; this.tween.Kill(false); break; case TweenCancelBehaviour.KillWithCompleteCallback: this.tween.Kill(true); break; case TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait: this.canceled = true; this.tween.Kill(true); break; case TweenCancelBehaviour.Complete: this.tween.Complete(false); break; case TweenCancelBehaviour.CompleteAndCancelAwait: this.canceled = true; this.tween.Complete(false); break; case TweenCancelBehaviour.CompleteWithSequenceCallback: this.tween.Complete(true); break; case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait: this.canceled = true; this.tween.Complete(true); break; case TweenCancelBehaviour.CancelAwait: // restore to original callback switch (callbackType) { case CallbackType.Kill: tween.onKill = originalCompleteAction; break; case CallbackType.Complete: tween.onComplete = originalCompleteAction; break; case CallbackType.Pause: tween.onPause = originalCompleteAction; break; case CallbackType.Play: tween.onPlay = originalCompleteAction; break; case CallbackType.Rewind: tween.onRewind = originalCompleteAction; break; case CallbackType.StepComplete: tween.onStepComplete = originalCompleteAction; break; default: break; } this.core.TrySetCanceled(this.cancellationToken); break; } }
private static IEnumerator NextFrameCoroutine(TweenCallback callback) { yield return(null); callback.Invoke(); }
protected virtual void OnTweenCompleted() { OnTweenCompletedCallback?.Invoke(); }
protected virtual void OnTweenUpdate() { OnTweenUpdateCallback?.Invoke(); }
private static IEnumerator NextFixedFrameCoroutine(TweenCallback callback) { yield return(new WaitForFixedUpdate()); callback.Invoke(); }
private IEnumerator Delayexecution() { yield return(new WaitForSeconds(delayeforcallback)); callback.Invoke(); }