82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XED.VirtualFactory;
|
|
|
|
namespace Studio.UVC.UI
|
|
{
|
|
public class UVCScrollView : MonoBehaviour
|
|
{
|
|
private ScrollRect scrollRect;
|
|
private UVCScrollviewItem item;
|
|
private Action onClickScrollItem;
|
|
|
|
private List<UVCScrollviewItem> scrollItems = new();
|
|
public void Init(Vector2 size)
|
|
{
|
|
scrollRect = GetComponent<ScrollRect>();
|
|
var rect = GetComponent<RectTransform>();
|
|
|
|
rect.sizeDelta = size;
|
|
item = Resources.Load<UVCScrollviewItem>("Prefabs/Common/UVCScrollviewItem");
|
|
}
|
|
|
|
public void SetVerticalItem<T>(List<T> items)
|
|
{
|
|
if (!scrollRect.gameObject.TryGetComponent<VerticalLayoutGroup>(out var layout))
|
|
{
|
|
layout.gameObject.AddComponent<VerticalLayoutGroup>();
|
|
}
|
|
}
|
|
|
|
|
|
public void SetHorizontalItem<T>(List<T> items)
|
|
{
|
|
if (!scrollRect.gameObject.TryGetComponent<HorizontalLayoutGroup>(out var layout))
|
|
{
|
|
layout.gameObject.AddComponent<HorizontalLayoutGroup>();
|
|
}
|
|
}
|
|
|
|
private void SetPadding(LayoutGroup layoutGroup)
|
|
{
|
|
//layoutGroup.padding.
|
|
if(layoutGroup is HorizontalLayoutGroup)
|
|
{
|
|
|
|
}
|
|
switch (layoutGroup)
|
|
{
|
|
//case layoutGroup as VerticalLayoutGroup:
|
|
// break;
|
|
}
|
|
|
|
}
|
|
|
|
public void SetLayOutGroupItem<T>(List<T>items,Vector2 cellSize)
|
|
{
|
|
if(!scrollRect.gameObject.TryGetComponent<GridLayoutGroup>(out var layout))
|
|
{
|
|
layout.gameObject.AddComponent<GridLayoutGroup>();
|
|
layout.cellSize = cellSize;
|
|
}
|
|
|
|
foreach (T item in items)
|
|
{
|
|
var itme = CreateItem();
|
|
}
|
|
}
|
|
|
|
|
|
public UVCScrollviewItem CreateItem()
|
|
{
|
|
var resultItem = Instantiate<UVCScrollviewItem>(item, scrollRect.content);
|
|
resultItem.onClickButton?.Invoke();
|
|
scrollItems.Add(resultItem);
|
|
return resultItem;
|
|
}
|
|
}
|
|
}
|