using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Farm_Mng : MonoBehaviour { public static Farm_Mng Instance { get { return Farm_Mng.st_this; } } private void Awake() { Farm_Mng.st_this = this; this.All_Plant_Data = new Dictionary(); this.All_Flag_Data = new Dictionary(); this.Farm_Init(); this.CSV_Read(); } private void Update() { } private void CSV_Read() { if (!GameUty.FileSystem.IsExistentFile(this.csv_name)) { NDebug.Assert("表がありません。" + this.csv_name, false); } using (AFileBase afileBase = GameUty.FileSystem.FileOpen(this.csv_name)) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, this.csv_name + "\nopen failed."); for (int i = 1; i < csvParser.max_cell_y; i++) { if (csvParser.IsCellToExistData(0, i)) { Farm_Mng.Plant_Data value = default(Farm_Mng.Plant_Data); for (int j = 0; j < csvParser.max_cell_x; j++) { this.Set_CSV_Data(csvParser, j, i, ref value); } this.All_Plant_Data.Add(csvParser.GetCellAsString(0, i), value); } } } } Debug.Log(this.All_Plant_Data); Debug.Log(this.All_Flag_Data); } private void Set_CSV_Data(CsvParser csv, int cell_X, int cell_Y, ref Farm_Mng.Plant_Data data) { switch (cell_X) { case 2: data.Hatuga_Day = csv.GetCellAsInteger(cell_X, cell_Y); break; case 3: data.Shukaku_Day = csv.GetCellAsInteger(cell_X, cell_Y); break; case 4: { GameObject gameObject = Resources.Load(this.saibaibox_path).transform.Find("saibaibox").gameObject; data.Noon_ObjName = gameObject.transform.Find(csv.GetCellAsString(cell_X, cell_Y)).transform.name; break; } case 5: { GameObject gameObject = Resources.Load(this.saibaibox_path).transform.Find("saibaibox").gameObject; data.Night_ObjName = gameObject.transform.Find(csv.GetCellAsString(cell_X, cell_Y)).transform.name; break; } case 6: this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_Tane)] = csv.GetCellAsInteger(cell_X, cell_Y); break; case 7: data.VR_Frag_Value = csv.GetCellAsInteger(cell_X, cell_Y); break; case 8: this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_Hatuga)] = csv.GetCellAsInteger(cell_X, cell_Y); break; case 9: this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_Mi)] = csv.GetCellAsInteger(cell_X, cell_Y); break; case 10: this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_None)] = csv.GetCellAsInteger(cell_X, cell_Y); break; } } private void Farm_Init() { this.nFarm_Data.nPlant = Farm_Mng.Plant_List.Nothing; this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_None; this.nFarm_Data.Elapsed_Day = 0; UnityEngine.Object.Destroy(this.Saibai_Box); } private void Set_Plant(string plant_name) { string b = string.Empty; switch (SceneVRCommunication.Instance.GetNowTime()) { case SceneVRCommunication.VR_TIME.MONING: case SceneVRCommunication.VR_TIME.DAY: b = this.All_Plant_Data[plant_name].Noon_ObjName; break; case SceneVRCommunication.VR_TIME.NIGHT: b = this.All_Plant_Data[plant_name].Night_ObjName; break; } if (plant_name != string.Empty) { if (this.Saibai_Box) { UnityEngine.Object.Destroy(this.Saibai_Box); } GameObject gameObject = Resources.Load(this.saibaibox_path); this.Saibai_Box = GameMain.Instance.BgMgr.AddPrefabToBg(gameObject.name, gameObject.name, null, gameObject.transform.position, gameObject.transform.eulerAngles); this.Saibai_Box = this.Saibai_Box.transform.Find("saibaibox").gameObject; IEnumerator enumerator = this.Saibai_Box.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; if (transform.name != b) { transform.gameObject.SetActive(false); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } } } private string GetPlantName(Farm_Mng.Plant_List plant) { string result = string.Empty; switch (plant) { case Farm_Mng.Plant_List.Ninjin: result = "にんじん"; break; case Farm_Mng.Plant_List.Toumorokosi: result = "とうもろこし"; break; case Farm_Mng.Plant_List.Tomato: result = "とまと"; break; case Farm_Mng.Plant_List.Suika: result = "すいか"; break; case Farm_Mng.Plant_List.Himawari: result = "ひまわり"; break; case Farm_Mng.Plant_List.Zakuro: result = "ざくろ"; break; case Farm_Mng.Plant_List.Natumikan: result = "夏みかん"; break; case Farm_Mng.Plant_List.Satumaimo: result = "さつまいも"; break; } return result; } private bool IsPlantActive() { return this.nFarm_Data.Elapsed_Day >= this.nFarm_Data.Hatuga_Day; } private void Set_Kanban() { if (!this.Kanban_Box) { GameObject gameObject = Resources.Load(this.kanbanbox_path).transform.Find("kanbanbox").gameObject; this.Kanban_Box = UnityEngine.Object.Instantiate(gameObject); } string b = string.Empty; Farm_Mng.Plant_Mode nMode = this.nFarm_Data.nMode; if (nMode != Farm_Mng.Plant_Mode.Mode_Tane) { if (nMode != Farm_Mng.Plant_Mode.Mode_Mi) { b = "Odogu_VF_Kanban_Taiki"; } else { b = "Odogu_VF_Kanban_OK"; } } else { b = "Odogu_VF_Kanban_Saibai"; } IEnumerator enumerator = this.Kanban_Box.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; if (transform.name != b) { transform.gameObject.SetActive(false); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.Kanban_Box.transform.parent = base.transform.parent; } private string GetFlagName(Farm_Mng.Plant_Mode mode) { string result = string.Empty; switch (mode) { case Farm_Mng.Plant_Mode.Mode_Tane: result = "入植"; break; case Farm_Mng.Plant_Mode.Mode_Hatuga: result = "発芽"; break; case Farm_Mng.Plant_Mode.Mode_Mi: result = "収穫"; break; default: result = "待機"; break; } return result; } private void Set_Flag(string flag_name, int flag_value) { Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0); maid.status.SetFlag(flag_name, flag_value); } public void Day_Start() { if (!this.IsPlantOn(Farm_Mng.Plant_List.Nothing)) { this.nFarm_Data.Elapsed_Day = this.nFarm_Data.Elapsed_Day + 1; if (this.IsPlantGet()) { this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_Mi; } else if (this.IsPlantActive()) { this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_Hatuga; } } string flagName = this.GetFlagName(this.nFarm_Data.nMode); this.Set_Flag("VR植物進捗状況", this.All_Flag_Data[flagName]); } public void Farm_Start() { if (!this.IsPlantOn(Farm_Mng.Plant_List.Nothing) && this.IsPlantActive()) { this.Set_Plant(this.GetPlantName(this.nFarm_Data.nPlant)); } } public void NyuShoku(Farm_Mng.Plant_List plant) { string plantName = this.GetPlantName(plant); if (plantName != string.Empty) { this.nFarm_Data.nPlant = plant; this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_Tane; this.nFarm_Data.Hatuga_Day = this.All_Plant_Data[plantName].Hatuga_Day; this.nFarm_Data.Shukaku_Day = this.All_Plant_Data[plantName].Shukaku_Day; string flagName = this.GetFlagName(this.nFarm_Data.nMode); this.Set_Flag("VR植物進捗状況", this.All_Flag_Data[flagName]); string plantName2 = this.GetPlantName(this.nFarm_Data.nPlant); this.Set_Flag("VRイベント植物名", this.All_Plant_Data[plantName2].VR_Frag_Value); } } public void SyuKaku() { if (!this.IsPlantOn(Farm_Mng.Plant_List.Nothing) && this.IsPlantGet()) { this.Farm_Init(); UnityEngine.Object.Destroy(this.Saibai_Box); this.Saibai_Box = null; string flagName = this.GetFlagName(this.nFarm_Data.nMode); this.Set_Flag("VR植物進捗状況", this.All_Flag_Data[flagName]); } } public bool IsPlantGet() { return this.nFarm_Data.Elapsed_Day >= this.nFarm_Data.Shukaku_Day; } public bool IsPlantOn(Farm_Mng.Plant_List plant) { return this.nFarm_Data.nPlant == plant; } private Farm_Mng.Farm_Data nFarm_Data; private Dictionary All_Plant_Data; [SerializeField] [Header("csvファイル名")] private string csv_name = "vrcom_culture.nei"; [SerializeField] [Header("植物プレハブのパス")] private string saibaibox_path = "Prefab/villa_farm_event_saibaibox"; private GameObject Saibai_Box; [SerializeField] [Header("看板プレハブのパス")] private string kanbanbox_path = "Prefab/villa_farm_event"; private GameObject Kanban_Box; private Dictionary All_Flag_Data; private static Farm_Mng st_this; private enum Plant_Mode { Mode_Tane, Mode_Hatuga, Mode_Mi, Mode_None } public enum Plant_List { Ninjin, Toumorokosi, Tomato, Suika, Himawari, Zakuro, Natumikan, Satumaimo, Nothing } private struct Farm_Data { public Farm_Mng.Plant_List nPlant; public Farm_Mng.Plant_Mode nMode; public int Hatuga_Day; public int Shukaku_Day; public int Elapsed_Day; } private struct Plant_Data { public int Hatuga_Day; public int Shukaku_Day; public string Night_ObjName; public string Noon_ObjName; public int VR_Frag_Value; } }