Farm_Mng.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class Farm_Mng : MonoBehaviour
  6. {
  7. public static Farm_Mng Instance
  8. {
  9. get
  10. {
  11. return Farm_Mng.st_this;
  12. }
  13. }
  14. private void Awake()
  15. {
  16. Farm_Mng.st_this = this;
  17. this.All_Plant_Data = new Dictionary<string, Farm_Mng.Plant_Data>();
  18. this.All_Flag_Data = new Dictionary<string, int>();
  19. this.Farm_Init();
  20. this.CSV_Read();
  21. }
  22. private void Update()
  23. {
  24. }
  25. private void CSV_Read()
  26. {
  27. if (!GameUty.FileSystem.IsExistentFile(this.csv_name))
  28. {
  29. NDebug.Assert("表がありません。" + this.csv_name, false);
  30. }
  31. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(this.csv_name))
  32. {
  33. using (CsvParser csvParser = new CsvParser())
  34. {
  35. bool condition = csvParser.Open(afileBase);
  36. NDebug.Assert(condition, this.csv_name + "\nopen failed.");
  37. for (int i = 1; i < csvParser.max_cell_y; i++)
  38. {
  39. if (csvParser.IsCellToExistData(0, i))
  40. {
  41. Farm_Mng.Plant_Data value = default(Farm_Mng.Plant_Data);
  42. for (int j = 0; j < csvParser.max_cell_x; j++)
  43. {
  44. this.Set_CSV_Data(csvParser, j, i, ref value);
  45. }
  46. this.All_Plant_Data.Add(csvParser.GetCellAsString(0, i), value);
  47. }
  48. }
  49. }
  50. }
  51. Debug.Log(this.All_Plant_Data);
  52. Debug.Log(this.All_Flag_Data);
  53. }
  54. private void Set_CSV_Data(CsvParser csv, int cell_X, int cell_Y, ref Farm_Mng.Plant_Data data)
  55. {
  56. switch (cell_X)
  57. {
  58. case 2:
  59. data.Hatuga_Day = csv.GetCellAsInteger(cell_X, cell_Y);
  60. break;
  61. case 3:
  62. data.Shukaku_Day = csv.GetCellAsInteger(cell_X, cell_Y);
  63. break;
  64. case 4:
  65. {
  66. GameObject gameObject = Resources.Load<GameObject>(this.saibaibox_path).transform.Find("saibaibox").gameObject;
  67. data.Noon_ObjName = gameObject.transform.Find(csv.GetCellAsString(cell_X, cell_Y)).transform.name;
  68. break;
  69. }
  70. case 5:
  71. {
  72. GameObject gameObject = Resources.Load<GameObject>(this.saibaibox_path).transform.Find("saibaibox").gameObject;
  73. data.Night_ObjName = gameObject.transform.Find(csv.GetCellAsString(cell_X, cell_Y)).transform.name;
  74. break;
  75. }
  76. case 6:
  77. this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_Tane)] = csv.GetCellAsInteger(cell_X, cell_Y);
  78. break;
  79. case 7:
  80. data.VR_Frag_Value = csv.GetCellAsInteger(cell_X, cell_Y);
  81. break;
  82. case 8:
  83. this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_Hatuga)] = csv.GetCellAsInteger(cell_X, cell_Y);
  84. break;
  85. case 9:
  86. this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_Mi)] = csv.GetCellAsInteger(cell_X, cell_Y);
  87. break;
  88. case 10:
  89. this.All_Flag_Data[this.GetFlagName(Farm_Mng.Plant_Mode.Mode_None)] = csv.GetCellAsInteger(cell_X, cell_Y);
  90. break;
  91. }
  92. }
  93. private void Farm_Init()
  94. {
  95. this.nFarm_Data.nPlant = Farm_Mng.Plant_List.Nothing;
  96. this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_None;
  97. this.nFarm_Data.Elapsed_Day = 0;
  98. UnityEngine.Object.Destroy(this.Saibai_Box);
  99. }
  100. private void Set_Plant(string plant_name)
  101. {
  102. string b = string.Empty;
  103. switch (SceneVRCommunication.Instance.GetNowTime())
  104. {
  105. case SceneVRCommunication.VR_TIME.MONING:
  106. case SceneVRCommunication.VR_TIME.DAY:
  107. b = this.All_Plant_Data[plant_name].Noon_ObjName;
  108. break;
  109. case SceneVRCommunication.VR_TIME.NIGHT:
  110. b = this.All_Plant_Data[plant_name].Night_ObjName;
  111. break;
  112. }
  113. if (plant_name != string.Empty)
  114. {
  115. if (this.Saibai_Box)
  116. {
  117. UnityEngine.Object.Destroy(this.Saibai_Box);
  118. }
  119. GameObject gameObject = Resources.Load<GameObject>(this.saibaibox_path);
  120. this.Saibai_Box = GameMain.Instance.BgMgr.AddPrefabToBg(gameObject.name, gameObject.name, null, gameObject.transform.position, gameObject.transform.eulerAngles);
  121. this.Saibai_Box = this.Saibai_Box.transform.Find("saibaibox").gameObject;
  122. IEnumerator enumerator = this.Saibai_Box.transform.GetEnumerator();
  123. try
  124. {
  125. while (enumerator.MoveNext())
  126. {
  127. object obj = enumerator.Current;
  128. Transform transform = (Transform)obj;
  129. if (transform.name != b)
  130. {
  131. transform.gameObject.SetActive(false);
  132. }
  133. }
  134. }
  135. finally
  136. {
  137. IDisposable disposable;
  138. if ((disposable = (enumerator as IDisposable)) != null)
  139. {
  140. disposable.Dispose();
  141. }
  142. }
  143. }
  144. }
  145. private string GetPlantName(Farm_Mng.Plant_List plant)
  146. {
  147. string result = string.Empty;
  148. switch (plant)
  149. {
  150. case Farm_Mng.Plant_List.Ninjin:
  151. result = "にんじん";
  152. break;
  153. case Farm_Mng.Plant_List.Toumorokosi:
  154. result = "とうもろこし";
  155. break;
  156. case Farm_Mng.Plant_List.Tomato:
  157. result = "とまと";
  158. break;
  159. case Farm_Mng.Plant_List.Suika:
  160. result = "すいか";
  161. break;
  162. case Farm_Mng.Plant_List.Himawari:
  163. result = "ひまわり";
  164. break;
  165. case Farm_Mng.Plant_List.Zakuro:
  166. result = "ざくろ";
  167. break;
  168. case Farm_Mng.Plant_List.Natumikan:
  169. result = "夏みかん";
  170. break;
  171. case Farm_Mng.Plant_List.Satumaimo:
  172. result = "さつまいも";
  173. break;
  174. }
  175. return result;
  176. }
  177. private bool IsPlantActive()
  178. {
  179. return this.nFarm_Data.Elapsed_Day >= this.nFarm_Data.Hatuga_Day;
  180. }
  181. private void Set_Kanban()
  182. {
  183. if (!this.Kanban_Box)
  184. {
  185. GameObject gameObject = Resources.Load<GameObject>(this.kanbanbox_path).transform.Find("kanbanbox").gameObject;
  186. this.Kanban_Box = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  187. }
  188. string b = string.Empty;
  189. Farm_Mng.Plant_Mode nMode = this.nFarm_Data.nMode;
  190. if (nMode != Farm_Mng.Plant_Mode.Mode_Tane)
  191. {
  192. if (nMode != Farm_Mng.Plant_Mode.Mode_Mi)
  193. {
  194. b = "Odogu_VF_Kanban_Taiki";
  195. }
  196. else
  197. {
  198. b = "Odogu_VF_Kanban_OK";
  199. }
  200. }
  201. else
  202. {
  203. b = "Odogu_VF_Kanban_Saibai";
  204. }
  205. IEnumerator enumerator = this.Kanban_Box.transform.GetEnumerator();
  206. try
  207. {
  208. while (enumerator.MoveNext())
  209. {
  210. object obj = enumerator.Current;
  211. Transform transform = (Transform)obj;
  212. if (transform.name != b)
  213. {
  214. transform.gameObject.SetActive(false);
  215. }
  216. }
  217. }
  218. finally
  219. {
  220. IDisposable disposable;
  221. if ((disposable = (enumerator as IDisposable)) != null)
  222. {
  223. disposable.Dispose();
  224. }
  225. }
  226. this.Kanban_Box.transform.parent = base.transform.parent;
  227. }
  228. private string GetFlagName(Farm_Mng.Plant_Mode mode)
  229. {
  230. string result = string.Empty;
  231. switch (mode)
  232. {
  233. case Farm_Mng.Plant_Mode.Mode_Tane:
  234. result = "入植";
  235. break;
  236. case Farm_Mng.Plant_Mode.Mode_Hatuga:
  237. result = "発芽";
  238. break;
  239. case Farm_Mng.Plant_Mode.Mode_Mi:
  240. result = "収穫";
  241. break;
  242. default:
  243. result = "待機";
  244. break;
  245. }
  246. return result;
  247. }
  248. private void Set_Flag(string flag_name, int flag_value)
  249. {
  250. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  251. maid.status.SetFlag(flag_name, flag_value);
  252. }
  253. public void Day_Start()
  254. {
  255. if (!this.IsPlantOn(Farm_Mng.Plant_List.Nothing))
  256. {
  257. this.nFarm_Data.Elapsed_Day = this.nFarm_Data.Elapsed_Day + 1;
  258. if (this.IsPlantGet())
  259. {
  260. this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_Mi;
  261. }
  262. else if (this.IsPlantActive())
  263. {
  264. this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_Hatuga;
  265. }
  266. }
  267. string flagName = this.GetFlagName(this.nFarm_Data.nMode);
  268. this.Set_Flag("VR植物進捗状況", this.All_Flag_Data[flagName]);
  269. }
  270. public void Farm_Start()
  271. {
  272. if (!this.IsPlantOn(Farm_Mng.Plant_List.Nothing) && this.IsPlantActive())
  273. {
  274. this.Set_Plant(this.GetPlantName(this.nFarm_Data.nPlant));
  275. }
  276. }
  277. public void NyuShoku(Farm_Mng.Plant_List plant)
  278. {
  279. string plantName = this.GetPlantName(plant);
  280. if (plantName != string.Empty)
  281. {
  282. this.nFarm_Data.nPlant = plant;
  283. this.nFarm_Data.nMode = Farm_Mng.Plant_Mode.Mode_Tane;
  284. this.nFarm_Data.Hatuga_Day = this.All_Plant_Data[plantName].Hatuga_Day;
  285. this.nFarm_Data.Shukaku_Day = this.All_Plant_Data[plantName].Shukaku_Day;
  286. string flagName = this.GetFlagName(this.nFarm_Data.nMode);
  287. this.Set_Flag("VR植物進捗状況", this.All_Flag_Data[flagName]);
  288. string plantName2 = this.GetPlantName(this.nFarm_Data.nPlant);
  289. this.Set_Flag("VRイベント植物名", this.All_Plant_Data[plantName2].VR_Frag_Value);
  290. }
  291. }
  292. public void SyuKaku()
  293. {
  294. if (!this.IsPlantOn(Farm_Mng.Plant_List.Nothing) && this.IsPlantGet())
  295. {
  296. this.Farm_Init();
  297. UnityEngine.Object.Destroy(this.Saibai_Box);
  298. this.Saibai_Box = null;
  299. string flagName = this.GetFlagName(this.nFarm_Data.nMode);
  300. this.Set_Flag("VR植物進捗状況", this.All_Flag_Data[flagName]);
  301. }
  302. }
  303. public bool IsPlantGet()
  304. {
  305. return this.nFarm_Data.Elapsed_Day >= this.nFarm_Data.Shukaku_Day;
  306. }
  307. public bool IsPlantOn(Farm_Mng.Plant_List plant)
  308. {
  309. return this.nFarm_Data.nPlant == plant;
  310. }
  311. private Farm_Mng.Farm_Data nFarm_Data;
  312. private Dictionary<string, Farm_Mng.Plant_Data> All_Plant_Data;
  313. [SerializeField]
  314. [Header("csvファイル名")]
  315. private string csv_name = "vrcom_culture.nei";
  316. [SerializeField]
  317. [Header("植物プレハブのパス")]
  318. private string saibaibox_path = "Prefab/villa_farm_event_saibaibox";
  319. private GameObject Saibai_Box;
  320. [SerializeField]
  321. [Header("看板プレハブのパス")]
  322. private string kanbanbox_path = "Prefab/villa_farm_event";
  323. private GameObject Kanban_Box;
  324. private Dictionary<string, int> All_Flag_Data;
  325. private static Farm_Mng st_this;
  326. private enum Plant_Mode
  327. {
  328. Mode_Tane,
  329. Mode_Hatuga,
  330. Mode_Mi,
  331. Mode_None
  332. }
  333. public enum Plant_List
  334. {
  335. Ninjin,
  336. Toumorokosi,
  337. Tomato,
  338. Suika,
  339. Himawari,
  340. Zakuro,
  341. Natumikan,
  342. Satumaimo,
  343. Nothing
  344. }
  345. private struct Farm_Data
  346. {
  347. public Farm_Mng.Plant_List nPlant;
  348. public Farm_Mng.Plant_Mode nMode;
  349. public int Hatuga_Day;
  350. public int Shukaku_Day;
  351. public int Elapsed_Day;
  352. }
  353. private struct Plant_Data
  354. {
  355. public int Hatuga_Day;
  356. public int Shukaku_Day;
  357. public string Night_ObjName;
  358. public string Noon_ObjName;
  359. public int VR_Frag_Value;
  360. }
  361. }