//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, April 22, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class TreasureChapterWin : Window { [SerializeField] RawImage m_GaussianMask; [SerializeField] UIAlphaTween m_AlphaTween; [SerializeField] Text m_ChapterName; [SerializeField] Image m_ChapterIcon; [SerializeField] Image m_TreasureIcon; [SerializeField] Text m_Description; [SerializeField] Text m_CloseRemind; [SerializeField] Transform m_ContainerFly; [SerializeField] Button m_Close; [SerializeField] float m_AutoCloseSeconds = 10f; float timer = 0f; float perSecond = 0f; bool flying = false; FunctionUnlockFlyObject flyObject = null; public static int displayId = 0; TreasureModel model { get { return ModelCenter.Instance.GetModel(); } } TaskModel taskModel { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Close.AddListener(OnClickClose); } protected override void OnPreOpen() { if (flyObject != null) { Destroy(flyObject); flyObject = null; } timer = 0f; perSecond = 0f; flying = false; m_GaussianMask.gameObject.SetActive(false); m_AlphaTween.from = 0f; m_AlphaTween.to = 1f; m_AlphaTween.SetStartState(); PlayerDatas.Instance.hero.StopAll(); Display(); DisplayTimer(); } protected override void OnActived() { base.OnActived(); CameraUtility.ScreenShotCut(m_GaussianMask, DoPrepare, true); } protected override void OnAfterOpen() { } protected override void OnPreClose() { model.treasureChapterId = 0; } protected override void OnAfterClose() { taskModel.AutomaticTripToTask(taskModel.currentMission); } protected override void LateUpdate() { perSecond += Time.deltaTime; if (perSecond >= 0.5f) { DisplayTimer(); perSecond = 0f; } timer += Time.deltaTime; if (timer >= m_AutoCloseSeconds && !flying) { OnClickClose(); } } #endregion private void DoPrepare() { m_GaussianMask.gameObject.SetActive(true); m_AlphaTween.Play(); } void Display() { var instance = UIUtility.CreateWidget("TreasureChapterFlyObject", "TreasureChapterFlyObject"); instance.transform.SetParentEx(m_ContainerFly, Vector3.zero, Quaternion.identity, Vector3.one); flyObject = instance.GetComponent(); flyObject.SetContent(FunctionUnlockType.TreasureChapter, model.treasureChapterId); flyObject.SetSpeed(6f); flyObject.gameObject.SetActive(true); var config = TreasureConfig.Get(model.treasureChapterId); if (config != null) { m_TreasureIcon.SetSprite(config.Icon); } var chapterConfig = TreasureChapterConfig.Get(model.treasureChapterId); if (chapterConfig != null) { m_ChapterIcon.SetSprite(chapterConfig.taskTitle); m_ChapterName.text = Language.Get("TreasureChapterName", Language.Get("Num_CHS_" + chapterConfig.chapterIndex)); m_Description.text = UIHelper.ReplaceNewLine(chapterConfig.description); } } void DisplayTimer() { m_CloseRemind.text = Language.Get("AutoCloseAfterSeconds", m_AutoCloseSeconds - (int)timer); } private void OnClickClose() { if (timer < 2f || flying) { return; } m_GaussianMask.gameObject.SetActive(false); flying = true; m_AlphaTween.from = 1f; m_AlphaTween.to = 0f; m_AlphaTween.Play(OnTweenComplete); } private void OnTweenComplete() { if (flyObject != null) { flyObject.Begin(OnReach); } } private void OnReach() { CloseClick(); } } }