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/XUISimpleList.cs | 85 +++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Client/Assets/Scripts/UICommon/XUISimpleList.cs (limited to 'Client/Assets/Scripts/UICommon/XUISimpleList.cs') diff --git a/Client/Assets/Scripts/UICommon/XUISimpleList.cs b/Client/Assets/Scripts/UICommon/XUISimpleList.cs new file mode 100644 index 00000000..24b45137 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISimpleList.cs @@ -0,0 +1,85 @@ +using UILib; +using UnityEngine; +using System; +using System.Collections.Generic; + +public class XUISimpleList : XUIObject , IXUISimpleList +{ + public enum Sorting + { + Horizontal, + Vertical, + } + + struct SimpleNode : IComparable + { + public Transform t; + public Vector3 pos; + + public int CompareTo(SimpleNode other) + { + switch (sSorting) + { + case Sorting.Horizontal: + return sRevert * pos.x.CompareTo(other.pos.x); + case Sorting.Vertical: + return sRevert * pos.y.CompareTo(other.pos.y); + } + return 0; + } + + public static Sorting sSorting = Sorting.Horizontal; + public static int sRevert = -1; + + } + + SimpleNode[] m_OriginDatas; + + public Sorting sorting = Sorting.Horizontal; + public bool IsRevert = false; + + protected override void OnAwake() + { + base.OnAwake(); + + int count = 0; + for (int i = 0; i < transform.childCount; ++i) + { + Transform child = transform.GetChild(i); + if (child && child.gameObject) + { + ++count; + } + } + + m_OriginDatas = new SimpleNode[count]; + + for (int i = 0, j = 0; i < transform.childCount; ++i) + { + Transform child = transform.GetChild(i); + if (child && child.gameObject) + { + m_OriginDatas[j].pos = child.localPosition; + m_OriginDatas[j].t = child; + ++j; + } + } + + SimpleNode.sSorting = sorting; + SimpleNode.sRevert = IsRevert ? -1 : 1; + + Array.Sort(m_OriginDatas); + } + + public void Refresh() + { + int j = 0; + for (int i = 0; i < m_OriginDatas.Length; ++i) + { + if (m_OriginDatas[i].t == null || !m_OriginDatas[i].t.gameObject.activeSelf) + continue; + + m_OriginDatas[i].t.localPosition = m_OriginDatas[j++].pos; + } + } +} -- cgit v1.1-26-g67d0