DanceSubtitleMgr.cs 4.6 KB

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