//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, April 03, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Spine.Unity; namespace vnxbqy.UI { public class LaunchBackGroundWin : Window { [SerializeField] RectTransform m_StaticBackGround; [SerializeField] Image m_BackGroundImage; [SerializeField] CanvasGroup m_CanvasGroup; [SerializeField] TextEx info; LoginModel loginModel { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { var sprite = BuiltInLoader.LoadSprite("LoginBackGround"); m_BackGroundImage.overrideSprite = sprite; m_BackGroundImage.preserveAspect = true; m_StaticBackGround.SetActive(true); this.transform.SetAsFirstSibling(); info.text = loginModel.loginErrorInfo; loginModel.loginErrorEvent += OnLoginError; } protected override void OnAfterOpen() { } protected override void OnPreClose() { loginModel.loginErrorEvent -= OnLoginError; loginModel.loginErrorInfo = string.Empty; } protected override void OnAfterClose() { } protected override void OnActived() { base.OnActived(); StartCoroutine(Co_FadeIn()); } public void FadeOut() { StartCoroutine(Co_FadeOut()); } IEnumerator Co_FadeIn() { var timer = 0f; while (timer < 0.5f) { timer += Time.deltaTime; m_CanvasGroup.alpha = Mathf.Clamp01(timer * 2f); yield return null; } m_CanvasGroup.alpha = 1f; } IEnumerator Co_FadeOut() { var timer = 0f; while (timer < 0.5f) { timer += Time.deltaTime; m_CanvasGroup.alpha = Mathf.Clamp01(1 - timer * 2f); yield return null; } m_CanvasGroup.alpha = 0f; WindowCenter.Instance.Close(); } #endregion void OnLoginError() { info.text = loginModel.loginErrorInfo; } } }