2025-02-20 03:15:42 +08:00
|
|
|
using System;
|
2025-01-27 22:11:24 -05:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2025-02-12 00:01:23 -05:00
|
|
|
using TMPro;
|
2025-01-27 22:11:24 -05:00
|
|
|
using UnityEngine;
|
2025-02-11 22:58:56 -05:00
|
|
|
using UnityEngine.Serialization;
|
2025-02-12 17:57:26 +08:00
|
|
|
using UnityEngine.UI;
|
2025-01-27 22:11:24 -05:00
|
|
|
|
2025-02-11 22:58:56 -05:00
|
|
|
namespace Ichni.Editor
|
2025-01-27 22:11:24 -05:00
|
|
|
{
|
2025-02-11 22:58:56 -05:00
|
|
|
public class DynamicUIContainer : MonoBehaviour
|
2025-01-27 22:11:24 -05:00
|
|
|
{
|
2025-02-12 00:01:23 -05:00
|
|
|
public TMP_Text title;
|
2025-04-14 17:49:47 -04:00
|
|
|
public RectTransform rect;
|
|
|
|
|
public List<DynamicUISubcontainer> subcontainers;
|
|
|
|
|
|
|
|
|
|
public int gridWidth, gridHeight;
|
2025-02-20 03:15:42 +08:00
|
|
|
|
2025-04-14 17:49:47 -04:00
|
|
|
public void Initialize(string titleText)
|
|
|
|
|
{
|
|
|
|
|
this.title.text = titleText;
|
|
|
|
|
this.subcontainers = new List<DynamicUISubcontainer>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DynamicUISubcontainer GenerateSubcontainer(int elementCountPerRow, float height = 100)
|
|
|
|
|
{
|
|
|
|
|
DynamicUISubcontainer subcontainer =
|
|
|
|
|
Instantiate(EditorManager.instance.basePrefabs.dynamicUISubcontainer, rect).
|
|
|
|
|
GetComponent<DynamicUISubcontainer>();
|
2025-02-20 03:15:42 +08:00
|
|
|
|
2025-04-14 17:49:47 -04:00
|
|
|
subcontainer.Initialize(this, elementCountPerRow, height);
|
|
|
|
|
subcontainers.Add(subcontainer);
|
|
|
|
|
return subcontainer;
|
|
|
|
|
}
|
2025-02-20 03:15:42 +08:00
|
|
|
|
2025-04-14 17:49:47 -04:00
|
|
|
public Vector2Int GetGrid(int elementCountPerRow, int heightUnit)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2Int(600 / elementCountPerRow, 100 * heightUnit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CheckGrid(Vector2Int newGrid)
|
|
|
|
|
{
|
|
|
|
|
if(newGrid.x > gridWidth)
|
|
|
|
|
{
|
|
|
|
|
gridWidth = newGrid.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(newGrid.y > gridHeight)
|
|
|
|
|
{
|
|
|
|
|
gridHeight = newGrid.y;
|
2025-02-20 03:15:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-27 22:11:24 -05:00
|
|
|
}
|
2025-02-11 22:58:56 -05:00
|
|
|
}
|