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 = 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 = 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 = 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.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 Textes = new List(); private static List itemGos = new List(); private static Dictionary> ItemDict = new Dictionary>(); #endregion private static int SpriteSize = 300; public static void Init(string language) { foreach (var item in itemGos) { Object.DestroyImmediate(item); } itemGos = new List(); List notifyItems = ItemDict[language]; foreach (var notifyItem in notifyItems) { GameObject itemGo = notifyItem.Create(); itemGos.Add(itemGo); } //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 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()); } 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()); // } // 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(); } } }