BgIconWindow.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. namespace SceneEditWindow
  6. {
  7. [AddComponentMenu("SceneEditWindow/BgIconWindow")]
  8. public class BgIconWindow : BaseIconWindow
  9. {
  10. public int selectedIconId { get; private set; }
  11. public override string windowName
  12. {
  13. get
  14. {
  15. return "BgIconWindow";
  16. }
  17. }
  18. public override void Awake()
  19. {
  20. BgIconData.Create();
  21. base.Awake();
  22. }
  23. protected virtual void OnDestroy()
  24. {
  25. foreach (KeyValuePair<int, Texture> keyValuePair in this.texDic)
  26. {
  27. UnityEngine.Object.DestroyImmediate(keyValuePair.Value);
  28. }
  29. this.texDic.Clear();
  30. }
  31. public void Exec(int bgId)
  32. {
  33. if (!this.tabButtonDic.ContainsKey(bgId))
  34. {
  35. Debug.LogError("背景番号[" + bgId.ToString() + "]の背景が見つかりませんでした");
  36. return;
  37. }
  38. this.tabPanel.Select(this.tabButtonDic[bgId]);
  39. }
  40. public void NextBG()
  41. {
  42. if (this.createItemList.Count <= 1)
  43. {
  44. return;
  45. }
  46. int num = int.MinValue;
  47. for (int i = 0; i < this.createItemList.Count; i++)
  48. {
  49. if (this.createItemList[i].id == this.selectedIconId)
  50. {
  51. num = this.createItemList[0].id;
  52. if (i + 1 < this.createItemList.Count)
  53. {
  54. num = this.createItemList[i + 1].id;
  55. }
  56. break;
  57. }
  58. }
  59. if (num != -2147483648)
  60. {
  61. this.Exec(num);
  62. }
  63. }
  64. public void PrevBG()
  65. {
  66. if (this.createItemList.Count <= 1)
  67. {
  68. return;
  69. }
  70. int num = int.MinValue;
  71. for (int i = 0; i < this.createItemList.Count; i++)
  72. {
  73. if (this.createItemList[i].id == this.selectedIconId)
  74. {
  75. num = this.createItemList[this.createItemList.Count - 1].id;
  76. if (0 <= i - 1)
  77. {
  78. num = this.createItemList[i - 1].id;
  79. }
  80. break;
  81. }
  82. }
  83. if (num != -2147483648)
  84. {
  85. this.Exec(num);
  86. }
  87. }
  88. protected override void OnSelectItem(int selectItemId)
  89. {
  90. BgIconData.ItemData itemData = BgIconData.GetItemData(selectItemId);
  91. this.selectedIconId = itemData.id;
  92. if (this.onSelectBgEvent != null)
  93. {
  94. this.onSelectBgEvent(itemData);
  95. }
  96. }
  97. protected override UIWFTabButton CreateItemObject(GameObject parent, int createItemId)
  98. {
  99. GameObject gameObject = Utility.CreatePrefab(parent, "SceneEdit/WindowParts/PoseIconItem", true);
  100. if (!this.texDic.ContainsKey(createItemId))
  101. {
  102. this.texDic.Add(createItemId, ImportCM.CreateTexture(BgIconData.GetItemData(createItemId).iconTexName));
  103. }
  104. UITexture component = gameObject.GetComponent<UITexture>();
  105. component.mainTexture = this.texDic[createItemId];
  106. this.createItemList.Add(BgIconData.GetItemData(createItemId));
  107. return gameObject.GetComponent<UIWFTabButton>();
  108. }
  109. protected override List<int> CreateItemIdList()
  110. {
  111. List<int> list = new List<int>();
  112. foreach (BgIconData.ItemData itemData in BgIconData.itemList)
  113. {
  114. if (!SceneEdit.compatibilityMode || itemData.isLegacyBG)
  115. {
  116. if (SceneEdit.compatibilityMode || !itemData.isLegacyBG)
  117. {
  118. if (itemData.enabled)
  119. {
  120. list.Add(itemData.id);
  121. }
  122. }
  123. }
  124. }
  125. return list;
  126. }
  127. public Action<BgIconData.ItemData> onSelectBgEvent;
  128. private Dictionary<int, Texture> texDic = new Dictionary<int, Texture>();
  129. private List<BgIconData.ItemData> createItemList = new List<BgIconData.ItemData>();
  130. }
  131. }