コード例 #1
0
ファイル: ImageFader.cs プロジェクト: drecom/AnimalRunLand
        public IEnumerator CloseAnimationCoroutine(Action onEnd, float duration = 0.3f)
        {
            // TitleBarがあれば隠す
            //var titleBoard = this.GetComponentInChildren<TitleBoard>();
            //if (titleBoard != null) titleBoard.Hide();
            // 黒い板を作る
            var obj   = new GameObject();
            var rect  = obj.AddComponent <RectTransform>();
            var image = obj.AddComponent <UnityEngine.UI.Image>();

            rect.sizeDelta = this.rectTransform.sizeDelta;// new Vector2(720, 1280);
            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.one;
            image.color    = new Color(0, 0, 0, 0);
            obj.transform.SetParent(this.rectTransform, false);
            var easing = new Shand.Easing();

            easing.Start(Shand.EasingPattern.Linear, duration, 0.0f, 1.0f);

            while (!easing.Ended)
            {
                var val = easing.UpdateValue(Time.deltaTime);
                image.color = new Color(0, 0, 0, val);
                yield return(null);
            }

            Destroy(obj);
            onEnd();
        }
コード例 #2
0
ファイル: ImageFader.cs プロジェクト: drecom/AnimalRunLand
        public void StartOpenAnimation()
        {
            StartAnimation(openAnimationType, true, () =>
            {
                this.IsOpenAnimationFinished = true;
                this.animation = null;

                if (this.OnOpenAnimationFinished != null)
                {
                    this.OnOpenAnimationFinished();
                }
            });
        }
コード例 #3
0
ファイル: ImageFader.cs プロジェクト: drecom/AnimalRunLand
 void Update()
 {
     if (this.animation != null)
     {
         if (!this.animation.Ended)
         {
             this.animation.Update(Time.deltaTime);
         }
         else
         {
             this.animation = null;
         }
     }
 }
コード例 #4
0
 public void StartFadeIn(float durationSec, Action <GameObject> onEnd)
 {
     this.fadeAnimation = new Shand.Easing();
     this.fadeAnimation.Start(Shand.EasingPattern.Linear, durationSec, 1.0f, 0.0f);
     this.fadeAnimation.SetOnUpdate(alpha =>
     {
         SetAlpha(alpha);
     });
     this.fadeAnimation.SetFinishEvent(() =>
     {
         this.fadeAnimation = null;
         onEnd(_instance.gameObject);
         _instance.gameObject.SetActive(false);
     });
 }
コード例 #5
0
 public void StartFadeOut(Texture2D tex, Action <GameObject> configUi,
                          float durationSec, Action onEnd)
 {
     _instance.gameObject.SetActive(true);
     UnityEngine.UI.Image image = GetImage();
     image.overrideSprite = Sprite.Create(
         tex,
         new Rect(0, 0, tex.width, tex.height),
         new Vector2(0, 0)
         );
     configUi(_instance.gameObject);
     SetAlpha(0.0f);
     this.fadeAnimation = new Shand.Easing();
     this.fadeAnimation.Start(Shand.EasingPattern.Linear, durationSec, 0.0f, 1.0f);
     this.fadeAnimation.SetOnUpdate(alpha =>
     {
         SetAlpha(alpha);
     });
     this.fadeAnimation.SetFinishEvent(() =>
     {
         this.fadeAnimation = null;
         onEnd();
     });
 }
コード例 #6
0
ファイル: ImageFader.cs プロジェクト: drecom/AnimalRunLand
        public void StartAnimation(AnimationType animationType, bool isOpen, Action end)
        {
            this.animation = new Easing();
            EasingPattern?pattern     = null;
            float         durationSec = 0f;
            float         startValue  = 0f;
            float         endValue    = 0f;
            var           rect        = this.rectTransform.rect;

            switch (animationType)
            {
            case AnimationType.SlideRight:
                pattern     = EasingPattern.QuinticOut;
                durationSec = 0.3f;
                startValue  = isOpen ? -rect.width : GetXPosition();
                endValue    = isOpen ? GetXPosition() : rect.width;
                this.animation.SetOnUpdate(v => SetXPosition(v));
                break;

            case AnimationType.SlideLeft:
                pattern     = EasingPattern.QuinticOut;
                durationSec = 0.3f;
                startValue  = isOpen ? rect.width : GetXPosition();
                endValue    = isOpen ? GetXPosition() : -rect.width;
                this.animation.SetOnUpdate(v => SetXPosition(v));
                break;

            case AnimationType.SlideUp:
                pattern     = EasingPattern.QuinticOut;
                durationSec = 0.3f;
                startValue  = isOpen ? -rect.height : GetYPosition();
                endValue    = isOpen ? GetYPosition() : rect.height;
                this.animation.SetOnUpdate(v => SetYPosition(v));
                break;

            case AnimationType.SlideDown:
                pattern     = EasingPattern.QuinticOut;
                durationSec = 0.3f;
                startValue  = isOpen ? rect.height : GetYPosition();
                endValue    = isOpen ? GetYPosition() : -rect.height;
                this.animation.SetOnUpdate(v => SetYPosition(v));
                break;

            case AnimationType.Zoom:
                pattern     = isOpen ? EasingPattern.ElasticOut : EasingPattern.QuinticOut;
                durationSec = 0.3f;
                startValue  = isOpen ? 0.5f : 1.0f;
                endValue    = isOpen ? 1.0f : 0.0f;
                this.animation.SetOnUpdate(v => SetZoom(v));
                break;

            case AnimationType.None:

                /// HACK : Close の場合、ホワイトアウト処理なので、別対応します
                if (isOpen)
                {
                    this.animation = null;
                    this.rectTransform.gameObject.SetActive(true);
                    SetXPosition(GetXPosition());
                }

                return;
            }

            if (pattern.HasValue)
            {
                this.animation.Start(pattern.Value, durationSec, startValue, endValue);
            }
            else
            {
                this.animation = null;
            }

            if (this.animation != null)
            {
                this.animation.SetFinishEvent(end);
                this.animation.UpdateValue(0.0f);
            }
        }