FriendView.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Friend;
  4. namespace GFGGame
  5. {
  6. public class FriendView : BaseView
  7. {
  8. private UI_FriendUI _ui;
  9. private GameObject _scenePrefab;
  10. private GameObject _sceneObject;
  11. public override void Dispose()
  12. {
  13. if (_sceneObject != null)
  14. {
  15. GameObject.Destroy(_sceneObject);
  16. _sceneObject = null;
  17. }
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void Init()
  26. {
  27. base.Init();
  28. packageName = UI_FriendUI.PACKAGE_NAME;
  29. _ui = UI_FriendUI.Create();
  30. viewCom = _ui.target;
  31. isfullScreen = true;
  32. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFriend"));
  33. _ui.m_list.SetVirtual();
  34. _ui.m_list.itemRenderer = RenderListItem;
  35. _ui.m_list.onClickItem.Add(OnListItemClick);
  36. }
  37. protected override void OnInit()
  38. {
  39. base.OnInit();
  40. _ui.m_btnBack.onClick.Add(OnHide);
  41. }
  42. protected override void AddEventListener()
  43. {
  44. base.AddEventListener();
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. UpdateList();
  50. CustomSuitData suitSavedData = CustomSuitDataManager.GetCurrentSuitList();
  51. // if (_ui.m_list.numItems > 0)
  52. // {
  53. // _ui.m_list.selectedIndex = 0;
  54. // suitSavedData = _ui.m_list.GetChildAt(0).asCom.data as CustomSuitData;
  55. // }
  56. UpdateScene(suitSavedData);
  57. }
  58. protected override void OnHide()
  59. {
  60. if (_sceneObject != null)
  61. {
  62. GameObject.Destroy(_sceneObject);
  63. _sceneObject = null;
  64. }
  65. ViewManager.GoBackFrom(typeof(FriendView).FullName);
  66. }
  67. protected override void RemoveEventListener()
  68. {
  69. base.RemoveEventListener();
  70. }
  71. private void UpdateList()
  72. {
  73. _ui.m_list.numItems = 20;
  74. }
  75. private void RenderListItem(int index, GObject obj)
  76. {
  77. UI_ListItem item = UI_ListItem.Proxy(obj);
  78. UI_ListItem.ProxyEnd();
  79. }
  80. private void OnListItemClick(EventContext context)
  81. {
  82. GObject item = context.data as GObject;
  83. CustomSuitData suitSavedData = item.data as CustomSuitData;
  84. UpdateScene(suitSavedData);
  85. }
  86. private void UpdateScene(CustomSuitData suitSavedData)
  87. {
  88. if (_sceneObject == null)
  89. {
  90. _sceneObject = GameObject.Instantiate(_scenePrefab);
  91. EquipDataCache.cacher.setSceneObj(_sceneObject);
  92. }
  93. EquipDataCache.cacher.PutOnSuitMemory(suitSavedData);
  94. }
  95. }
  96. }