2025-04-14 17:49:47 -04:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ichni.Editor
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DynamicUISubcontainer : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
Inspector Inspector => EditorManager.instance.uiManager.inspector;
|
|
|
|
|
|
public DynamicUIContainer parentContainer;
|
|
|
|
|
|
public GridLayoutGroup gridLayoutGroup;
|
|
|
|
|
|
public RectTransform rect;
|
|
|
|
|
|
public List<DynamicUIElement> dynamicUIElements;
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(DynamicUIContainer parentContainer, int elementCountPerRow, float height = 100)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.parentContainer = parentContainer;
|
|
|
|
|
|
this.gridLayoutGroup.cellSize = new Vector2(600f / elementCountPerRow, height);
|
2026-03-22 12:05:32 -04:00
|
|
|
|
// 支持对象池复用:避免每次 new List 产生 GC,直接清空
|
|
|
|
|
|
if (this.dynamicUIElements == null)
|
|
|
|
|
|
this.dynamicUIElements = new List<DynamicUIElement>();
|
|
|
|
|
|
else
|
|
|
|
|
|
this.dynamicUIElements.Clear();
|
2025-04-14 17:49:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DynamicUISubcontainer Mark(string mark, IHaveInspection inspection = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
inspection ??= Inspector;
|
|
|
|
|
|
inspection.MarkedSubcontainers.TryAdd(mark, this);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|