From d07e14add74e017b52ab2371efeea1aa4ea10ced Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 8 May 2021 23:15:13 +0800 Subject: +init --- .../Scripts/LayoutGroup/GridLayoutGroupExt.cs | 153 +++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs (limited to 'Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs') diff --git a/Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs b/Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs new file mode 100644 index 0000000..9d202b9 --- /dev/null +++ b/Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs @@ -0,0 +1,153 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using UnityEditor; + +namespace UIExt +{ + [AddComponentMenu("UI Extensions/LayoutGroup/GridLayoutGroupExt")] + [DisallowMultipleComponent] + [CanEditMultipleObjects] + public class GridLayoutGroupExt + : UIBehaviour + , ILayoutElement + , ILayoutGroup + { + public enum ScrollMode + { + Vertical = 1, + Horizontal = 2, + Auto = 3 // both horizontal and vertical + } + + public enum MovementType + { + Unrestricted, // Unrestricted movement -- can scroll forever + Elastic, // Restricted but flexible -- can go past the edges, but springs back in place + Clamped, // Restricted movement where it's not possible to go past the edges + } + + [System.NonSerialized] private RectTransform m_Rect; + protected RectTransform rectTransform + { + get + { + if (m_Rect == null) + m_Rect = GetComponent(); + return m_Rect; + } + } + + [SerializeField] private ScrollRect m_Scrollrect; + public ScrollRect scrollRect { get { return m_Scrollrect; } set { m_Scrollrect = value; } } + + [SerializeField] private RectTransform m_Content; + public RectTransform content { get { return m_Content; } set { m_Content = value; } } + + [SerializeField] private LayoutItem m_ItemTemplate; + public LayoutItem itemTemplate { get { return m_ItemTemplate; } set { m_ItemTemplate = value; } } + + [SerializeField] private int m_RowCount; + public int rowCount { get { return m_RowCount; } set { m_RowCount = value; } } + [SerializeField] private int m_ColumCount; + public int columCount { get { return m_ColumCount; } set { m_ColumCount = value; } } + + [SerializeField] protected RectOffset m_Padding = new RectOffset(); + public RectOffset padding { get { return m_Padding; } set { SetProperty(ref m_Padding, value); } } + + [SerializeField] private Vector2Int m_CellSize; + public Vector2Int cellSize { get { return m_CellSize; } set { m_CellSize = value; } } + + [SerializeField] private Vector2Int m_Spacing; + public Vector2Int spacing { get { return m_Spacing; } set { m_Spacing = value; } } + + [SerializeField] private ScrollMode m_ScrollMode = ScrollMode.Vertical; + + [SerializeField] private MovementType m_MovementType = MovementType.Elastic; + + private List m_DataList; + public List dataList { get { return m_DataList; } } + + public float minWidth + { + get + { + throw new System.NotImplementedException(); + } + } + + public float preferredWidth { get { return 0; } } + + public float flexibleWidth { get { return 0; } } + + public float minHeight { get { return 0; } } + + public float preferredHeight { get { return 0; } } + + public float flexibleHeight { get { return 0; } } + + public int layoutPriority { get { return 0; } } + + public void SetList(List datalist) + { + m_DataList = datalist; + } + + public void MoveTo(int indexOfData) + { + + } + + public void MoveTo(object data) + { + + } + + public void CalculateLayoutInputHorizontal() + { + + } + + public void CalculateLayoutInputVertical() + { + + } + + public void SetLayoutHorizontal() + { + } + + public void SetLayoutVertical() + { + } + + protected void SetProperty(ref T currentValue, T newValue) + { + if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) + return; + currentValue = newValue; + SetDirty(); + } + + protected void SetDirty() + { + if (!IsActive()) + return; + + if (!CanvasUpdateRegistry.IsRebuildingLayout()) + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + else + StartCoroutine(DelayedSetDirty(rectTransform)); + } + + IEnumerator DelayedSetDirty(RectTransform rectTransform) + { + yield return null; + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + } + + } + +} -- cgit v1.1-26-g67d0