52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UIElements;
|
||
|
|
||
|
namespace BITKit.UX
|
||
|
{
|
||
|
public class UXTableBuilder : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private Vector2Int initialSize = new Vector2Int(1, 1);
|
||
|
[SerializeField,SerializeReference,SubclassSelector] private IVisualElementProvider containerProvider;
|
||
|
|
||
|
public VisualElement this[int x, int y] => GetContainer(x, y);
|
||
|
public VisualElement this[int x] => GetContainer(x, currentRank);
|
||
|
private VisualElement[,] _containers;
|
||
|
public VisualElement GetContainer(int x, int y)=>_containers[x, y];
|
||
|
private int currentRank = 0;
|
||
|
private void Awake()
|
||
|
{
|
||
|
containerProvider.VisualElement.style.flexDirection = FlexDirection.Row;
|
||
|
Clear();
|
||
|
}
|
||
|
public void Clear()
|
||
|
{
|
||
|
currentRank = 0;
|
||
|
containerProvider.GetVisualElement().Clear();
|
||
|
_containers = new VisualElement[initialSize.x, initialSize.y];
|
||
|
for (var x = 0; x< initialSize.x; x++)
|
||
|
{
|
||
|
var row = new VisualElement();
|
||
|
containerProvider.VisualElement.Add(row);
|
||
|
for (var y = 0; y < initialSize.y; y++)
|
||
|
{
|
||
|
var col = new VisualElement();
|
||
|
row.Add(col);
|
||
|
_containers[x, y] = col;
|
||
|
col.style.justifyContent = Justify.SpaceBetween;
|
||
|
}
|
||
|
row.style.justifyContent = Justify.SpaceBetween;
|
||
|
}
|
||
|
}
|
||
|
public void NextLine()
|
||
|
{
|
||
|
currentRank++;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|