FacilityUIPowerUpList.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class FacilityUIPowerUpList : MonoBehaviour
  6. {
  7. public void Show(Facility facility, Action<Facility.PowerUpRecipe> callbackSelect)
  8. {
  9. this.SetupFacilityPowerUpListButton(facility, callbackSelect);
  10. }
  11. private void SetupFacilityPowerUpListButton(Facility facility, Action<Facility.PowerUpRecipe> callbackSelect)
  12. {
  13. this.m_uGUIListViewer.parentItemArea.gameObject.SetActive(true);
  14. int[] powerUpRecipeIDArray = new int[0];
  15. if (FacilityDataTable.IsExistFacilityPowerUpRecipe(facility.param.typeID, true))
  16. {
  17. powerUpRecipeIDArray = FacilityDataTable.GetFacilityPowerUpRecipeIDArray(facility.param.typeID, true);
  18. }
  19. this.m_uGUIListViewer.Show<Transform>(powerUpRecipeIDArray.Length, delegate(int i, Transform trans)
  20. {
  21. Facility.PowerUpRecipe powerUpRecipe = FacilityDataTable.GetFacilityPowerUpRecipe(powerUpRecipeIDArray[i]);
  22. Toggle componentInChildren = trans.GetComponentInChildren<Toggle>();
  23. Text componentInChildren2 = trans.GetComponentInChildren<Text>();
  24. componentInChildren2.text = powerUpRecipe.name;
  25. componentInChildren.onValueChanged.RemoveAllListeners();
  26. componentInChildren.onValueChanged.AddListener(delegate(bool isOn)
  27. {
  28. if (!isOn)
  29. {
  30. return;
  31. }
  32. if (callbackSelect != null)
  33. {
  34. callbackSelect(powerUpRecipe);
  35. }
  36. this.UpdateConditionsText(powerUpRecipe.id);
  37. });
  38. });
  39. if (powerUpRecipeIDArray.Length <= 0)
  40. {
  41. this.m_uGUIListViewer.Show<Transform>(1, delegate(int i, Transform trans)
  42. {
  43. Toggle componentInChildren = trans.GetComponentInChildren<Toggle>();
  44. Text componentInChildren2 = trans.GetComponentInChildren<Text>();
  45. componentInChildren.enabled = false;
  46. componentInChildren2.text = "レシピは存在しません。";
  47. });
  48. }
  49. this.m_uGUIListConditions.ResetList();
  50. }
  51. private void UpdateConditionsText(int recipeID)
  52. {
  53. FacilityDataTable.FacilityRecipeData facilityRecipeData = FacilityDataTable.GetFacilityRecipeData(recipeID);
  54. if (facilityRecipeData == null)
  55. {
  56. this.m_uGUIListConditions.ResetList();
  57. return;
  58. }
  59. string[] conditions = facilityRecipeData.conditions;
  60. List<string> strConditionsList = new List<string>();
  61. for (int j = 0; j < conditions.Length; j++)
  62. {
  63. if (!string.IsNullOrEmpty(conditions[j]))
  64. {
  65. strConditionsList.Add(conditions[j]);
  66. }
  67. }
  68. this.m_uGUIListConditions.Show<RectTransform>(strConditionsList.Count, delegate(int i, RectTransform trans)
  69. {
  70. string text = strConditionsList[i];
  71. Text[] componentsInChildren = trans.GetComponentsInChildren<Text>();
  72. componentsInChildren[0].text = (i + 1).ToString();
  73. componentsInChildren[1].text = text;
  74. Image componentInChildren = trans.GetComponentInChildren<Image>();
  75. componentInChildren.enabled = (i % 2 != 0);
  76. });
  77. }
  78. public void Hide()
  79. {
  80. this.m_uGUIListViewer.parentItemArea.gameObject.SetActive(false);
  81. }
  82. [SerializeField]
  83. private uGUIListViewer m_uGUIListViewer;
  84. [SerializeField]
  85. private uGUIListViewer m_uGUIListConditions;
  86. }