123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using Object = UnityEngine.Object;
- public class NotifyItem
- {
- public virtual GameObject Create()
- {
- throw new Exception();
- }
- }
- public class NotifyTitle : NotifyItem
- {
- public string text;
- public NotifyTitle(string text)
- {
- this.text = text;
- }
- public override GameObject Create()
- {
- Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
- Transform trans = ResourceManager.Get(ResourceLabel.NotifyTitle, Folder.UI, false, parent, false);
- Text text = trans.GetComponent<Text>();
- text.text = this.text;
- return trans.gameObject;
- }
- }
- public class NotifyDate : NotifyItem
- {
- public string text;
- public NotifyDate(string text)
- {
- this.text = text;
- }
- public override GameObject Create()
- {
- Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
- Transform trans = ResourceManager.Get(ResourceLabel.NotifyDate, Folder.UI, false, parent, false);
- Text text = trans.GetComponent<Text>();
- text.text = this.text;
- return trans.gameObject;
- }
- }
- public class NotifyContent : NotifyItem
- {
- public string text;
- public NotifyContent(string text)
- {
- this.text = text;
- }
- public override GameObject Create()
- {
- Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
- Transform trans = ResourceManager.Get(ResourceLabel.NotifyContent, Folder.UI, false, parent, false);
- Text text = trans.GetComponent<Text>();
- text.text = this.text;
- return trans.gameObject;
- }
- }
- public class NotifyImage : NotifyItem
- {
- public string spriteName;
- public NotifyImage(string spriteName)
- {
- this.spriteName = spriteName;
- }
- public override GameObject Create()
- {
- Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
- Transform trans = ResourceManager.Get(ResourceLabel.NotifyImage, Folder.UI, false, parent, false);
- Image image = trans.GetComponent<Image>();
- image.sprite = HttpManager.AnnounceSpiteDict[spriteName];
- image.SetNativeSize();
- if (image.rectTransform.rect.width > 580)
- {
- Vector2 newSize = new Vector2();
- newSize.x = 580;
- newSize.y = image.rectTransform.rect.height*580/image.rectTransform.rect.width;
- image.rectTransform.sizeDelta = newSize;
- }
- return trans.gameObject;
- }
- }
- public class AnnounceManager
- {
- #region Config
- public static string DefaultLanguage = "null";
- public static string Hans = "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 List<GameObject> itemGos = new List<GameObject>();
- private static Dictionary<string, List<NotifyItem>> ItemDict = new Dictionary<string, List<NotifyItem>>();
- #endregion
- private static int SpriteSize = 300;
- public static void Init(string language)
- {
- foreach (var item in itemGos)
- {
- Object.DestroyImmediate(item);
- }
- itemGos = new List<GameObject>();
- List<NotifyItem> notifyItems = ItemDict[language];
- foreach (var notifyItem in notifyItems)
- {
- GameObject itemGo = notifyItem.Create();
- itemGos.Add(itemGo);
- }
- //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 AddItem(string language, NotifyItem item)
- {
- if (language == DefaultLanguage)
- {
- AddItem(En, item);
- AddItem(Hans, item);
- AddItem(Hant, item);
- }
- if (!ItemDict.ContainsKey(language))
- {
- ItemDict.Add(language, new List<NotifyItem>());
- }
- ItemDict[language].Add(item);
- }
- //public static void AddContent(bool isImage, string language, string content, TextAnchor alignment)
- //{
- // if (language == DefaultLanguage)
- // {
- // AddContent(isImage, En, content, alignment);
- // AddContent(isImage, Hans, content, alignment);
- // AddContent(isImage, Hant, content, alignment);
- // }
- // if (!ItemDict.ContainsKey(language))
- // {
- // ItemDict.Add(language, new List<Content>());
- // }
- // ItemDict[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 Hans;
- }
- else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
- {
- return Hant;
- }
- else if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
- {
- return En;
- }
- else
- {
- throw new Exception();
- }
- }
- }
|