123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- 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<string, Farm_Mng.Plant_Data>();
- this.All_Flag_Data = new Dictionary<string, int>();
- 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<GameObject>(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<GameObject>(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<GameObject>(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<GameObject>(this.kanbanbox_path).transform.Find("kanbanbox").gameObject;
- this.Kanban_Box = UnityEngine.Object.Instantiate<GameObject>(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<string, Farm_Mng.Plant_Data> 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<string, int> 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;
- }
- }
|