VRCultivationSeedInventory.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. public class VRCultivationSeedInventory : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. for (int i = 0; i < this.m_UIButtonPlantSeeds.Length; i++)
  10. {
  11. Button button = this.m_UIButtonPlantSeeds[i];
  12. button.onClick.AddListener(delegate
  13. {
  14. this.ButtonEvent_Selected(button);
  15. if (this.m_OnEventButtonSelected != null)
  16. {
  17. this.m_OnEventButtonSelected();
  18. }
  19. });
  20. }
  21. if (this.m_ButtonReturn)
  22. {
  23. this.m_ButtonReturn.onClick.AddListener(this.m_OnEventButtonClosed);
  24. }
  25. this.Refresh();
  26. }
  27. private void ButtonEvent_Selected(Button data)
  28. {
  29. Farm_Mng instance = Farm_Mng.Instance;
  30. if (!instance)
  31. {
  32. return;
  33. }
  34. Farm_Mng.Plant_List seedType = this.GetSeedType(data.GetComponentInChildren<Text>().text);
  35. instance.NyuShoku(seedType);
  36. VRCanvasManager.Instance.ClearCanvasStack();
  37. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  38. }
  39. private void SetButtonEnabled(Button button, bool b)
  40. {
  41. button.interactable = b;
  42. }
  43. private void Refresh()
  44. {
  45. string text = "vrcom_culture.nei";
  46. if (!GameUty.FileSystem.IsExistentFile(text))
  47. {
  48. NDebug.Assert("表がありません。" + text, false);
  49. }
  50. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  51. {
  52. using (CsvParser csvParser = new CsvParser())
  53. {
  54. bool condition = csvParser.Open(afileBase);
  55. NDebug.Assert(condition, text + "\nopen failed.");
  56. for (int i = 1; i < csvParser.max_cell_y; i++)
  57. {
  58. if (csvParser.IsCellToExistData(0, i))
  59. {
  60. int num = 0;
  61. string cellAsString = csvParser.GetCellAsString(num++, i);
  62. string cellAsString2 = csvParser.GetCellAsString(num++, i);
  63. bool b = false;
  64. if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
  65. {
  66. b = (GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(cellAsString2) >= 1);
  67. }
  68. Button seedButton = this.GetSeedButton(cellAsString);
  69. this.SetButtonEnabled(seedButton, b);
  70. }
  71. }
  72. }
  73. }
  74. }
  75. private Button GetSeedButton(string seedName)
  76. {
  77. for (int i = 0; i < this.m_UIButtonPlantSeeds.Length; i++)
  78. {
  79. Button button = this.m_UIButtonPlantSeeds[i];
  80. Text componentInChildren = button.GetComponentInChildren<Text>();
  81. if (string.Equals(componentInChildren.text, seedName))
  82. {
  83. return button;
  84. }
  85. }
  86. Debug.LogWarning("[畑の種]植物「" + seedName + "」は存在しない");
  87. return null;
  88. }
  89. private Farm_Mng.Plant_List GetSeedType(string eventName)
  90. {
  91. if (eventName.Equals("にんじん"))
  92. {
  93. return Farm_Mng.Plant_List.Ninjin;
  94. }
  95. if (eventName.Equals("とうもろこし"))
  96. {
  97. return Farm_Mng.Plant_List.Toumorokosi;
  98. }
  99. if (eventName.Equals("とまと"))
  100. {
  101. return Farm_Mng.Plant_List.Tomato;
  102. }
  103. if (eventName.Equals("すいか"))
  104. {
  105. return Farm_Mng.Plant_List.Suika;
  106. }
  107. if (eventName.Equals("ひまわり"))
  108. {
  109. return Farm_Mng.Plant_List.Himawari;
  110. }
  111. if (eventName.Equals("ざくろ"))
  112. {
  113. return Farm_Mng.Plant_List.Zakuro;
  114. }
  115. if (eventName.Equals("夏みかん"))
  116. {
  117. return Farm_Mng.Plant_List.Natumikan;
  118. }
  119. if (eventName.Equals("さつまいも"))
  120. {
  121. return Farm_Mng.Plant_List.Satumaimo;
  122. }
  123. return Farm_Mng.Plant_List.Nothing;
  124. }
  125. private void OnEnable()
  126. {
  127. this.Refresh();
  128. }
  129. [SerializeField]
  130. [Tooltip("種のボタンUI")]
  131. private Button[] m_UIButtonPlantSeeds;
  132. [SerializeField]
  133. [Tooltip("閉じるボタン")]
  134. private Button m_ButtonReturn;
  135. [HideInInspector]
  136. public UnityAction m_OnEventButtonSelected;
  137. [HideInInspector]
  138. public UnityAction m_OnEventButtonClosed;
  139. }