using System; using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class AnnounceManager { private class Content { public bool IsSprite; public string content; public TextAnchor Alignment; public Content(bool isSprite, string content, TextAnchor alignment) { this.content = content; IsSprite = isSprite; Alignment = alignment; } } #region Config public static string DefaultLanguage = "null"; public static string Hants = "Chinese"; public static string Hant = "ChineseTraditional"; public static string En = "English"; public static bool Inited; private static List Textes = new List(); private static Dictionary> ContentDictionary = new Dictionary>(); #endregion private static int SpriteSize = 300; public static void Init(string language) { Inited = true; List contents = ContentDictionary[language]; for (int i = 0; i < contents.Count; i++) { Transform transform = ResourceManager.Get(ResourceLabel.NotifyItem, Folder.UI, false, ResourceManager.Get(CanvasLabel.R_Grid), false); if (contents[i].IsSprite) { transform.GetComponent().fontSize = SpriteSize; transform.GetComponent().verticalOverflow = VerticalWrapMode.Overflow; transform.GetComponent().horizontalOverflow = HorizontalWrapMode.Overflow; transform.GetComponent().resizeTextForBestFit = false; transform.GetComponent().enabled = true; transform.GetChild(0).GetComponent().sprite = HttpManager.AnnounceSpite; } transform.GetComponent().text = contents[i].content; transform.GetComponent().alignment = contents[i].Alignment; Textes.Add(transform.GetComponent()); } } public static void ShowAnnouncePanel() { if (!Inited) { Init(GetLanguage()); } else { SwitchLanguage(GetLanguage()); } AudioManager.PlayClip(AudioLabel.Bubble); ResourceManager.Get(CanvasLabel.R_Notify).TweenForCG(); Auxiliary.Instance.DelayCall ( () => { LayoutRebuilder.MarkLayoutForRebuild(ResourceManager.Get(CanvasLabel.R_Grid)); }, 1 ); } public static void AddContent(bool isImage, string language, string content, TextAnchor alignment) { if (language == DefaultLanguage) { AddContent(isImage, En, content, alignment); AddContent(isImage, Hants, content, alignment); AddContent(isImage, Hant, content, alignment); } if (!ContentDictionary.ContainsKey(language)) { ContentDictionary.Add(language, new List()); } ContentDictionary[language].Add(new Content(isImage, content, alignment)); } public static void SwitchLanguage(string language) { for (int i = 0; i < Textes.Count; i++) { Textes[i].text = ContentDictionary[language][i].content; } } 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(); } } }