This commit is contained in:
geondo55
2025-05-13 18:08:24 +09:00
parent 6f93f2c02c
commit e2683e77c4

View File

@@ -7,6 +7,9 @@ using XED.Manage;
using Unity.Hierarchy;
using XED.Core;
using XED.Command;
using UnityEditor.UIElements;
using JetBrains.Annotations;
using UnityEditor.Localization.Plugins.XLIFF.V20;
namespace XED.AssetLibraryTree
{
@@ -35,6 +38,7 @@ namespace XED.AssetLibraryTree
public UnityEvent<AssetLibraryItem> onHover;
public bool isSiblingEditable;
private int rowItemCount = 3;
private void Awake()
{
@@ -178,10 +182,36 @@ namespace XED.AssetLibraryTree
foreach (var item in activeItems) pool.Release(item);
activeItems.Clear();
int itemsPerRow = 3;
int startIndex = Mathf.Clamp(currentIndex * itemsPerRow, 0, data.Count);
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * itemsPerRow, 0, data.Count);
int startIndex = Mathf.Clamp(currentIndex * rowItemCount, 0, data.Count);
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * rowItemCount, 0, data.Count);
Debug.Log("startIndex1 " + startIndex);
Debug.Log("endIndex1 " + endIndex);
int diff = endIndex - startIndex;
int offset = 0;
for (int i = 0; i < startIndex; i++)
{
AssetLibraryItem item = data[i];
if (item.type == AssetLibraryItemType.folder)
{
offset += 1;
}
offset++;
if(offset == startIndex)
{
startIndex = i;
break;
}
else if(offset >= startIndex)
{
startIndex = i - 1;
break;
}
}
endIndex = startIndex + diff;
Debug.Log("startIndex2 " + startIndex);
Debug.Log("endIndex2 " + endIndex);
SetScrollItemUI(startIndex, endIndex);
}
private void RebuildVisibleItems(AssetLibraryItem focusItem)
@@ -195,24 +225,47 @@ namespace XED.AssetLibraryTree
foreach (var item in activeItems) pool.Release(item);
activeItems.Clear();
int itemsPerRow = 3;
int startIndex = Mathf.Clamp(currentIndex * itemsPerRow, 0, data.Count);
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * itemsPerRow, 0, data.Count);
int startIndex = Mathf.Clamp(currentIndex * rowItemCount, 0, data.Count);
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * rowItemCount, 0, data.Count);
int offset = 0;
for (int i = 0; i < startIndex; i++)
{
AssetLibraryItem item = data[i];
if (item.type == AssetLibraryItemType.folder)
{
offset += 2;
}
offset++;
SetScrollItemUI(startIndex, endIndex);
if (offset == startIndex)
{
startIndex = i;
break;
}
else if (offset >= startIndex)
{
startIndex = i - 1;
break;
}
}
SetScrollItemUI(startIndex - offset, endIndex - offset);
}
int emptyCount;
int folderCount = 0;
private void SetScrollItemUI(int startIndex, int endIndex)
{
int itemsPerRow = 3;
float spacingX = 10f;
float spacingX = 20f;
float spacingY = 10f;
folderCount = 0;
emptyCount = 0;
int row = 0;
int col = 0;
AssetLibraryItem preItem = null;
float contentWidth = scrollRect.GetComponent<RectTransform>().sizeDelta.x;
float itemWidth = itemPrefab.GetComponent<RectTransform>().sizeDelta.x;
RectTransform viewport = scrollRect.GetComponent<RectTransform>();
float contentWidth = viewport.sizeDelta.x;
float itemWidth = (contentWidth - spacingX * (itemsPerRow - 1)) / itemsPerRow;
int rowCount = Mathf.CeilToInt((float)data.Count / itemsPerRow);
float totalHeight = rowCount * (itemHeight + spacingY);
int allRowItemCount = Mathf.CeilToInt(data.Count / rowItemCount);
float totalHeight = allRowItemCount * (itemHeight + spacingY);
content.sizeDelta = new Vector2(contentWidth, totalHeight);
for (int i = startIndex; i < endIndex; i++)
@@ -222,11 +275,39 @@ namespace XED.AssetLibraryTree
itemUI.SetItemData(item);
itemUI.SetSelected(selectedItems);
itemUI.transform.SetParent(content, false);
if (item.type == AssetLibraryItemType.folder)
{
emptyCount += 2;
folderCount++;
if (preItem !=null && preItem.type != AssetLibraryItemType.folder)
{
emptyCount += ((rowItemCount - 1) - col);
}
}
Debug.Log("emptyCount " + emptyCount);
//if (i == startIndex)
//{
// offset = 0;
//}
//else
//{
// offset = i - folderCount + folderCount * rowItemCount;
//}
int row = i / itemsPerRow;
int col = i % itemsPerRow;
//if (i == startIndex)
// emptyCount = 0;
float x = col * (itemWidth + spacingX) - ((itemsPerRow - 1) * (itemWidth + spacingX)) / 2f;
row = (i+ emptyCount) / rowItemCount;
col = (i + emptyCount) % rowItemCount;
if (item.type == AssetLibraryItemType.folder)
{
col = 0;
}
float x = col * (itemWidth + spacingX) - ((rowItemCount - 1) * (itemWidth + spacingX)) / 2f;
float y = -row * (itemHeight + spacingY) - itemHeight / 2f;
RectTransform rt = itemUI.GetComponent<RectTransform>();
@@ -234,6 +315,7 @@ namespace XED.AssetLibraryTree
rt.anchoredPosition = new Vector2(x, y);
activeItems.Add(itemUI);
preItem = item;
}
}
private AssetLibraryScrollItemUI GetItemUI()