using System; using System.Collections.Generic; using UnityEngine; public class SubtitleDisplayManager : MonoBehaviour { public string charaNameText { get { return this.charaNameText_; } set { this.Awake(); if (this.charaNameText_ == value) { return; } this.charaNameText_ = ((!string.IsNullOrEmpty(value)) ? value : string.Empty); if (this.charaNameUILabel != null) { this.charaNameUILabel.text = this.charaNameText_; this.charaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(this.charaNameText_)); } if (this.singleCharaNameUILabel != null) { this.singleCharaNameUILabel.text = this.charaNameText_; this.singleCharaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(this.charaNameText_)); } } } public string originalText { get { return this.originalUILabel.text; } set { this.Awake(); if (this.originalText_ == value) { return; } this.originalUILabel.text = (this.originalText_ = ((!string.IsNullOrEmpty(value)) ? MessageClass.GetWrapString(this.originalUILabel, value) : string.Empty)); if (this.displayType_ == SubtitleDisplayManager.DisplayType.Original) { this.singleUILabel.text = this.originalText_; } } } public string subtitlesText { get { return this.subtitlesUILabel.text; } set { this.Awake(); if (this.subtitlesText_ == value) { return; } this.subtitlesUILabel.text = (this.subtitlesText_ = ((!string.IsNullOrEmpty(value)) ? value : string.Empty)); if (this.displayType_ == SubtitleDisplayManager.DisplayType.Subtitle) { this.singleUILabel.text = this.subtitlesText_; } } } public SubtitleDisplayManager.DisplayType displayType { get { return this.displayType_; } set { this.Awake(); this.displayType_ = value; this.twoTextAreaObject.SetActive(false); this.singleTextAreaObject.SetActive(false); if (this.displayType_ == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle) { this.twoTextAreaObject.SetActive(true); } else if (this.displayType_ == SubtitleDisplayManager.DisplayType.None) { if (this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.None) { if (this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle) { this.twoTextAreaObject.SetActive(true); } else if (this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Original || this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Subtitle) { this.singleTextAreaObject.SetActive(true); this.singleUILabel.text = ((this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalText_ : this.subtitlesText_); } } } else if (this.displayType_ == SubtitleDisplayManager.DisplayType.Original || this.displayType_ == SubtitleDisplayManager.DisplayType.Subtitle) { this.singleTextAreaObject.SetActive(true); this.singleUILabel.text = ((this.displayType_ != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalText_ : this.subtitlesText_); } } } public bool visible { get { return base.gameObject.activeInHierarchy; } set { base.gameObject.SetActive(value); } } public float messageBgAlpha { get { return (this.messageBgAlphaLinkWidgets == null || 0 >= this.messageBgAlphaLinkWidgets.Length) ? 0f : this.messageBgAlphaLinkWidgets[0].alpha; } set { if (this.messageBgAlphaLinkWidgets != null) { foreach (UIWidget uiwidget in this.messageBgAlphaLinkWidgets) { if (uiwidget != null && !Mathf.Approximately(uiwidget.alpha, value)) { uiwidget.alpha = value; } } } } } private float configMessageAlpha { get { return (float)(100 - GameMain.Instance.CMSystem.MsgWndAlpha) / 100f; } } private SubtitleDisplayManager.DisplayType configDisplayType { get { return GameMain.Instance.CMSystem.SubtitleType; } set { GameMain.Instance.CMSystem.SubtitleType = value; } } private void Awake() { if (this.callAwake) { return; } this.callAwake = true; string text = string.Empty; this.charaNameText = text; text = text; this.subtitlesText = text; this.originalText = text; this.displayType = this.configDisplayType; this.messageBgAlpha = this.configMessageAlpha; } public void SetTextFromScriptStyle(string text) { if (string.IsNullOrEmpty(text)) { string empty = string.Empty; this.subtitlesText = empty; this.originalText = empty; return; } KeyValuePair translationText = MessageClass.GetTranslationText(text); this.originalText = translationText.Key; this.subtitlesText = translationText.Value; } public void Update() { if (this.messageBgAlpha != this.configMessageAlpha) { this.messageBgAlpha = this.configMessageAlpha; } if (this.displayType != this.configDisplayType) { this.displayType = this.configDisplayType; } } [Header("日本語と翻訳,2テキスト表示する時の設定")] [SerializeField] private GameObject twoTextAreaObject; [SerializeField] private UILabel charaNameUILabel; [SerializeField] private UILabel originalUILabel; [SerializeField] private UILabel subtitlesUILabel; [Header("日本語 or 翻訳の1テキストのみ表示する時の設定")] [SerializeField] private GameObject singleTextAreaObject; [SerializeField] private UILabel singleCharaNameUILabel; [SerializeField] private UILabel singleUILabel; [Header("メッセージ背景不透明度とリンクされるWidget")] [SerializeField] private UIWidget[] messageBgAlphaLinkWidgets; [Header("None指定の時、特定のタイプに動作をオーバーライドする設定")] [SerializeField] private SubtitleDisplayManager.DisplayType hideTypeOverRide; private bool callAwake; private string charaNameText_; private string originalText_; private string subtitlesText_; private SubtitleDisplayManager.DisplayType displayType_; public enum DisplayType { None, OriginalAndSubtitle, Subtitle, Original } public static class EnumConvert { public static string GetString(SubtitleDisplayManager.DisplayType displayType) { string result = "表示しない"; if (displayType == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle) { result = "両方表示"; } else if (displayType == SubtitleDisplayManager.DisplayType.Original) { result = "日本語のみ"; } else if (displayType == SubtitleDisplayManager.DisplayType.Subtitle) { result = "英語のみ"; } return result; } } }