示例#1
0
        public virtual void OnClick(/*bool isClickCanceled,*/ Tween.TweenCallback callback = null)
        {
            if (tween != null && !tween.isCompleted)
            {
                tween.Complete();
            }

            if (interactable)
            {
#if MODULE_AUDIO_NATIVE
                NativeAudioHandler.PlayButtonPressSound();
#endif

                if (animationType == AnimationType.Tween)
                {
                    tween = graphic.transform.DOScale(1f, 0.04f, true).SetEasing(Ease.Type.QuadIn).OnComplete(!isClickCanceled ? callback : null);
                }
                else
                {
                    animator.SetTrigger(pointerUpTriggerParameter);
                    Tween.DelayedCall(0.075f, !isClickCanceled ? callback : null);
                }
            }
            else
            {
                //if (disabledSound != null)
                //    AudioController.PlaySound(disabledSound, AudioController.AudioType.Sound);
                //NativeAudioHandler.PlayButtonPressSound();

                //tween = graphic.transform.DOScale(1f, 0.075f, true).SetEasing(Ease.Type.QuadIn);
            }
        }
示例#2
0
        public void SetState(bool state)
        {
            Debug.Log("Toggle. Current state: " + this.state + "  new state: " + state);

            if (isBusy && this.state == state)
            {
                return;
            }

            isBusy = true;

            this.state = state;

#if USING_UNITY_EVENT
            if (onStateChanged != null)
            {
                onStateChanged.Invoke(state);
            }
#else
            if (OnStateChanged != null)
            {
                OnStateChanged.Invoke(state);
            }
#endif

            animationTweenCase = movableElement.DOAnchoredPosition(new Vector3(state ? offsetValue : -offsetValue, 0), 0.1f, true).SetEasing(Ease.Type.CubicOut).OnComplete(delegate
            {
                if (state)
                {
                    enableText.color  = activeOnTextColor;
                    disableText.color = disabledTextColor;

                    if (icon != null)
                    {
                        icon.color = activeOnTextColor;
                    }

                    movableElementGraphic.color = activeOnTextColor;
                }
                else
                {
                    enableText.color  = disabledTextColor;
                    disableText.color = activeOffTextColor;

                    if (icon != null)
                    {
                        icon.color = activeOffTextColor;
                    }

                    movableElementGraphic.color = activeOffTextColor;
                }

                isBusy = false;
            });
        }
示例#3
0
 public static void RemoveAll()
 {
     for (int i = 0; i < tweensCount; i++)
     {
         TweenCase tween = tweens[i];
         if (tween != null)
         {
             tween.Kill();
         }
     }
 }
示例#4
0
        public void FadeOut(float value, float time, bool stop = false)
        {
            TweenCase tweenCase = source.DOVolume(value, time);

            if (stop)
            {
                tweenCase.OnComplete(delegate
                {
                    source.Stop();
                });
            }
        }
示例#5
0
        public static void AddTween(TweenCase tween)
        {
            if (requiresActiveReorganization)
            {
                ReorganizeActiveTweens();
            }

            tween.isActive = true;
            tween.activeId = (maxActiveLookupID = tweensCount);

            tweens[tweensCount] = tween;
            tweensCount++;

            hasActiveTweens = true;
        }
示例#6
0
        private static void ReorganizeActiveTweens()
        {
            if (tweensCount <= 0)
            {
                maxActiveLookupID            = -1;
                reorganizeFromID             = -1;
                requiresActiveReorganization = false;

                return;
            }

            if (reorganizeFromID == maxActiveLookupID)
            {
                maxActiveLookupID--;
                reorganizeFromID             = -1;
                requiresActiveReorganization = false;

                return;
            }

            int defaultOffset   = 1;
            int tweensTempCount = maxActiveLookupID + 1;

            maxActiveLookupID = reorganizeFromID - 1;

            for (int i = reorganizeFromID + 1; i < tweensTempCount; i++)
            {
                TweenCase tween = tweens[i];
                if (tween != null)
                {
                    tween.activeId = (maxActiveLookupID = i - defaultOffset);

                    tweens[i - defaultOffset] = tween;
                    tweens[i] = null;
                }
                else
                {
                    defaultOffset++;
                }

                //Debug.Log("MaxActiveLookupID: " + maxActiveLookupID + "; ReorganizeFromID: " + reorganizeFromID + "; Offset: " + defaultOffset + ";");
            }

            requiresActiveReorganization = false;
            reorganizeFromID             = -1;
        }
示例#7
0
        private void RemoveActiveTween(TweenCase tween)
        {
            int activeId = tween.activeId;

            tween.activeId = -1;

            requiresActiveReorganization = true;

            if (reorganizeFromID == -1 || reorganizeFromID > activeId)
            {
                reorganizeFromID = activeId;
            }

            tweens[activeId] = null;

            tweensCount--;
            hasActiveTweens = (tweensCount > 0);
        }
示例#8
0
        private void PointerDownAnimation()
        {
            if (tween != null && !tween.isCompleted)
            {
                tween.Complete();
            }

            if (interactable)
            {
                if (animationType == AnimationType.Tween)
                {
                    tween = graphic.transform.DOScale(0.9f, 0.04f, true).SetEasing(Ease.Type.QuadOut);
                }
                else
                {
                    animator.SetTrigger(pointerDownTriggerParameter);
                }
            }
            else
            {
                //tween = graphic.transform.DOScale(0.96f, 0.075f, true).SetEasing(Ease.Type.QuadOut);
            }
        }
示例#9
0
 public static void MarkForKilling(TweenCase tween)
 {
     killingTweens.Add(tween);
 }
示例#10
0
        private void Update()
        {
            if (!hasActiveTweens)
            {
                return;
            }

            if (requiresActiveReorganization)
            {
                ReorganizeActiveTweens();
            }

            float deltaTime         = Time.deltaTime;
            float unscaledDeltaTime = Time.unscaledDeltaTime;

            for (int i = 0; i < tweensCount; i++)
            {
                TweenCase tween = tweens[i];
                if (tween != null)
                {
                    if (tween.isActive && !tween.isPaused)
                    {
                        if (!tween.isUnscaled)
                        {
                            if (Time.timeScale == 0)
                            {
                                continue;
                            }

                            tween.NextState(deltaTime);
                        }
                        else
                        {
                            tween.NextState(unscaledDeltaTime);
                        }

                        tween.Invoke();

                        if (tween.isCompleted)
                        {
                            tween.DefaultComplete();

                            if (tween.onCompleteCallback != null)
                            {
                                tween.onCompleteCallback.Invoke();
                            }

                            tween.Kill();
                        }
                    }
                }
            }

            int killingTweensCount = killingTweens.Count - 1;

            for (int i = killingTweensCount; i > -1; i--)
            {
                RemoveActiveTween(killingTweens[i]);
            }
            killingTweens.Clear();
        }