DanceSetting.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. using System.Text;
  8. using Dance;
  9. using UnityEngine;
  10. public class DanceSetting : MonoBehaviour
  11. {
  12. private void Awake()
  13. {
  14. this.m_OrijinBgheight = this.m_SettingUIBg.height;
  15. if (!DanceSetting.m_IsFileCheck)
  16. {
  17. Action<string, bool> action = delegate(string file_path, bool binary_ver)
  18. {
  19. float num = -1f;
  20. FileInfo fileInfo = new FileInfo(file_path);
  21. try
  22. {
  23. if (binary_ver)
  24. {
  25. using (FileStream fileStream = new FileStream(file_path, FileMode.Open, FileAccess.Read))
  26. {
  27. BinaryFormatter binaryFormatter = new BinaryFormatter();
  28. string text = (string)binaryFormatter.Deserialize(fileStream);
  29. string text2 = (string)binaryFormatter.Deserialize(fileStream);
  30. float.TryParse(text2.Split(new char[]
  31. {
  32. ':'
  33. })[1], out num);
  34. DanceSetting.Settings = (SettingData)binaryFormatter.Deserialize(fileStream);
  35. fileStream.Close();
  36. }
  37. }
  38. else
  39. {
  40. using (StreamReader streamReader = new StreamReader(fileInfo.OpenRead(), Encoding.UTF8))
  41. {
  42. string text3 = streamReader.ReadLine();
  43. if (text3 == "@Dance_Setting")
  44. {
  45. string s = streamReader.ReadLine().Split(new char[]
  46. {
  47. ':'
  48. })[1];
  49. float.TryParse(s, out num);
  50. text3 = streamReader.ReadLine();
  51. }
  52. DanceSetting.Settings = JsonUtility.FromJson<SettingData>(text3);
  53. streamReader.Close();
  54. }
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. if (num > 0f)
  60. {
  61. if (num == 1f)
  62. {
  63. Debug.Log("2017/11/22以前の設定データです");
  64. }
  65. }
  66. else
  67. {
  68. DanceSetting.Settings = new SettingData();
  69. File.Delete(file_path);
  70. Debug.LogWarning("ダンス設定読み込みに失敗したので初期化します。エラー箇所:" + ex.StackTrace);
  71. }
  72. }
  73. };
  74. string fullPath = Path.GetFullPath(".\\dance_setting_br.dat");
  75. DanceSetting.m_IsFileExist = File.Exists(fullPath);
  76. if (DanceSetting.m_IsFileExist)
  77. {
  78. action(fullPath, true);
  79. }
  80. else
  81. {
  82. string fullPath2 = Path.GetFullPath(".\\dance_setting.set");
  83. string fullPath3 = Path.GetFullPath(".\\dance_setting.dat");
  84. if (File.Exists(fullPath2))
  85. {
  86. action(fullPath2, false);
  87. File.Delete(fullPath2);
  88. }
  89. else if (File.Exists(fullPath3))
  90. {
  91. action(fullPath3, false);
  92. File.Delete(fullPath3);
  93. }
  94. }
  95. DanceSetting.m_IsFileCheck = true;
  96. }
  97. }
  98. private void Start()
  99. {
  100. EventDelegate.Callback callback = delegate
  101. {
  102. GameObject gameObject = GameObject.Find("Drop-down List");
  103. if (gameObject)
  104. {
  105. int width = gameObject.GetComponentInChildren<UISprite>().width;
  106. gameObject.transform.position = UIButton.current.transform.TransformPoint(Vector3.down * this.m_PopUpOffset + Vector3.left * (float)width / 2f);
  107. }
  108. };
  109. IEnumerator enumerator = this.m_ButtonGroup.GetEnumerator();
  110. try
  111. {
  112. while (enumerator.MoveNext())
  113. {
  114. object obj = enumerator.Current;
  115. Transform transform = (Transform)obj;
  116. UIPopupList componentInChildren = transform.GetComponentInChildren<UIPopupList>();
  117. if (componentInChildren)
  118. {
  119. DanceSetting.NeedData needData = new DanceSetting.NeedData();
  120. if (transform.Find("Label"))
  121. {
  122. needData.Label = transform.Find("Label").GetComponent<UILabel>();
  123. }
  124. needData.Button = transform.GetComponentInChildren<UIButton>();
  125. EventDelegate.Add(needData.Button.onClick, callback);
  126. needData.Collider = transform.GetComponentInChildren<BoxCollider>();
  127. this.m_SettingUIList.Add(componentInChildren, needData);
  128. EventDelegate.Add(componentInChildren.onChange, new EventDelegate.Callback(this.ValueSetting));
  129. this.SetUIValue(componentInChildren);
  130. }
  131. }
  132. }
  133. finally
  134. {
  135. IDisposable disposable;
  136. if ((disposable = (enumerator as IDisposable)) != null)
  137. {
  138. disposable.Dispose();
  139. }
  140. }
  141. }
  142. private void SetUIValue(UIPopupList list)
  143. {
  144. DanceSetting.UIInspectorSetting uiinspectorSetting = this.m_SettingList.SingleOrDefault((DanceSetting.UIInspectorSetting e) => e.PopUpUI == list);
  145. if (uiinspectorSetting == null)
  146. {
  147. return;
  148. }
  149. foreach (string text in list.items)
  150. {
  151. bool flag = false;
  152. switch (uiinspectorSetting.MyType)
  153. {
  154. case DanceSetting.SettingType.Product:
  155. flag = this.IsProductMatch(text);
  156. break;
  157. case DanceSetting.SettingType.Audience:
  158. flag = this.IsAudienceMatch(text);
  159. break;
  160. case DanceSetting.SettingType.DepthofField:
  161. flag = this.IsSettingOn(text, DanceSetting.Settings.IsDepthOfFieldOn);
  162. break;
  163. case DanceSetting.SettingType.SePlay:
  164. flag = this.IsSettingOn(text, DanceSetting.Settings.IsSEPlay);
  165. break;
  166. case DanceSetting.SettingType.Voltage:
  167. flag = this.IsVoltageMatch(text);
  168. break;
  169. case DanceSetting.SettingType.BlackBg:
  170. flag = this.IsSettingOn(text, DanceSetting.Settings.IsblackBGon);
  171. break;
  172. case DanceSetting.SettingType.NoteEffect:
  173. flag = this.IsEffectLigthtMatch(text);
  174. break;
  175. case DanceSetting.SettingType.NoteTiming:
  176. flag = this.IsTimingMatch(text);
  177. break;
  178. case DanceSetting.SettingType.JudgeTiming:
  179. flag = this.IsJudgeTimingMatch(text);
  180. break;
  181. case DanceSetting.SettingType.FpsCam:
  182. flag = this.IsSettingOn(text, DanceSetting.Settings.FPSCamMode);
  183. break;
  184. case DanceSetting.SettingType.Cutin:
  185. flag = this.IsCutinMatch(text);
  186. break;
  187. case DanceSetting.SettingType.Undress:
  188. flag = this.IsUndressFaceMatch(text);
  189. break;
  190. }
  191. if (flag)
  192. {
  193. list.value = text;
  194. break;
  195. }
  196. }
  197. }
  198. private bool IsProductMatch(string text)
  199. {
  200. bool result = false;
  201. switch (DanceSetting.Settings.Product)
  202. {
  203. case Product_Mgr.ProductRank.Low:
  204. result = (text == "下位");
  205. break;
  206. case Product_Mgr.ProductRank.Special:
  207. result = (text == "上位");
  208. break;
  209. case Product_Mgr.ProductRank.Normal:
  210. result = (text == "通常");
  211. break;
  212. }
  213. return result;
  214. }
  215. private bool IsAudienceMatch(string text)
  216. {
  217. bool result = false;
  218. switch (DanceSetting.Settings.Audience)
  219. {
  220. case Product_Mgr.AudienceState.Few:
  221. result = (text == "小");
  222. break;
  223. case Product_Mgr.AudienceState.Normal:
  224. result = (text == "中");
  225. break;
  226. case Product_Mgr.AudienceState.Many:
  227. result = (text == "大");
  228. break;
  229. }
  230. return result;
  231. }
  232. private bool IsSettingOn(string text, bool condition)
  233. {
  234. if (condition)
  235. {
  236. return text == "ON";
  237. }
  238. return text == "OFF";
  239. }
  240. private bool IsVoltageMatch(string text)
  241. {
  242. int num = 0;
  243. if (int.TryParse(text, out num))
  244. {
  245. return DanceSetting.Settings.Voltage == num;
  246. }
  247. if (text == "普通")
  248. {
  249. return DanceSetting.Settings.Voltage == 3;
  250. }
  251. return text == "難しい" && DanceSetting.Settings.Voltage == 4;
  252. }
  253. private bool IsCutinMatch(string text)
  254. {
  255. return DanceSetting.Settings.CutInGrade == Appeal_Mgr.ParseGrade(text);
  256. }
  257. private bool IsTimingMatch(string text)
  258. {
  259. return DanceSetting.Settings.NoteOccurTiming.ToString() == text.Replace("+", string.Empty).Replace("秒", string.Empty);
  260. }
  261. private bool IsEffectLigthtMatch(string text)
  262. {
  263. if (text == "軽量")
  264. {
  265. return DanceSetting.Settings.IsNoteEffectLight;
  266. }
  267. return !DanceSetting.Settings.IsNoteEffectLight;
  268. }
  269. private bool IsUndressFaceMatch(string text)
  270. {
  271. if (text == "通常")
  272. {
  273. return DanceSetting.Settings.UndressFaceOn;
  274. }
  275. return !DanceSetting.Settings.UndressFaceOn;
  276. }
  277. private bool IsJudgeTimingMatch(string text)
  278. {
  279. return DanceSetting.Settings.NoteJudgeTiming == float.Parse(text.Replace("秒", string.Empty));
  280. }
  281. private void OnDestroy()
  282. {
  283. using (FileStream fileStream = new FileStream(Path.GetFullPath(".\\dance_setting_br.dat"), FileMode.Create, FileAccess.Write))
  284. {
  285. BinaryFormatter binaryFormatter = new BinaryFormatter();
  286. binaryFormatter.Serialize(fileStream, "@Dance_Setting");
  287. binaryFormatter.Serialize(fileStream, string.Format("Ver:{0}", 1.7f));
  288. binaryFormatter.Serialize(fileStream, DanceSetting.Settings);
  289. fileStream.Close();
  290. }
  291. DanceSetting.m_IsFileExist = true;
  292. }
  293. private void SwitchFlag(string value_text, ref bool swtch_flag)
  294. {
  295. if (value_text != null)
  296. {
  297. if (!(value_text == "ON"))
  298. {
  299. if (value_text == "OFF")
  300. {
  301. swtch_flag = false;
  302. }
  303. }
  304. else
  305. {
  306. swtch_flag = true;
  307. }
  308. }
  309. }
  310. private void SetProduct(string value_text)
  311. {
  312. Product_Mgr.ProductRank product = Product_Mgr.ProductRank.Low;
  313. if (value_text != null)
  314. {
  315. if (!(value_text == "下位"))
  316. {
  317. if (!(value_text == "通常"))
  318. {
  319. if (value_text == "上位")
  320. {
  321. product = Product_Mgr.ProductRank.Special;
  322. }
  323. }
  324. else
  325. {
  326. product = Product_Mgr.ProductRank.Normal;
  327. }
  328. }
  329. else
  330. {
  331. product = Product_Mgr.ProductRank.Low;
  332. }
  333. }
  334. DanceSetting.Settings.Product = product;
  335. }
  336. private void SetAudience(string value_text)
  337. {
  338. Product_Mgr.AudienceState audience = Product_Mgr.AudienceState.Normal;
  339. if (value_text != null)
  340. {
  341. if (!(value_text == "小"))
  342. {
  343. if (!(value_text == "中"))
  344. {
  345. if (value_text == "大")
  346. {
  347. audience = Product_Mgr.AudienceState.Many;
  348. }
  349. }
  350. else
  351. {
  352. audience = Product_Mgr.AudienceState.Normal;
  353. }
  354. }
  355. else
  356. {
  357. audience = Product_Mgr.AudienceState.Few;
  358. }
  359. }
  360. DanceSetting.Settings.Audience = audience;
  361. }
  362. private void SetVoltage(string value_text)
  363. {
  364. int voltage = 0;
  365. if (int.TryParse(value_text, out voltage))
  366. {
  367. DanceSetting.Settings.Voltage = voltage;
  368. }
  369. else if (value_text != null)
  370. {
  371. if (!(value_text == "普通"))
  372. {
  373. if (value_text == "難しい")
  374. {
  375. DanceSetting.Settings.Voltage = 4;
  376. }
  377. }
  378. else
  379. {
  380. DanceSetting.Settings.Voltage = 3;
  381. }
  382. }
  383. }
  384. private void SetCutInGrade(string value_text)
  385. {
  386. DanceSetting.Settings.CutInGrade = Appeal_Mgr.ParseGrade(value_text);
  387. }
  388. private void SetNoteTiming(string value_text)
  389. {
  390. DanceSetting.Settings.NoteOccurTiming = int.Parse(value_text.Replace("+", string.Empty));
  391. }
  392. private void SetEffectLight(string value_text)
  393. {
  394. if (value_text != null)
  395. {
  396. if (!(value_text == "通常"))
  397. {
  398. if (value_text == "軽量")
  399. {
  400. DanceSetting.Settings.IsNoteEffectLight = true;
  401. }
  402. }
  403. else
  404. {
  405. DanceSetting.Settings.IsNoteEffectLight = false;
  406. }
  407. }
  408. }
  409. private void SetUndressFace(string value_text)
  410. {
  411. if (value_text != null)
  412. {
  413. if (!(value_text == "通常"))
  414. {
  415. if (value_text == "我慢")
  416. {
  417. DanceSetting.Settings.UndressFaceOn = false;
  418. }
  419. }
  420. else
  421. {
  422. DanceSetting.Settings.UndressFaceOn = true;
  423. }
  424. }
  425. }
  426. private void SetJudgeTiming(string value_text)
  427. {
  428. DanceSetting.Settings.NoteJudgeTiming = float.Parse(value_text);
  429. }
  430. private void ValueSetting()
  431. {
  432. string value = UIPopupList.current.value;
  433. DanceSetting.UIInspectorSetting uiinspectorSetting = this.m_SettingList.SingleOrDefault((DanceSetting.UIInspectorSetting e) => e.PopUpUI == UIPopupList.current);
  434. if (uiinspectorSetting == null)
  435. {
  436. return;
  437. }
  438. switch (uiinspectorSetting.MyType)
  439. {
  440. case DanceSetting.SettingType.Product:
  441. this.SetProduct(value);
  442. break;
  443. case DanceSetting.SettingType.Audience:
  444. this.SetAudience(value);
  445. break;
  446. case DanceSetting.SettingType.DepthofField:
  447. this.SwitchFlag(value, ref DanceSetting.Settings.IsDepthOfFieldOn);
  448. break;
  449. case DanceSetting.SettingType.SePlay:
  450. this.SwitchFlag(value, ref DanceSetting.Settings.IsSEPlay);
  451. break;
  452. case DanceSetting.SettingType.Voltage:
  453. this.SetVoltage(value);
  454. break;
  455. case DanceSetting.SettingType.BlackBg:
  456. this.SwitchFlag(value, ref DanceSetting.Settings.IsblackBGon);
  457. break;
  458. case DanceSetting.SettingType.NoteEffect:
  459. this.SetEffectLight(value);
  460. break;
  461. case DanceSetting.SettingType.NoteTiming:
  462. this.SetNoteTiming(value);
  463. break;
  464. case DanceSetting.SettingType.JudgeTiming:
  465. this.SetJudgeTiming(value);
  466. break;
  467. case DanceSetting.SettingType.FpsCam:
  468. this.SwitchFlag(value, ref DanceSetting.Settings.FPSCamMode);
  469. break;
  470. case DanceSetting.SettingType.Cutin:
  471. this.SetCutInGrade(value);
  472. break;
  473. case DanceSetting.SettingType.Undress:
  474. this.SetUndressFace(value);
  475. break;
  476. }
  477. if (this.m_SettingUIList[UIPopupList.current].Label)
  478. {
  479. this.m_IsSettingChange = (this.m_SettingUIList[UIPopupList.current].Label.text != UIPopupList.current.value);
  480. this.m_SettingUIList[UIPopupList.current].Label.text = UIPopupList.current.value;
  481. }
  482. }
  483. public void DisSelectable()
  484. {
  485. foreach (KeyValuePair<UIPopupList, DanceSetting.NeedData> keyValuePair in this.m_SettingUIList)
  486. {
  487. if (keyValuePair.Value.Collider)
  488. {
  489. keyValuePair.Value.Collider.enabled = false;
  490. }
  491. }
  492. }
  493. public void SetUIMode(string mode = "")
  494. {
  495. RhythmAction_Mgr.DanceType nowDance = RhythmAction_Mgr.NowDance;
  496. if (nowDance != RhythmAction_Mgr.DanceType.Challenge)
  497. {
  498. if (nowDance != RhythmAction_Mgr.DanceType.VS)
  499. {
  500. if (mode.IndexOf("モード") >= 0)
  501. {
  502. this.m_ModeLabel.text = mode + "設定";
  503. }
  504. else
  505. {
  506. this.m_ModeLabel.text = mode + "モード設定";
  507. }
  508. }
  509. else
  510. {
  511. this.m_ModeLabel.text = "VSダンス設定";
  512. }
  513. }
  514. else
  515. {
  516. this.m_ModeLabel.text = "ダンスショー設定";
  517. }
  518. int num = 0;
  519. foreach (DanceSetting.UIInspectorSetting uiinspectorSetting in this.m_SettingList)
  520. {
  521. GameObject gameObject = uiinspectorSetting.PopUpUI.transform.parent.gameObject;
  522. bool flag = uiinspectorSetting.OnDanceList.Contains(RhythmAction_Mgr.NowDance);
  523. if (GameMain.Instance.VRMode)
  524. {
  525. flag &= uiinspectorSetting.UseVR;
  526. }
  527. gameObject.SetActive(flag);
  528. if (flag)
  529. {
  530. gameObject.transform.localPosition = Vector3.up * (this.m_FirstUIposY - this.m_UISetInterval * (float)num);
  531. num++;
  532. }
  533. }
  534. this.m_SettingUIBg.height = this.m_OrijinBgheight + num * Mathf.FloorToInt(this.m_UISetInterval);
  535. }
  536. private const string m_SettingHeader = "@Dance_Setting";
  537. private const float m_SettingVer = 1.7f;
  538. [SerializeField]
  539. [Header("設定項目設置間隔")]
  540. private float m_UISetInterval;
  541. [SerializeField]
  542. private float m_FirstUIposY;
  543. [SerializeField]
  544. [Header("ポップアップ表示オフセット")]
  545. private float m_PopUpOffset = 27.47f;
  546. [SerializeField]
  547. [Header("ボタンUIグループ")]
  548. private Transform m_ButtonGroup;
  549. [SerializeField]
  550. private UILabel m_ModeLabel;
  551. private Dictionary<UIPopupList, DanceSetting.NeedData> m_SettingUIList = new Dictionary<UIPopupList, DanceSetting.NeedData>();
  552. [SerializeField]
  553. [Header("各UI設定")]
  554. private List<DanceSetting.UIInspectorSetting> m_SettingList = new List<DanceSetting.UIInspectorSetting>
  555. {
  556. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.Product),
  557. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.Audience),
  558. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.DepthofField),
  559. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.SePlay),
  560. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.Voltage),
  561. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.BlackBg),
  562. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.NoteEffect),
  563. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.NoteTiming),
  564. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.JudgeTiming),
  565. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.FpsCam),
  566. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.Cutin),
  567. new DanceSetting.UIInspectorSetting(DanceSetting.SettingType.Undress)
  568. };
  569. private bool m_IsSettingChange;
  570. [SerializeField]
  571. [Header("設定UI背景")]
  572. private UISprite m_SettingUIBg;
  573. private int m_OrijinBgheight;
  574. public static SettingData Settings = new SettingData();
  575. private static bool m_IsFileExist = false;
  576. private static bool m_IsFileCheck = false;
  577. private class NeedData
  578. {
  579. public UILabel Label;
  580. public UIButton Button;
  581. public BoxCollider Collider;
  582. public string DefoValue;
  583. }
  584. public enum SettingType
  585. {
  586. Product,
  587. Audience,
  588. DepthofField,
  589. SePlay,
  590. Voltage,
  591. BlackBg,
  592. NoteEffect,
  593. NoteTiming,
  594. JudgeTiming,
  595. FpsCam,
  596. Cutin,
  597. Undress,
  598. AllRelease
  599. }
  600. [Serializable]
  601. private class UIInspectorSetting
  602. {
  603. public UIInspectorSetting(DanceSetting.SettingType type)
  604. {
  605. this.MyType = type;
  606. }
  607. public DanceSetting.SettingType MyType;
  608. public UIPopupList PopUpUI;
  609. public List<RhythmAction_Mgr.DanceType> OnDanceList = new List<RhythmAction_Mgr.DanceType>();
  610. public bool UsePublic = true;
  611. public bool UseVR = true;
  612. }
  613. }