| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 | using System.Collections;using UnityEngine;using FairyGUI;using System;namespace GFGGame{    public class ScreenBlackController : SingletonBase<ScreenBlackController>    {        private const float fadeDuration = 0.2f;        private bool isShowing;        private GGraph _gGraph;        private GTweener _gTween;        private float _duration;        public void ShowBlack(float durationMilliSecs, GComponent parent = null, int index = -1)        {            if(isShowing)            {                return;            }            _duration = durationMilliSecs/1000f - fadeDuration * 2;            _duration = Mathf.Max(fadeDuration * 2, _duration);            isShowing = true;            if(_gGraph == null)            {                _gGraph = new GGraph();                _gGraph.DrawRect(GRoot.inst.width, GRoot.inst.height, 0, Color.black, Color.black);                _gGraph.AddRelation(GRoot.inst, RelationType.Size);            }            if (parent == null)            {                ViewManager.AddChildToTopLayer(_gGraph);            }            else            {                if(index < 0)                {                    parent.AddChild(_gGraph);                }                else                {                    parent.AddChildAt(_gGraph, index);                }            }            _gGraph.x = -(_gGraph.width - GRoot.inst.width) / 2;            _gGraph.y = -(_gGraph.height - GRoot.inst.height) / 2;            _gGraph.alpha = 0;            _gTween = _gGraph.TweenFade(1, fadeDuration);            _gTween.OnComplete(OnFadeInComplete);            //_gTween.OnUpdate(() => { Debug.LogFormat("alpha{0}", _gGraph.alpha); });        }        public void HideBlack()        {            isShowing = false;            Timers.inst.Remove(OnBlackComplete);            if(_gTween != null)            {                _gTween.Kill();            }            if(_gGraph != null)            {                _gGraph.RemoveFromParent();            }        }        private void OnFadeInComplete()        {            Timers.inst.Add(_duration, 1, OnBlackComplete);        }        private void OnBlackComplete(object param)        {            _gTween = _gGraph.TweenFade(0, fadeDuration);            _gTween.OnComplete(OnFadeOutComplete);        }        private void OnFadeOutComplete()        {            HideBlack();        }    }}
 |