UAVPanel.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class UAVPanel : PopUpPanel
  6. {
  7. public Transform equipContainer;
  8. public EquipIcon equipItemPrefab;
  9. public EquipInfo equipInfo;
  10. private EquipedData equipedData;
  11. void Awake()
  12. {
  13. ListHelper.HideAll (equipContainer);
  14. equipItemPrefab.uavPanel = this;
  15. equipInfo.uavPanel = this;
  16. Shown ();
  17. }
  18. protected override void Shown ()
  19. {
  20. EquipManager.GetInstance ().InventoryUpdate.AddListener (OnInventoryUpdate);
  21. EquipManager.GetInstance ().RequestInventory ();
  22. }
  23. private void OnInventoryUpdate()
  24. {
  25. EquipManager.GetInstance ().InventoryUpdate.RemoveListener (OnInventoryUpdate);
  26. List<Equipment> list = UAVManager.GetInstance ().GetInventoryList ();
  27. ListHelper.FillList<Equipment> (equipContainer, list, equipItemPrefab);
  28. if (list.Count > 0)
  29. SelectEquip (equipItemPrefab);
  30. else
  31. SelectEquip (null);
  32. }
  33. public void SelectEquip(EquipIcon icon)
  34. {
  35. ButtonUtil.TabSelected (icon, equipContainer);
  36. if (icon != null) {
  37. ShowEquipInfo (icon.data as Equipment);
  38. } else {
  39. ShowEquipInfo (null);
  40. }
  41. }
  42. private void ShowEquipInfo(Equipment equipment)
  43. {
  44. equipInfo.SetEquip (equipment);
  45. }
  46. public void Equip(Equipment equip)
  47. {
  48. UAVItem uavItem = UAVManager.GetInstance ().GetUAVItem (equip.GetData ().id);
  49. UAVManager.GetInstance ().SetEquipedItem (uavItem);
  50. List<Equipment> list = UAVManager.GetInstance ().GetInventoryList ();
  51. ListHelper.FillList<Equipment> (equipContainer, list, equipItemPrefab);
  52. ShowEquipInfo (equip);
  53. }
  54. public bool IsEquiped(Equipment equip)
  55. {
  56. UAVItem uavItem = UAVManager.GetInstance ().GetEquipedItem ();
  57. if(uavItem != null && uavItem.GetEquipment () == equip)
  58. return true;
  59. return false;
  60. }
  61. private static UAVPanel currentPanel;
  62. public static UAVPanel Show()
  63. {
  64. if (currentPanel != null) {
  65. currentPanel.gameObject.SetActive (true);
  66. PopUpManager.AddToMainCanvas (currentPanel.gameObject);
  67. }
  68. else
  69. currentPanel = PopUpManager.AddPopUp<UAVPanel> (Resources.Load<GameObject> ("Prefabs/UI/UAVPanel/UAVPanel"), null, true);
  70. currentPanel.Open ();
  71. return currentPanel;
  72. }
  73. }