From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs (limited to 'Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs') diff --git a/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs b/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs new file mode 100644 index 00000000..81ecac3d --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using UnityEngine; +using System; +[ExecuteInEditMode] +public class XUIAtlasSelector : MonoBehaviour { + + [Serializable] + public class AtlasInfo + { + [SerializeField] + public string atlasName; + [SerializeField] + public int startDepth = 0; + [SerializeField] + public List list = new List(); + } + + [SerializeField] + public Dictionary atlasInfos; + [SerializeField] + public int widgetSize = 0; + + // Use this for initialization + void Start () { + Setup(); + } + [ContextMenu("Execute")] + public void Excute() + { + Setup(); + } + + private void Setup() + { + if (atlasInfos == null) atlasInfos = new Dictionary(); + UISprite[] uiSprites = transform.GetComponentsInChildren(); + widgetSize = uiSprites.Length; + UISprite widget; + string nullAtlas = "NullAtlas"; + int i, length; + for (i = 0,length = uiSprites.Length; i < length; i++) + { + widget = uiSprites[i]; + if (widget.atlas != null) + { + Insert(atlasInfos, widget.atlas.name, widget); + } + else + { + Insert(atlasInfos, nullAtlas, widget); + } + } + string fontName = "Font"; + UILabel[] fonts = transform.GetComponentsInChildren(); + widgetSize += fonts.Length; + for (i = 0, length = fonts.Length; i < length; i++) + { + if(fonts[i].bitmapFont != null) + { + Insert(atlasInfos, "bitmapFont:" + fontName, fonts[i]); + } + else + { + Insert(atlasInfos, fontName, fonts[i]); + } + + } + foreach (KeyValuePair info in atlasInfos) + { + info.Value.list.Sort(SortCompare); + if (info.Value.list.Count > 0) + { + info.Value.startDepth = info.Value.list[0].depth; + } + } + } + + private int SortCompare(UIWidget widget1, UIWidget widget2 ) + { + return widget1.depth - widget2.depth; + } + + private void Insert(Dictionary infos ,string atlasName , UIWidget widget) + { + AtlasInfo info; + if(!infos.TryGetValue(atlasName,out info)) + { + info = new AtlasInfo(); + info.atlasName = atlasName; + infos.Add(atlasName,info); + } + info.list.Add(widget); + } + + // Update is called once per frame + void Update () { + + } +} -- cgit v1.1-26-g67d0