123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- public class VRCultivationSeedInventory : MonoBehaviour
- {
- private void Start()
- {
- for (int i = 0; i < this.m_UIButtonPlantSeeds.Length; i++)
- {
- Button button = this.m_UIButtonPlantSeeds[i];
- button.onClick.AddListener(delegate
- {
- this.ButtonEvent_Selected(button);
- if (this.m_OnEventButtonSelected != null)
- {
- this.m_OnEventButtonSelected();
- }
- });
- }
- if (this.m_ButtonReturn)
- {
- this.m_ButtonReturn.onClick.AddListener(this.m_OnEventButtonClosed);
- }
- this.Refresh();
- }
- private void ButtonEvent_Selected(Button data)
- {
- Farm_Mng instance = Farm_Mng.Instance;
- if (!instance)
- {
- return;
- }
- Farm_Mng.Plant_List seedType = this.GetSeedType(data.GetComponentInChildren<Text>().text);
- instance.NyuShoku(seedType);
- VRCanvasManager.Instance.ClearCanvasStack();
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
- }
- private void SetButtonEnabled(Button button, bool b)
- {
- button.interactable = b;
- }
- private void Refresh()
- {
- string text = "vrcom_culture.nei";
- if (!GameUty.FileSystem.IsExistentFile(text))
- {
- NDebug.Assert("表がありません。" + text, false);
- }
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, text + "\nopen failed.");
- for (int i = 1; i < csvParser.max_cell_y; i++)
- {
- if (csvParser.IsCellToExistData(0, i))
- {
- int num = 0;
- string cellAsString = csvParser.GetCellAsString(num++, i);
- string cellAsString2 = csvParser.GetCellAsString(num++, i);
- bool b = false;
- if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
- {
- b = (GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(cellAsString2) >= 1);
- }
- Button seedButton = this.GetSeedButton(cellAsString);
- this.SetButtonEnabled(seedButton, b);
- }
- }
- }
- }
- }
- private Button GetSeedButton(string seedName)
- {
- for (int i = 0; i < this.m_UIButtonPlantSeeds.Length; i++)
- {
- Button button = this.m_UIButtonPlantSeeds[i];
- Text componentInChildren = button.GetComponentInChildren<Text>();
- if (string.Equals(componentInChildren.text, seedName))
- {
- return button;
- }
- }
- Debug.LogWarning("[畑の種]植物「" + seedName + "」は存在しない");
- return null;
- }
- private Farm_Mng.Plant_List GetSeedType(string eventName)
- {
- if (eventName.Equals("にんじん"))
- {
- return Farm_Mng.Plant_List.Ninjin;
- }
- if (eventName.Equals("とうもろこし"))
- {
- return Farm_Mng.Plant_List.Toumorokosi;
- }
- if (eventName.Equals("とまと"))
- {
- return Farm_Mng.Plant_List.Tomato;
- }
- if (eventName.Equals("すいか"))
- {
- return Farm_Mng.Plant_List.Suika;
- }
- if (eventName.Equals("ひまわり"))
- {
- return Farm_Mng.Plant_List.Himawari;
- }
- if (eventName.Equals("ざくろ"))
- {
- return Farm_Mng.Plant_List.Zakuro;
- }
- if (eventName.Equals("夏みかん"))
- {
- return Farm_Mng.Plant_List.Natumikan;
- }
- if (eventName.Equals("さつまいも"))
- {
- return Farm_Mng.Plant_List.Satumaimo;
- }
- return Farm_Mng.Plant_List.Nothing;
- }
- private void OnEnable()
- {
- this.Refresh();
- }
- [SerializeField]
- [Tooltip("種のボタンUI")]
- private Button[] m_UIButtonPlantSeeds;
- [SerializeField]
- [Tooltip("閉じるボタン")]
- private Button m_ButtonReturn;
- [HideInInspector]
- public UnityAction m_OnEventButtonSelected;
- [HideInInspector]
- public UnityAction m_OnEventButtonClosed;
- }
|