Update Cryville.Common.

This commit is contained in:
2022-10-14 23:32:43 +08:00
parent d3cac8a28d
commit c8eee7ab3f
18 changed files with 497 additions and 47 deletions

View File

@@ -3,61 +3,84 @@ using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {
/// <summary>
/// A handler for loading an item.
/// </summary>
/// <param name="index">The zero-based index of the item.</param>
/// <param name="gameObject">The game object for the item instantiated from the item template.</param>
/// <returns></returns>
public delegate bool LoadItemHandler(int index, GameObject gameObject);
/// <summary>
/// A scrollable grid that dynamically loads its items.
/// </summary>
public sealed class ScrollableItemGrid : MonoBehaviour {
[SerializeField]
[Tooltip("The item template.")]
private GameObject m_itemTemplate;
/// <summary>
/// The item template.
/// </summary>
public GameObject ItemTemplate {
get { return m_itemTemplate; }
set { m_itemTemplate = value; OnTemplateUpdate(); }
}
public Func<int, GameObject, bool> LoadItem { private get; set; }
public enum Corner {
UpperLeft = 0,
UpperRight = 1,
LowerLeft = 2,
LowerRight = 3,
}
[SerializeField]
private Corner m_startCorner; // TODO
public Corner StartCorner {
get { return m_startCorner; }
set { m_startCorner = value; OnFrameUpdate(); }
}
/// <summary>
/// The handler for loading an item.
/// </summary>
public LoadItemHandler LoadItem { private get; set; }
/// <summary>
/// Axis.
/// </summary>
public enum Axis {
Horizontal = 0, Vertical = 1,
/// <summary>
/// Horizontal (x) axis.
/// </summary>
Horizontal = 0,
/// <summary>
/// Vertical (y) axis.
/// </summary>
Vertical = 1,
}
[SerializeField]
[Tooltip("The main axis.")]
private Axis m_startAxis;
/// <summary>
/// The main axis.
/// </summary>
public Axis StartAxis {
get { return m_startAxis; }
set { m_startAxis = value; OnFrameUpdate(); }
}
[SerializeField]
private Vector2 m_spacing; // TODO
public Vector2 Spacing {
get { return m_spacing; }
set { m_spacing = value; OnFrameUpdate(); }
}
[SerializeField]
[Tooltip("The item count.")]
private int m_itemCount = 3;
/// <summary>
/// The item count.
/// </summary>
public int ItemCount {
get { return m_itemCount; }
set { m_itemCount = value; OnRefresh(); }
}
[SerializeField]
[Tooltip("The item count per line.")]
private int m_lineItemCount = 3;
/// <summary>
/// The item count per line.
/// </summary>
public int LineItemCount {
get { return m_lineItemCount; }
set { m_lineItemCount = value; OnFrameUpdate(); }
}
[SerializeField]
[Tooltip("The length of the cross axis per line.")]
private float m_lineHeight = 100;
/// <summary>
/// The length of the cross axis per line.
/// </summary>
public float LineHeight {
get { return m_lineHeight; }
set { m_lineHeight = value; OnFrameUpdate(); }
@@ -78,6 +101,9 @@ namespace Cryville.Common.Unity.UI {
);
}
}
/// <summary>
/// The maximum count of visible lines.
/// </summary>
public int VisibleLines {
get {
return Mathf.CeilToInt(VisibleSize.y / m_lineHeight) + 1;