123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using UI.FieldGuide;
- using FairyGUI;
- using UnityEngine;
- using System.Collections.Generic;
- namespace GFGGame
- {
- public class SuitShowView : BaseWindow
- {
- private UI_SuitShowUI _ui;
- private int _suitTypeId;
- private int _suitId;
- private GameObject _scenePrefab;
- private GameObject _sceneObject;
- private GoWrapper _wrapper;
- private DressUpObjDataCache _dressUpObjDataCache;
- private bool _actionIsPic;
- private List<int> _suitIds;
- public override void Dispose()
- {
- if (_scenePrefab != null)
- {
- GameObject.Destroy(_scenePrefab);
- _scenePrefab = null;
- }
- if (_dressUpObjDataCache != null)
- {
- _dressUpObjDataCache.Dispose();
- _dressUpObjDataCache = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- _ui = UI_SuitShowUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- this.clickBlankToClose = false;
- _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
- _dressUpObjDataCache = new DressUpObjDataCache();
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_imgBonusBox.target.onClick.Add(OnClickImgBonusBox);
- _ui.m_btnChangeAction.onClick.Add(OnClickBtnChangeAction);
- _ui.m_btnLeft.onClick.Add(OnClickBtnLeft);
- _ui.m_btnRight.onClick.Add(OnClickBtnRight);
- }
- protected override void OnShown()
- {
- base.OnShown();
- object[] datas = this.viewData as object[];
- _suitTypeId = (int)datas[0];
- _suitId = (int)datas[1];
- List<int> suitIds = datas[2] as List<int>;
- _suitIds = new List<int>();
- foreach (int suitId in suitIds)
- {
- if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId))
- {
- _suitIds.Add(suitId);
- }
- }
- SuitGuideMenuCfg cfg = SuitGuideMenuCfgArray.Instance.GetCfg(_suitTypeId);
- _ui.m_txtTypeName.text = cfg.name;
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjtj_bjbj");
- UpdateArrows();
- UpdateSuitView();
- UpdateSuitBoxStatus();
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
- }
- protected override void OnHide()
- {
- base.OnHide();
- if (_sceneObject != null)
- {
- GameObject.Destroy(_sceneObject);
- _sceneObject = null;
- }
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
- }
- private void OnClickBtnBack()
- {
- this.Hide();
- }
- private void OnClickImgBonusBox()
- {
- SuitUtil.ShowSuitGuideBonus(_suitId);
- }
- private void OnClickBtnChangeAction()
- {
- if (!_ui.m_btnChangeAction.grayed)
- {
- _actionIsPic = !_actionIsPic;
- UpdateSuitView(_actionIsPic);
- }
- }
- private void UpdateSuitView(bool isPic = true)
- {
- _actionIsPic = isPic;
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
- _ui.m_txtSuitName.text = suitCfg.name;
- if (_sceneObject != null)
- {
- GameObject.Destroy(_sceneObject);
- _sceneObject = null;
- }
- _sceneObject = GameObject.Instantiate(_scenePrefab);
- int scale = 100;
- _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
- _dressUpObjDataCache.setSceneObj(_sceneObject);
- _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
- _dressUpObjDataCache.PutOnSuitCfg(_suitId, isPic, false, new int[] { ConstDressUpItemType.BEI_JING });
- if (_wrapper == null)
- {
- _wrapper = new GoWrapper(_sceneObject);
- _ui.m_holder.SetNativeObject(_wrapper);
- }
- else
- {
- _wrapper.wrapTarget = _sceneObject;
- }
- _ui.m_btnChangeAction.grayed = !_dressUpObjDataCache.HasSuitPicRes;
- UpdateSuitBoxStatus();
- }
- private void UpdateArrows()
- {
- int index = _suitIds.IndexOf(_suitId);
- int count = _suitIds.Count;
- _ui.m_btnRight.visible = (index + 1 < count);
- _ui.m_btnLeft.visible = (index - 1 >= 0);
- }
- private void OnClickBtnLeft()
- {
- int index = _suitIds.IndexOf(_suitId);
- int targetIndex = index - 1;
- if (targetIndex >= 0)
- {
- _suitId = _suitIds[targetIndex];
- UpdateArrows();
- UpdateSuitView();
- }
- UpdateSuitBoxStatus();
- }
- private void OnClickBtnRight()
- {
- int index = _suitIds.IndexOf(_suitId);
- int targetIndex = index + 1;
- if (targetIndex < _suitIds.Count)
- {
- _suitId = _suitIds[targetIndex];
- UpdateArrows();
- UpdateSuitView();
- }
- UpdateSuitBoxStatus();
- }
- private void UpdateSuitBoxStatus(EventContext eventContext = null)
- {
- if (eventContext == null || _suitId == (int)eventContext.data)
- {
- int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(_suitId);
- RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, false);
- RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, status == ConstBonusStatus.CAN_GET);
- if (status == ConstBonusStatus.CAN_GET)
- {
- _ui.m_imgBonusBox.m_c1.selectedIndex = 1;
- }
- else
- {
- _ui.m_imgBonusBox.m_c1.selectedIndex = 0;
- }
- }
- }
- }
- }
|