using System.Collections; using UnityEngine; using FairyGUI; using System; namespace GFGGame { public class ScreenBlackController : SingletonBase { 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(); } } }