VRTrophyMenu.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class VRTrophyMenu : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. }
  9. private void UpdateTrohyUI()
  10. {
  11. this.m_PrefabElement.SetActive(false);
  12. string text = "vrcom_trophy.nei";
  13. if (!GameUty.FileSystem.IsExistentFile(text))
  14. {
  15. NDebug.Assert("表がありません。" + text, false);
  16. }
  17. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  18. {
  19. using (CsvParser csvParser = new CsvParser())
  20. {
  21. bool condition = csvParser.Open(afileBase);
  22. NDebug.Assert(condition, text + "\nopen failed.");
  23. for (int i = 1; i < csvParser.max_cell_y; i++)
  24. {
  25. if (csvParser.IsCellToExistData(0, i))
  26. {
  27. int num = 0;
  28. int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
  29. string cellAsString = csvParser.GetCellAsString(num++, i);
  30. string cellAsString2 = csvParser.GetCellAsString(num++, i);
  31. string cellAsString3 = csvParser.GetCellAsString(num++, i);
  32. string cellAsString4 = csvParser.GetCellAsString(num++, i);
  33. bool isGet = false;
  34. if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
  35. {
  36. isGet = (GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(cellAsString) >= 1);
  37. }
  38. VRTrophyMenu.ElementData elementData = this.CreateElement(isGet);
  39. elementData.TextName.text = cellAsString2;
  40. elementData.TextFlag.text = cellAsString3;
  41. elementData.TextItem.text = cellAsString4;
  42. }
  43. }
  44. }
  45. }
  46. }
  47. private VRTrophyMenu.ElementData CreateElement(bool isGet)
  48. {
  49. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabElement);
  50. gameObject.SetActive(true);
  51. gameObject.transform.SetParent(this.m_Content, false);
  52. VRTrophyMenu.ElementData elementData = new VRTrophyMenu.ElementData();
  53. elementData.TextName = gameObject.transform.Find("Text Trohy Name").GetComponent<Text>();
  54. elementData.TextFlag = gameObject.transform.Find("Text Trohy Flag").GetComponent<Text>();
  55. elementData.TextItem = gameObject.transform.Find("Text Trohy Item").GetComponent<Text>();
  56. Color targetColor = (!isGet) ? (Color.white * 0.75f) : Color.white;
  57. Graphic[] componentsInChildren = gameObject.GetComponentsInChildren<Graphic>();
  58. for (int i = 0; i < componentsInChildren.Length; i++)
  59. {
  60. componentsInChildren[i].CrossFadeColor(targetColor, 0f, false, false);
  61. }
  62. return elementData;
  63. }
  64. private void OnEnable()
  65. {
  66. this.UpdateTrohyUI();
  67. }
  68. private void OnDisable()
  69. {
  70. if (base.gameObject == null)
  71. {
  72. return;
  73. }
  74. if (this.m_Content == null)
  75. {
  76. return;
  77. }
  78. if (this.m_PrefabElement == null)
  79. {
  80. return;
  81. }
  82. for (int i = 0; i < this.m_Content.childCount; i++)
  83. {
  84. GameObject gameObject = this.m_Content.GetChild(i).gameObject;
  85. if (!(gameObject == this.m_PrefabElement))
  86. {
  87. UnityEngine.Object.Destroy(gameObject);
  88. }
  89. }
  90. }
  91. [SerializeField]
  92. [Tooltip("トロフィーの概要を表示する要素(プレハブ)")]
  93. private GameObject m_PrefabElement;
  94. [SerializeField]
  95. [Tooltip("説明する要素を並べるUI")]
  96. private RectTransform m_Content;
  97. private class ElementData
  98. {
  99. public ElementData()
  100. {
  101. this.TextName = null;
  102. this.TextFlag = null;
  103. this.TextItem = null;
  104. }
  105. public Text TextName;
  106. public Text TextFlag;
  107. public Text TextItem;
  108. }
  109. }