FacilityUIPowerUpMaterialList.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. public class FacilityUIPowerUpMaterialList : MonoBehaviour
  6. {
  7. private FacilityManager FacilityMgr
  8. {
  9. get
  10. {
  11. if (this.m_FacilityMgr == null)
  12. {
  13. this.m_FacilityMgr = GameMain.Instance.FacilityMgr;
  14. }
  15. return this.m_FacilityMgr;
  16. }
  17. }
  18. public void Show(int id, Facility facility, Action<int[]> callbackSelect)
  19. {
  20. this.m_CallbackSelect = callbackSelect;
  21. this.SetupFacilityPowerUpMaterialListDropDown(id, facility);
  22. }
  23. private void SetupFacilityPowerUpMaterialListDropDown(int id, Facility facility)
  24. {
  25. this.m_uGUIListViewer.parentItemArea.gameObject.SetActive(true);
  26. this.DeleteDropdown();
  27. Facility.PowerUpRecipe facilityPowerUpRecipe = FacilityDataTable.GetFacilityPowerUpRecipe(id);
  28. int[] materialCategoryIDArray = facilityPowerUpRecipe.materialCategoryIDArray;
  29. Facility.RecipeData recipeData = facility.GetRecipeData(id);
  30. this.m_uGUIListViewer.Show<Transform>(materialCategoryIDArray.Length, delegate(int i, Transform trans)
  31. {
  32. int num = materialCategoryIDArray[i];
  33. Dropdown componentInChildren = trans.GetComponentInChildren<Dropdown>();
  34. Text[] componentsInChildren = trans.GetComponentsInChildren<Text>();
  35. FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial dropdownPowerUpMaterial = trans.gameObject.AddComponent<FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial>();
  36. string facilityPowerUpMaterialCategoryName = FacilityDataTable.GetFacilityPowerUpMaterialCategoryName(num);
  37. componentsInChildren[0].text = facilityPowerUpMaterialCategoryName;
  38. componentsInChildren[1].text = string.Format("CATEGORY{0}", i + 1);
  39. componentInChildren.ClearOptions();
  40. Facility.PowerUpMaterial[] materialArray = this.FacilityMgr.GetFacilityPowerUpItemEnableArray(num);
  41. if (materialArray.Length > 0)
  42. {
  43. for (int j = 0; j < materialArray.Length; j++)
  44. {
  45. componentInChildren.options.Add(new Dropdown.OptionData(materialArray[j].name));
  46. if (recipeData.materialIDArray[i] == materialArray[j].id)
  47. {
  48. dropdownPowerUpMaterial.materialID = materialArray[j].id;
  49. componentInChildren.value = j;
  50. }
  51. }
  52. }
  53. else
  54. {
  55. componentInChildren.image.raycastTarget = false;
  56. dropdownPowerUpMaterial.materialID = 0;
  57. componentInChildren.options.Add(new Dropdown.OptionData("無し"));
  58. }
  59. if (dropdownPowerUpMaterial.materialID == 0)
  60. {
  61. if (materialArray.Length > 0)
  62. {
  63. dropdownPowerUpMaterial.materialID = materialArray[0].id;
  64. componentInChildren.value = 0;
  65. }
  66. else
  67. {
  68. dropdownPowerUpMaterial.materialID = -1;
  69. }
  70. }
  71. componentInChildren.RefreshShownValue();
  72. componentInChildren.onValueChanged.AddListener(delegate(int value)
  73. {
  74. dropdownPowerUpMaterial.materialID = materialArray[value].id;
  75. this.OnUpdateDropdownParams();
  76. });
  77. if (i == 0)
  78. {
  79. Transform transform = dropdownPowerUpMaterial.transform.Find("Image Plus Mark");
  80. if (transform)
  81. {
  82. transform.gameObject.SetActive(false);
  83. }
  84. else
  85. {
  86. Debug.LogError("[FacilityPowerUP]プラスマークのイメージが見つかりません\n「Image Plus Mark」という名前の子オブジェクトを追加してください");
  87. }
  88. }
  89. });
  90. this.OnUpdateDropdownParams();
  91. }
  92. public void HideAllDropdown()
  93. {
  94. Transform transform = this.m_uGUIListViewer.transform;
  95. Dropdown[] componentsInChildren = transform.GetComponentsInChildren<Dropdown>();
  96. for (int i = 0; i < componentsInChildren.Length; i++)
  97. {
  98. componentsInChildren[i].Hide();
  99. }
  100. }
  101. public void DeleteDropdown()
  102. {
  103. this.HideAllDropdown();
  104. this.m_uGUIListViewer.ResetList();
  105. }
  106. private void OnUpdateDropdownParams()
  107. {
  108. Transform transform = this.m_uGUIListViewer.transform;
  109. FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial[] componentsInChildren = transform.GetComponentsInChildren<FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial>();
  110. int[] array = new int[componentsInChildren.Length];
  111. for (int i = 0; i < componentsInChildren.Length; i++)
  112. {
  113. array[i] = componentsInChildren[i].materialID;
  114. }
  115. if (this.m_CallbackSelect != null)
  116. {
  117. this.m_CallbackSelect(array);
  118. }
  119. }
  120. private FacilityManager m_FacilityMgr;
  121. [SerializeField]
  122. private uGUIListViewer m_uGUIListViewer;
  123. private Action<int[]> m_CallbackSelect;
  124. private class DropdownPowerUpMaterial : MonoBehaviour, IPointerClickHandler, ISubmitHandler, IEventSystemHandler
  125. {
  126. private void SetupTemplateCanvas()
  127. {
  128. Dropdown component = base.GetComponent<Dropdown>();
  129. Transform transform = component.transform.Find("Dropdown List");
  130. if (!transform)
  131. {
  132. return;
  133. }
  134. Canvas component2 = transform.GetComponent<Canvas>();
  135. Canvas componentInParent = component.GetComponentInParent<Canvas>();
  136. component2.sortingOrder = componentInParent.sortingOrder + 50;
  137. }
  138. private void SetupBlockerCanvas()
  139. {
  140. Dropdown component = base.GetComponent<Dropdown>();
  141. Canvas componentInParent = component.GetComponentInParent<Canvas>();
  142. Transform transform = componentInParent.transform.Find("Blocker");
  143. if (!transform)
  144. {
  145. return;
  146. }
  147. Canvas component2 = transform.GetComponent<Canvas>();
  148. component2.sortingOrder = componentInParent.sortingOrder + 1;
  149. CanvasGroup canvasGroup = transform.gameObject.GetComponent<CanvasGroup>();
  150. if (!canvasGroup)
  151. {
  152. canvasGroup = transform.gameObject.AddComponent<CanvasGroup>();
  153. }
  154. canvasGroup.ignoreParentGroups = true;
  155. canvasGroup.interactable = true;
  156. canvasGroup.blocksRaycasts = true;
  157. }
  158. public void OnPointerClick(PointerEventData data)
  159. {
  160. this.SetupTemplateCanvas();
  161. this.SetupBlockerCanvas();
  162. }
  163. public void OnSubmit(BaseEventData data)
  164. {
  165. this.SetupTemplateCanvas();
  166. this.SetupBlockerCanvas();
  167. }
  168. public int materialID;
  169. }
  170. }