DanceSubtitleMgr.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using I2.Loc;
  4. using UnityEngine;
  5. public class DanceSubtitleMgr : PartsMgrBase
  6. {
  7. protected override void Start()
  8. {
  9. base.Start();
  10. base.IsActive &= (DanceMain.SelectDanceData != null);
  11. base.IsActive &= DanceSetting.Settings.IsSubtitleOn;
  12. base.IsActive &= !Product.isJapan;
  13. if (!base.IsActive)
  14. {
  15. base.gameObject.SetActive(false);
  16. return;
  17. }
  18. this.m_SubtitleUI.SetActive(false);
  19. string csv_path = RhythmAction_Mgr.Instance.MusicCSV_Path + "dance_subtitle.nei";
  20. KasaiUtility.CsvReadY(csv_path, delegate(CsvParser csv, int cy)
  21. {
  22. int num = 0;
  23. DanceSubtitleMgr.SubtitleData subtitleData = new DanceSubtitleMgr.SubtitleData();
  24. subtitleData.ID = csv.GetCellAsInteger(num++, cy);
  25. subtitleData.StartTime = csv.GetCellAsReal(num++, cy);
  26. subtitleData.EndTime = csv.GetCellAsReal(num++, cy);
  27. subtitleData.TranslationKey = csv.GetCellAsString(num++, cy);
  28. this.m_SubtitleDataList.Add(subtitleData);
  29. }, 1, delegate
  30. {
  31. this.IsActive = false;
  32. Debug.Log(csv_path + "が見つからなかったので、ダンスの字幕を非表示にします。");
  33. this.gameObject.SetActive(false);
  34. });
  35. }
  36. private void DrawSubtitle()
  37. {
  38. float danceTimer = RhythmAction_Mgr.Instance.DanceTimer;
  39. string sheet_name = DanceMain.SelectDanceData.SubtitleSheetName + "/";
  40. Product.Language systemLanguage = Product.systemLanguage;
  41. using (List<DanceSubtitleMgr.SubtitleData>.Enumerator enumerator = this.m_SubtitleDataList.GetEnumerator())
  42. {
  43. while (enumerator.MoveNext())
  44. {
  45. DanceSubtitleMgr.SubtitleData data = enumerator.Current;
  46. if (data.EndTime <= danceTimer)
  47. {
  48. if (data.IsExistUIObj)
  49. {
  50. data.DestroyUIObj();
  51. this.m_SubtitleUIGrid.UpdateChildUI();
  52. }
  53. }
  54. else if (data.StartTime <= danceTimer && !data.IsExistUIObj)
  55. {
  56. bool create_success = false;
  57. Action<Product.Language> action = delegate(Product.Language langage)
  58. {
  59. string term = sheet_name + data.TranslationKey;
  60. string translation = LocalizationManager.GetTranslation(term, true, 0, true, false, null, Product.EnumConvert.ToI2LocalizeLanguageName(langage));
  61. if (string.IsNullOrEmpty(translation))
  62. {
  63. return;
  64. }
  65. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_SubtitleUI, this.m_SubtitleUIGrid.transform, false);
  66. gameObject.SetActive(true);
  67. data.SetUIObj(langage, gameObject);
  68. UILabel component = gameObject.GetComponent<UILabel>();
  69. component.text = translation;
  70. if (component.width > this.m_NewLineWidthSize)
  71. {
  72. component.overflowMethod = UILabel.Overflow.ResizeHeight;
  73. component.width = this.m_NewLineWidthSize;
  74. component.ProcessText();
  75. }
  76. create_success |= true;
  77. };
  78. if (Product.supportMultiLanguage)
  79. {
  80. switch (DanceSetting.Settings.SubtitleType)
  81. {
  82. case SubtitleDisplayManager.DisplayType.OriginalAndSubtitle:
  83. action(Product.Language.Japanese);
  84. action(systemLanguage);
  85. break;
  86. case SubtitleDisplayManager.DisplayType.Subtitle:
  87. action(systemLanguage);
  88. break;
  89. case SubtitleDisplayManager.DisplayType.Original:
  90. action(Product.Language.Japanese);
  91. break;
  92. }
  93. }
  94. else
  95. {
  96. action(Product.Language.Japanese);
  97. }
  98. if (create_success)
  99. {
  100. this.m_SubtitleUIGrid.UpdateChildUI();
  101. }
  102. }
  103. }
  104. }
  105. }
  106. public override void StartAction()
  107. {
  108. RhythmAction_Mgr.Instance.StartTimeCroutine(new Action(this.DrawSubtitle), null);
  109. }
  110. private List<DanceSubtitleMgr.SubtitleData> m_SubtitleDataList = new List<DanceSubtitleMgr.SubtitleData>();
  111. [SerializeField]
  112. [Header("使い回し用オブジェクト")]
  113. private GameObject m_SubtitleUI;
  114. [SerializeField]
  115. [Header("字幕UIの親")]
  116. private DynamicUIGrid m_SubtitleUIGrid;
  117. [SerializeField]
  118. [Header("表示領域の横サイズがこれ以上になったら改行")]
  119. private int m_NewLineWidthSize = 930;
  120. private class SubtitleData
  121. {
  122. public bool IsExistUIObj
  123. {
  124. get
  125. {
  126. return this.OrijinalUI != null || this.SubtitleUI != null;
  127. }
  128. }
  129. public void SetUIObj(Product.Language langage_code, GameObject ui_obj)
  130. {
  131. if (langage_code == Product.Language.Japanese)
  132. {
  133. this.OrijinalUI = ui_obj;
  134. }
  135. else
  136. {
  137. this.SubtitleUI = ui_obj;
  138. }
  139. }
  140. public void DestroyUIObj()
  141. {
  142. if (this.OrijinalUI)
  143. {
  144. UnityEngine.Object.DestroyImmediate(this.OrijinalUI);
  145. }
  146. if (this.SubtitleUI)
  147. {
  148. UnityEngine.Object.DestroyImmediate(this.SubtitleUI);
  149. }
  150. }
  151. public int ID;
  152. public float StartTime;
  153. public float EndTime;
  154. public string TranslationKey;
  155. public GameObject OrijinalUI;
  156. public GameObject SubtitleUI;
  157. }
  158. }