diff options
author | chai <chaifix@163.com> | 2021-05-08 23:15:13 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-05-08 23:15:13 +0800 |
commit | d07e14add74e017b52ab2371efeea1aa4ea10ced (patch) | |
tree | efd07869326e4c428f5bfe43fad0c2583d32a401 /Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs |
+init
Diffstat (limited to 'Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs')
-rw-r--r-- | Assets/UI_Extension/Scripts/LayoutGroup/GridLayoutGroupExt.cs | 153 |
1 files changed, 153 insertions, 0 deletions
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<RectTransform>(); + 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<object> m_DataList;
+ public List<object> 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<object> 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<T>(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); + } +
+ }
+
+}
|