123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using UnityEngine;
- using FairyGUI;
- using UI.Friend;
- namespace GFGGame
- {
- public class FriendView : BaseView
- {
- private UI_FriendUI _ui;
- private GameObject _scenePrefab;
- private GameObject _sceneObject;
- public override void Dispose()
- {
- if (_sceneObject != null)
- {
- GameObject.Destroy(_sceneObject);
- _sceneObject = null;
- }
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void Init()
- {
- base.Init();
- packageName = UI_FriendUI.PACKAGE_NAME;
- _ui = UI_FriendUI.Create();
- viewCom = _ui.target;
- isfullScreen = true;
- _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFriend"));
- _ui.m_list.SetVirtual();
- _ui.m_list.itemRenderer = RenderListItem;
- _ui.m_list.onClickItem.Add(OnListItemClick);
- }
- protected override void OnInit()
- {
- base.OnInit();
- _ui.m_btnBack.onClick.Add(OnHide);
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateList();
- CustomSuitData suitSavedData = CustomSuitDataManager.GetCurrentSuitList();
- // if (_ui.m_list.numItems > 0)
- // {
- // _ui.m_list.selectedIndex = 0;
- // suitSavedData = _ui.m_list.GetChildAt(0).asCom.data as CustomSuitData;
- // }
- UpdateScene(suitSavedData);
- }
- protected override void OnHide()
- {
- if (_sceneObject != null)
- {
- GameObject.Destroy(_sceneObject);
- _sceneObject = null;
- }
- ViewManager.GoBackFrom(typeof(FriendView).FullName);
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- }
- private void UpdateList()
- {
- _ui.m_list.numItems = 20;
- }
- private void RenderListItem(int index, GObject obj)
- {
- UI_ListItem item = UI_ListItem.Proxy(obj);
- UI_ListItem.ProxyEnd();
- }
- private void OnListItemClick(EventContext context)
- {
- GObject item = context.data as GObject;
- CustomSuitData suitSavedData = item.data as CustomSuitData;
- UpdateScene(suitSavedData);
- }
- private void UpdateScene(CustomSuitData suitSavedData)
- {
- if (_sceneObject == null)
- {
- _sceneObject = GameObject.Instantiate(_scenePrefab);
- EquipDataCache.cacher.setSceneObj(_sceneObject);
- }
- EquipDataCache.cacher.PutOnSuitMemory(suitSavedData);
- }
- }
- }
|