فهرست منبع

修改公告布局

LiuQilin 7 سال پیش
والد
کامیت
fe7d483e97

+ 4 - 0
Assets/Resource/Prefab/Object/DebugMode.prefab

@@ -165,6 +165,10 @@ MonoBehaviour:
   - {fileID: 1266546654056180, guid: 7f826c7f4c27c8d44afe9f47f9705a59, type: 2}
   - {fileID: 1178346060137818, guid: e2d62becad3f170428db59673f313354, type: 2}
   - {fileID: 1178346060137818, guid: e2d62becad3f170428db59673f313354, type: 2}
+  - {fileID: 1001614888670902, guid: b3735629db90d5c42acd23018f34baa1, type: 2}
+  - {fileID: 1464068286795752, guid: 42200e1913f63a147a8bd9f0e1ff7c5f, type: 2}
+  - {fileID: 1173200693923306, guid: 3cbac8864a3ca4a4fbee23187ed8b18d, type: 2}
+  - {fileID: 1523257016453190, guid: 4267e2a622c30f343b2a61c510f2afbb, type: 2}
   AtlasList:
   - {fileID: 21300004, guid: b31bbacb2e0ff3d459f4878983a39b50, type: 3}
   - {fileID: 21300006, guid: b31bbacb2e0ff3d459f4878983a39b50, type: 3}

+ 2 - 2
Assets/Resource/Prefab/PrefabUI/NotifyImage.prefab

@@ -76,6 +76,6 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
-  m_AnchoredPosition: {x: 0, y: 0}
+  m_AnchoredPosition: {x: 0, y: 50}
   m_SizeDelta: {x: 100, y: 100}
-  m_Pivot: {x: 0.5, y: 0.5}
+  m_Pivot: {x: 0.5, y: 0.99999994}

+ 139 - 30
Assets/Script/Manage/AnnounceManager.cs

@@ -4,41 +4,134 @@ using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
+using Object = UnityEngine.Object;
 
-public class AnnounceManager
+public class NotifyItem
+{
+    public virtual GameObject Create()
+    {
+        throw new Exception();
+    }
+}
+
+public class NotifyTitle : NotifyItem
 {
-    private class Content
+    public string text;
+
+    public NotifyTitle(string text)
     {
-        public bool IsSprite;
-        public string content;
-        public TextAnchor Alignment;
+        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 Content(bool isSprite, string content, TextAnchor alignment)
+    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)
         {
-            this.content = content;
-            IsSprite = isSprite;
-            Alignment = alignment;
+            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 Hants = "Chinese";
+    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 Dictionary<string, List<Content>> ContentDictionary = new Dictionary<string, List<Content>>();
+    //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)
     {
-        Inited = true;
+        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];
 
@@ -73,7 +166,7 @@ public class AnnounceManager
         }
         else
         {
-            SwitchLanguage(GetLanguage());
+            //SwitchLanguage(GetLanguage());
         }
 
         AudioManager.PlayClip(AudioLabel.Bubble);
@@ -90,37 +183,53 @@ public class AnnounceManager
         );
     }
 
-
-    public static void AddContent(bool isImage, string language, string content, TextAnchor alignment)
+    public static void AddItem(string language, NotifyItem item)
     {
         if (language == DefaultLanguage)
         {
-            AddContent(isImage, En, content, alignment);
-            AddContent(isImage, Hants, content, alignment);
-            AddContent(isImage, Hant, content, alignment);
+            AddItem(En, item);
+            AddItem(Hans, item);
+            AddItem(Hant, item);
         }
 
-        if (!ContentDictionary.ContainsKey(language))
+        if (!ItemDict.ContainsKey(language))
         {
-            ContentDictionary.Add(language, new List<Content>());
+            ItemDict.Add(language, new List<NotifyItem>());
         }
 
-        ContentDictionary[language].Add(new Content(isImage, content, alignment));
+        ItemDict[language].Add(item);
     }
 
-    public static void SwitchLanguage(string language)
-    {
-        for (int i = 0; i < Textes.Count; i++)
-        {
-            Textes[i].text = ContentDictionary[language][i].content;
-        }
-    }
+    //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 Hants;
+            return Hans;
         }
         else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
         {

+ 57 - 36
Assets/Script/Manage/HttpManager.cs

@@ -126,7 +126,7 @@ public class HttpManager : Regist
     public static int AnnounceIndex = -1;
     public static bool IsAnnounceReady;
     public static string AnnounceContent;
-    public static Sprite AnnounceSpite;
+    public static Dictionary<string, Sprite> AnnounceSpiteDict = new Dictionary<string, Sprite>();
 
     public static Button WifiButton;
 
@@ -516,6 +516,8 @@ public class HttpManager : Regist
         XmlNode rootNode;
         XmlDocument document = new XmlDocument();
 
+        //Debug.Log(xml);
+
         //Debug.Log((int)xml[0]);
         //Debug.Log((int)xml[xml.Length-1]);
         //Debug.Log((int)xml[xml.Length - 2]);
@@ -530,7 +532,7 @@ public class HttpManager : Regist
         {
             document.LoadXml(xml);
 
-            Debug.Log(document.OuterXml);
+            //Debug.Log(document.OuterXml);
 
             rootNode = document.SelectSingleNode("announce");
 
@@ -560,35 +562,44 @@ public class HttpManager : Regist
 
     public static void DecodeAnnounceData(XmlNode node, List<string> urlList)
     {
-        //Debug.Log(node.InnerText);
+        //Debug.Log(node.OuterXml);
+
         XmlNodeList nodeList = node.SelectNodes("title");
         
         for (int i = 0; i < nodeList.Count; i++)
         {
-            AnnounceManager.AddContent(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
+            string language = nodeList[i].Attributes[0].Value;
+            NotifyTitle notifyTitle = new NotifyTitle(nodeList[i].InnerText);
+            AnnounceManager.AddItem(language, notifyTitle);
+            //AnnounceManager.AddContent(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
         }
 
-        AnnounceManager.AddContent(false, "null", node.SelectSingleNode("date").InnerText, TextAnchor.MiddleLeft);
+        NotifyDate notifyDate = new NotifyDate(node.SelectSingleNode("date").InnerText);
+        AnnounceManager.AddItem("null", notifyDate);
+        //AnnounceManager.AddContent(false, "null", node.SelectSingleNode("date").InnerText, TextAnchor.MiddleLeft);
 
         nodeList = node.SelectSingleNode("content").ChildNodes;
 
         for (int i = 0; i < nodeList.Count; i++)
         {
-            //Debug.Log(nodeList[i].Name);
-            //Debug.LogWarning(nodeList[i].Value);
             if (nodeList[i].Name == "text")
             {
-                AnnounceManager.AddContent(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
+                string language = nodeList[i].Attributes[0].Value;
+                NotifyContent notifyContent = new NotifyContent(nodeList[i].InnerText);
+                AnnounceManager.AddItem(language, notifyContent);
+                //AnnounceManager.AddContent(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
             }
             else if (nodeList[i].Name == "image")
             {
                 urlList.UniqueAdd(nodeList[i].InnerText);
 
-                AnnounceManager.AddContent(true, "null", $"<({Path.GetFileNameWithoutExtension(nodeList[i].InnerText)})>", TextAnchor.MiddleCenter);
+                NotifyImage notifyImage = new NotifyImage(Path.GetFileNameWithoutExtension(nodeList[i].InnerText));
+                AnnounceManager.AddItem(nodeList[i].Attributes[0].Value, notifyImage);
+                //AnnounceManager.AddContent(true, "null", $"<({Path.GetFileNameWithoutExtension(nodeList[i].InnerText)})>", TextAnchor.MiddleCenter);
             }
         }
 
-        AnnounceManager.AddContent(false, "null", "", TextAnchor.MiddleLeft);
+        //AnnounceManager.AddContent(false, "null", "", TextAnchor.MiddleLeft);
     }
 
     public static IEnumerator PullAnnounceSprite(List<string> urlList, Action<List<WWW>> callback)
@@ -610,43 +621,53 @@ public class HttpManager : Regist
 
     public static void PullAnnounceSpriteCallback(List<WWW> wwwList)
     {
-        List<Texture2D> textureList = new List<Texture2D>();
-        List<SpriteInfo> spriteInfoList = new List<SpriteInfo>();
-
         for (int i = 0; i < wwwList.Count; i++)
         {
-            textureList.Add(wwwList[i].texture);
+            Texture2D texture = wwwList[i].texture;
+            Sprite sprite = Sprite.Create(wwwList[i].texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
+            sprite.name = Path.GetFileNameWithoutExtension(wwwList[i].url);
+            AnnounceSpiteDict.Add(sprite.name, sprite);
+            //Debug.Log(sprite.name);
+        }
+        IsAnnounceReady = true;
 
-            SpriteInfo spriteInfo = new SpriteInfo();
-            spriteInfo.Name = Path.GetFileNameWithoutExtension(wwwList[i].url);
+        //List<Texture2D> textureList = new List<Texture2D>();
+        //List<SpriteInfo> spriteInfoList = new List<SpriteInfo>();
 
-            spriteInfoList.Add(spriteInfo);
-        }
+        //for (int i = 0; i < wwwList.Count; i++)
+        //{
+        //    textureList.Add(wwwList[i].texture);
 
-        Texture2D atlas = new Texture2D(2048, 2048);
+        //    SpriteInfo spriteInfo = new SpriteInfo();
+        //    spriteInfo.Name = Path.GetFileNameWithoutExtension(wwwList[i].url);
 
-        Rect[] rects = atlas.PackTextures(textureList.ToArray(), 1);
+        //    spriteInfoList.Add(spriteInfo);
+        //}
 
-        Sprite sprite = Sprite.Create(atlas, new Rect(0, 0, atlas.width, atlas.height), new Vector2(0.5f, 0.5f));
+        //Texture2D atlas = new Texture2D(2048, 2048);
 
-        for (int i = 0; i < spriteInfoList.Count; i++)
-        {
-            spriteInfoList[i].Width = textureList[i].width;
-            spriteInfoList[i].Height = textureList[i].height;
+        //Rect[] rects = atlas.PackTextures(textureList.ToArray(), 1);
 
-            spriteInfoList[i].UvList = new List<Vector2>()
-            {
-                new Vector2(rects[i].xMin, rects[i].yMax),
-                new Vector2(rects[i].xMax, rects[i].yMax),
-                new Vector2(rects[i].xMax, rects[i].yMin),
-                new Vector2(rects[i].xMin, rects[i].yMin),
-            };
+        //Sprite sprite = Sprite.Create(atlas, new Rect(0, 0, atlas.width, atlas.height), new Vector2(0.5f, 0.5f));
 
-            SpriteAsset.SpriteInfoDic.Add(spriteInfoList[i].Name, spriteInfoList[i]);
-        }
+        //for (int i = 0; i < spriteInfoList.Count; i++)
+        //{
+        //    spriteInfoList[i].Width = textureList[i].width;
+        //    spriteInfoList[i].Height = textureList[i].height;
 
-        AnnounceSpite = sprite;
-        IsAnnounceReady = true;
+        //    spriteInfoList[i].UvList = new List<Vector2>()
+        //    {
+        //        new Vector2(rects[i].xMin, rects[i].yMax),
+        //        new Vector2(rects[i].xMax, rects[i].yMax),
+        //        new Vector2(rects[i].xMax, rects[i].yMin),
+        //        new Vector2(rects[i].xMin, rects[i].yMin),
+        //    };
+
+        //    SpriteAsset.SpriteInfoDic.Add(spriteInfoList[i].Name, spriteInfoList[i]);
+        //}
+
+        //AnnounceSpite = sprite;
+        //IsAnnounceReady = true;
 
         if (Initializer.Inited)
         {