123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- public class AnnounceManager
- {
- private class Content
- {
- public bool IsImage;
- public string text;
- public TextAnchor Alignment;
- public Content(bool isImage, string text, TextAnchor alignment)
- {
- this.text = text;
- this.IsImage = isImage;
- this.Alignment = alignment;
- }
- }
- #region Config
- public static string DefaultLanguage = "null";
- public static string Hants = "Chinese";
- public static string Hant = "ChineseTraditional";
- public static string En = "English";
- #endregion
- public static bool Initialized;
- private static List<Text> TextList = new List<Text>();
- private static Dictionary<string, List<Content>> ContentsDic = new Dictionary<string, List<Content>>();
- public static void AddLine(bool isImage, string language, string content, TextAnchor alignment)
- {
- if (language == DefaultLanguage)
- {
- AddLine(isImage, En, content, alignment);
- AddLine(isImage, Hants, content, alignment);
- AddLine(isImage, Hant, content, alignment);
- }
- if (!ContentsDic.ContainsKey(language))
- {
- ContentsDic.Add(language, new List<Content>());
- }
- ContentsDic[language].Add(new Content(isImage, content, alignment));
- }
- public static void Show()
- {
- if (!Initialized)
- {
- Initialize(GetLanguage());
- }
- else
- {
- SwitchLanguage(GetLanguage());
- }
- AudioManager.PlayClip(Clip.BubbleClip);
- ResourceManager.Get(ObjectLabel.R_Notify).TweenForCG();
- Auxiliary.Instance.DelayCall
- (
- () =>
- {
- ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.R_Grid).CalculateLayoutInputVertical();
- ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.R_Grid).SetLayoutVertical();
- },
- 1
- );
- }
- public static void Initialize(string language)
- {
- Initialized = true;
- List<Content> contents = ContentsDic[language];
- for (int i = 0; i < contents.Count; i++)
- {
- Transform transform = ResourceManager.Get("NotifyItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.R_Grid), false);
- if (contents[i].IsImage)
- {
- transform.GetComponent<Text>().fontSize = 300;
- transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
- transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
- transform.GetComponent<Text>().resizeTextForBestFit = false;
- transform.GetComponent<ContentSizeFitter>().enabled = true;
- transform.GetChild(0).GetComponent<Image>().sprite = HttpManager.NotificationSprite;
- }
- transform.GetComponent<Text>().text = contents[i].text;
- transform.GetComponent<Text>().alignment = contents[i].Alignment;
- TextList.Add(transform.GetComponent<Text>());
- }
- }
- public static void SwitchLanguage(string language)
- {
- for (int i = 0; i < TextList.Count; i++)
- {
- TextList[i].text = ContentsDic[language][i].text;
- }
- }
- public static string GetLanguage()
- {
- if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
- {
- return Hants;
- }
- else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
- {
- return Hant;
- }
- else if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
- {
- return En;
- }
- else
- {
- throw new Exception();
- }
- }
- }
|