修改RecyclerView
This commit is contained in:
parent
52bc0b3319
commit
bbee53ccf6
@ -7,6 +7,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
public class RecyclerView : MonoBehaviour
|
public class RecyclerView : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private Direction direction;
|
[SerializeField] private Direction direction;
|
||||||
|
|
||||||
public Direction Direction
|
public Direction Direction
|
||||||
{
|
{
|
||||||
get => direction;
|
get => direction;
|
||||||
@ -14,6 +15,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private Alignment alignment;
|
[SerializeField] private Alignment alignment;
|
||||||
|
|
||||||
public Alignment Alignment
|
public Alignment Alignment
|
||||||
{
|
{
|
||||||
get => alignment;
|
get => alignment;
|
||||||
@ -21,6 +23,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private Vector2 spacing;
|
[SerializeField] private Vector2 spacing;
|
||||||
|
|
||||||
public Vector2 Spacing
|
public Vector2 Spacing
|
||||||
{
|
{
|
||||||
get => spacing;
|
get => spacing;
|
||||||
@ -28,6 +31,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private Vector2 padding;
|
[SerializeField] private Vector2 padding;
|
||||||
|
|
||||||
public Vector2 Padding
|
public Vector2 Padding
|
||||||
{
|
{
|
||||||
get => padding;
|
get => padding;
|
||||||
@ -35,6 +39,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private bool scroll;
|
[SerializeField] private bool scroll;
|
||||||
|
|
||||||
public bool Scroll
|
public bool Scroll
|
||||||
{
|
{
|
||||||
get => scroll;
|
get => scroll;
|
||||||
@ -42,6 +47,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private bool snap;
|
[SerializeField] private bool snap;
|
||||||
|
|
||||||
public bool Snap
|
public bool Snap
|
||||||
{
|
{
|
||||||
get => snap;
|
get => snap;
|
||||||
@ -49,6 +55,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField, Range(1f, 50f)] private float scrollSpeed = 7f;
|
[SerializeField, Range(1f, 50f)] private float scrollSpeed = 7f;
|
||||||
|
|
||||||
public float ScrollSpeed
|
public float ScrollSpeed
|
||||||
{
|
{
|
||||||
get => scrollSpeed;
|
get => scrollSpeed;
|
||||||
@ -56,6 +63,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField, Range(10f, 50f)] private float wheelSpeed = 30f;
|
[SerializeField, Range(10f, 50f)] private float wheelSpeed = 30f;
|
||||||
|
|
||||||
public float WheeelSpeed
|
public float WheeelSpeed
|
||||||
{
|
{
|
||||||
get => wheelSpeed;
|
get => wheelSpeed;
|
||||||
@ -63,6 +71,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private ViewHolder[] templates;
|
[SerializeField] private ViewHolder[] templates;
|
||||||
|
|
||||||
public ViewHolder[] Templates
|
public ViewHolder[] Templates
|
||||||
{
|
{
|
||||||
get => templates;
|
get => templates;
|
||||||
@ -76,6 +85,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
|
|
||||||
private int startIndex, endIndex;
|
private int startIndex, endIndex;
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
|
|
||||||
public int CurrentIndex
|
public int CurrentIndex
|
||||||
{
|
{
|
||||||
get => currentIndex;
|
get => currentIndex;
|
||||||
@ -85,6 +95,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
public bool CanScroll => true;
|
public bool CanScroll => true;
|
||||||
|
|
||||||
private RectTransform content;
|
private RectTransform content;
|
||||||
|
|
||||||
public RectTransform Content
|
public RectTransform Content
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -93,6 +104,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
{
|
{
|
||||||
content = transform.GetChild(0).GetComponent<RectTransform>();
|
content = transform.GetChild(0).GetComponent<RectTransform>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,6 +130,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
ConfigScroller();
|
ConfigScroller();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return scroller;
|
return scroller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,6 +149,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
scrollbar.gameObject.AddComponent<ScrollbarEx>().OnDragEnd = OnScrollbarDragEnd;
|
scrollbar.gameObject.AddComponent<ScrollbarEx>().OnDragEnd = OnScrollbarDragEnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return scrollbar;
|
return scrollbar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,6 +250,14 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < templates.Length; i++)
|
||||||
|
{
|
||||||
|
templates[i].gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
viewProvider?.Dispose();
|
viewProvider?.Dispose();
|
||||||
@ -248,6 +270,7 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
{
|
{
|
||||||
scroller.Position = 0;
|
scroller.Position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollbar != null)
|
if (scrollbar != null)
|
||||||
{
|
{
|
||||||
scrollbar.SetValueWithoutNotify(0);
|
scrollbar.SetValueWithoutNotify(0);
|
||||||
@ -330,12 +353,8 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Scrollbar.gameObject.SetActive(true);
|
Scrollbar.gameObject.SetActive(true);
|
||||||
Scrollbar.direction = direction == Direction.Vertical ?
|
Scrollbar.direction = direction == Direction.Vertical ? Scrollbar.Direction.TopToBottom : Scrollbar.Direction.LeftToRight;
|
||||||
Scrollbar.Direction.TopToBottom :
|
Scrollbar.size = direction == Direction.Vertical ? Scroller.ViewSize.y / Scroller.ContentSize.y : Scroller.ViewSize.x / Scroller.ContentSize.x;
|
||||||
Scrollbar.Direction.LeftToRight;
|
|
||||||
Scrollbar.size = direction == Direction.Vertical ?
|
|
||||||
Scroller.ViewSize.y / Scroller.ContentSize.y :
|
|
||||||
Scroller.ViewSize.x / Scroller.ContentSize.x;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
|
|
||||||
|
public bool ChoiseState { private set; get; }
|
||||||
|
|
||||||
public Vector2 SizeDelta => RectTransform.sizeDelta;
|
public Vector2 SizeDelta => RectTransform.sizeDelta;
|
||||||
|
|
||||||
public virtual void OnStop()
|
public virtual void OnStop()
|
||||||
@ -42,9 +44,17 @@ namespace AlicizaX.UI.RecyclerView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void BindChoiceState(bool state)
|
protected internal void BindChoiceState(bool state)
|
||||||
{
|
{
|
||||||
|
if (ChoiseState != state)
|
||||||
|
{
|
||||||
|
ChoiseState = state;
|
||||||
|
OnBindChoiceState(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected internal virtual void OnBindChoiceState(bool state)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user