//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, May 04, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TableConfig; namespace Snxxz.UI { public class TreasureStageUpTriggerWin : Window { [SerializeField] RawImage m_RawScreenShot; [SerializeField] UIAlphaTween m_AlphaTween; [SerializeField] RectTransform m_FlyContainer; [SerializeField] RectTransform m_FurnacesFlyContainer; [SerializeField] Vector2 m_SkillPosition; [SerializeField] float m_FurnacesScale = 8f; FunctionUnlockFlyObject flyObject; public static Texture2D screenShotCut = null; TreasureModel m_Model; TreasureModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel()); } } Treasure m_Treasure; bool flying = false; float timer = 0f; #region Built-in protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { flying = false; timer = 0f; m_AlphaTween.SetStartState(); m_RawScreenShot.gameObject.SetActive(screenShotCut != null); if (screenShotCut != null) { m_RawScreenShot.texture = screenShotCut; } model.treasureStageUpShow = true; var mapId = PlayerDatas.Instance.baseData.MapID; var mapConfig = Config.Instance.Get(mapId); if (mapConfig == null || mapConfig.MapFBType == 0) { PlayerDatas.Instance.hero.Behaviour.StopHandupAI(); MapTransferUtility.Instance.Clear(); PlayerDatas.Instance.hero.StopPathFind(); } } protected override void OnActived() { base.OnActived(); StartCoroutine(Co_DelayShow()); } protected override void OnAfterOpen() { } IEnumerator Co_DelayShow() { yield return null; DoPrepare(); } protected override void OnPreClose() { model.treasureStageUpShow = false; if (screenShotCut != null) { CameraUtility.StopShotCut(screenShotCut); screenShotCut = null; } } protected override void OnAfterClose() { } protected override void LateUpdate() { base.LateUpdate(); if (flying) { timer += Time.deltaTime; if (timer > 5f) { CloseImmediately(); } } } #endregion void DoPrepare() { model.TryGetTreasure(model.selectedTreasure, out m_Treasure); if (m_Treasure.id == 301) { OnFurnacesTreasure(); return; } var _stage = m_Treasure.treasureStages.Find((x) => { return x.stage == m_Treasure.stage; }); if (_stage == null) { CloseImmediately(); return; } var instance = UIUtility.CreateWidget(_stage.unlockType == TreasureStageUnlock.Skill ?"TreasureStageSkillFlyObject": "TreasureStageFuncFlyObject", "TreasureStageFlyObject"); instance.transform.SetParentEx(m_FlyContainer, Vector3.zero, Quaternion.identity, Vector3.one); var _index = _stage.stage; _index = m_Treasure.GetStageIndex(_index); var _config = ScriptableObjectLoader.LoadSoTreasureMeridian(model.selectedTreasure); if (_config != null) { instance.transform.localPosition = _stage.unlockType == TreasureStageUnlock.Skill ? m_SkillPosition : _config[_index].position; } flyObject = instance.GetComponent(); switch (_stage.unlockType) { case TreasureStageUnlock.Skill: flyObject.SetContent(FunctionUnlockType.TreasureSkill, m_Treasure.id); flyObject.SetSpeed(6.0f); break; case TreasureStageUnlock.Func: flyObject.SetContent(FunctionUnlockType.Normal, _stage.func); flyObject.SetSpeed(3.0f); break; } if (screenShotCut != null) { m_AlphaTween.Play(OnAlphaComplete); } else { m_AlphaTween.SetEndState(); flyObject.Begin(OnReach); } } void OnFurnacesTreasure() { var instance = UIUtility.CreateWidget("TreasureUnlockFlyObject_1", "TreasureUnlockFlyObject_1"); instance.transform.SetParentEx(m_FurnacesFlyContainer, Vector3.zero, Quaternion.identity, Vector3.one); flyObject = instance.GetComponent(); flyObject.SetContent(FunctionUnlockType.TreasureFunc, 301); flyObject.transform.localScale = Vector3.one * m_FurnacesScale; flyObject.SetScale(m_FurnacesScale); if (screenShotCut != null) { m_AlphaTween.Play(OnAlphaComplete); } else { m_AlphaTween.SetEndState(); flyObject.Begin(OnReach); } } private void OnAlphaComplete() { flying = true; flyObject.Begin(OnReach); } private void OnReach() { if (m_Treasure.id == 301) { NewBieCenter.Instance.StartNewBieGuide(33); CloseImmediately(); return; } var _stage = m_Treasure.treasureStages.Find((x) => { return x.stage == m_Treasure.stage; }); switch (_stage.unlockType) { case TreasureStageUnlock.Func: var funcConfig = Config.Instance.Get(_stage.func); if (funcConfig != null) { if ((FuncOpenEnum)funcConfig.FuncId == FuncOpenEnum.Strength) { NewBieCenter.Instance.StartNewBieGuide(10); } else if((FuncOpenEnum)funcConfig.FuncId == FuncOpenEnum.Mounts) { NewBieCenter.Instance.StartNewBieGuide(19); } else if ((FuncOpenEnum)funcConfig.FuncId == FuncOpenEnum.Pet) { NewBieCenter.Instance.StartNewBieGuide(23); } else if ((FuncOpenEnum)funcConfig.FuncId == FuncOpenEnum.Rune) { NewBieCenter.Instance.StartNewBieGuide(27); } } break; case TreasureStageUnlock.Skill: switch (m_Treasure.id) { case 104: SnxxzGame.Instance.StartCoroutine(Co_SkillGuide()); return; case 105: NewBieCenter.Instance.StartNewBieGuide(49); break; } break; } CloseImmediately(); } IEnumerator Co_SkillGuide() { yield return WaitingForSecondConst.WaitMS500; var _skillModel = ModelCenter.Instance.GetModel(); if (!_skillModel.AutoUseXp()) { ModelCenter.Instance.GetModel().FunctionButton(); NewBieCenter.Instance.StartNewBieGuide(34); } CloseImmediately(); } } }