123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 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<Text> Textes = new List<Text>();
- private static Dictionary<string, List<Content>> ContentDictionary = new Dictionary<string, List<Content>>();
- #endregion
- private static int SpriteSize = 300;
- public static void Init(string language)
- {
- Inited = true;
- List<Content> 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<Text>().fontSize = SpriteSize;
- 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.AnnounceSpite;
- }
- transform.GetComponent<Text>().text = contents[i].content;
- transform.GetComponent<Text>().alignment = contents[i].Alignment;
- Textes.Add(transform.GetComponent<Text>());
- }
- }
- 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<RectTransform>(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<Content>());
- }
- 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();
- }
- }
- }
|