에셋 라이브러리 스크롤 버그 #154

Merged
UVCXR merged 1 commits from pgd/20250611_merge into main 2025-06-11 16:49:26 +09:00
4 changed files with 78 additions and 64 deletions

View File

@@ -112,7 +112,7 @@ RectTransform:
m_Father: {fileID: 1685799791316290074}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0.99998707}
m_AnchorMax: {x: 1, y: 0.99999106}
m_AnchoredPosition: {x: 2, y: 0}
m_SizeDelta: {x: 8, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
@@ -1018,7 +1018,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 5808496954263173159}
m_Direction: 2
m_Value: 0
m_Size: 0.99998707
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@@ -1062,8 +1062,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 210, y: -408.97}
m_SizeDelta: {x: 420, y: 817.93}
m_AnchoredPosition: {x: 210, y: -431.02136}
m_SizeDelta: {x: 420, y: 862.0427}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7966294254755768478
CanvasRenderer:
@@ -1741,7 +1741,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: -0.00034048597, y: 0.005433774}
m_AnchoredPosition: {x: -0.00034048597, y: 0.0035585074}
m_SizeDelta: {x: 282.99957, y: 2}
m_Pivot: {x: 0, y: 1}
--- !u!114 &2780744526690132257
@@ -2202,8 +2202,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 210, y: -501.18732}
m_SizeDelta: {x: 420, y: 817.9348}
m_AnchoredPosition: {x: 210, y: -531.1099}
m_SizeDelta: {x: 420, y: 877.78}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &5930958411786542109
MonoBehaviour:

View File

@@ -39,7 +39,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: -10}
m_SizeDelta: {x: 0, y: 35}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &8577872390119345382
@@ -621,7 +621,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 420, y: 50}
m_SizeDelta: {x: 420, y: 110}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &9006872392457284266
CanvasRenderer:
@@ -1128,7 +1128,7 @@ MonoBehaviour:
m_Color: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 0
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []

View File

@@ -367,8 +367,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}
m_AnchoredPosition: {x: 0, y: -30}
m_SizeDelta: {x: 110, y: 30}
m_AnchoredPosition: {x: 0, y: -15}
m_SizeDelta: {x: 110, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &499100886614822048
CanvasRenderer:
@@ -620,7 +620,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 110, y: 140}
m_SizeDelta: {x: 110, y: 110}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &9006872392457284266
CanvasRenderer:
@@ -1105,7 +1105,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 5}
m_SizeDelta: {x: 80, y: 80}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5193183312611458682

View File

@@ -32,7 +32,6 @@ namespace Studio.AssetLibraryTree
private AssetLibraryItem lastSelectedItem = null;
private float itemHeight; // Height of a single item.
private float folderHeight;
private int visibleItemCount; // Number of visible items that fit in the viewport.
private int currentIndex = -1; // The index of the first visible item.
@@ -42,7 +41,8 @@ namespace Studio.AssetLibraryTree
public bool isSiblingEditable;
int rowItemCount = 3;
private int rowItemCount = 3;
private float scrollViewOffset = 2f;
private void Awake()
{
@@ -85,9 +85,7 @@ namespace Studio.AssetLibraryTree
scrollRect.setToNextSiblingItem.AddListener(SetToNextSiblingItem);
//아이템 하나당 높이값 저장
itemHeight = itemPrefab.GetComponent<RectTransform>().rect.height;
folderHeight = folderPrefab.GetComponent<RectTransform>().rect.height;
float rowHeight = itemHeight + 10f; // row 간격 포함 (spacingY)
visibleItemCount = Mathf.CeilToInt(scrollRect.GetComponent<RectTransform>().sizeDelta.y / rowHeight) + 1;
visibleItemCount = Mathf.CeilToInt(scrollRect.GetComponent<RectTransform>().sizeDelta.y / itemHeight) + 1;
searchInput.onValueChanged.AddListener(SearchData);
//searchCancelButton.onClick.RemoveAllListeners();
@@ -124,6 +122,39 @@ namespace Studio.AssetLibraryTree
{
return root.Find(name, type);
}
public void CalculateSlotArea()
{
int fileCountCurLine = 0;
displayData.Clear();
foreach (var item in data)
{
if (item.type == AssetLibraryItemType.folder)
{
if (fileCountCurLine > 0)
{
for (int i = 0; i < rowItemCount - fileCountCurLine; i++)
{
displayData.Add(null);
}
fileCountCurLine = 0;
}
displayData.Add(item);
displayData.Add(null);
displayData.Add(null);
}
else
{
fileCountCurLine++;
displayData.Add(item);
if (fileCountCurLine == 3)
{
fileCountCurLine = 0;
}
}
}
}
public void SetData()
{
data.Clear();
@@ -144,9 +175,8 @@ namespace Studio.AssetLibraryTree
private void RebuildVisibleItems()
{
float rowHeight = itemHeight + 10f;
float scrollY = content.anchoredPosition.y;
int newRowIndex = Mathf.FloorToInt(scrollY / rowHeight);
int newRowIndex = Mathf.FloorToInt(scrollY / itemHeight);
if (newRowIndex < 0) newRowIndex = 0;
if (newRowIndex == currentIndex)
@@ -161,31 +191,9 @@ namespace Studio.AssetLibraryTree
foldersPool.Release(item);
activeItems.Clear();
activeFolders.Clear();
displayData.Clear();
activeFolders.Clear();
foreach (var item in data)
{
if (item.type == AssetLibraryItemType.folder)
{
int offset = displayData.Count % rowItemCount;
if (offset != 0)
{
int emptyCount = rowItemCount - offset;
for (int i = 0; i < emptyCount; i++)
displayData.Add(null);
}
displayData.Add(item);
displayData.Add(null);
displayData.Add(null);
}
else
{
displayData.Add(item);
}
}
CalculateSlotArea();
int startIndex = Mathf.Clamp(currentIndex * rowItemCount, 0, displayData.Count);
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * rowItemCount, 0, displayData.Count);
@@ -196,60 +204,66 @@ namespace Studio.AssetLibraryTree
{
float spacingX = 25f;
float spacingY = 0f;
int folderCount = 0;
float height = 0f;
RectTransform viewport = scrollRect.GetComponent<RectTransform>();
float contentWidth = viewport.sizeDelta.x;
float itemWidth = itemPrefab.GetComponent<RectTransform>().sizeDelta.x;
int allRowItemCount = Mathf.CeilToInt(data.Count / rowItemCount);
float totalHeight = allRowItemCount * (itemHeight + spacingY);
int folderRowCount = 0;
int allRowItemCount = Mathf.CeilToInt(displayData.Count / (float)rowItemCount);
float totalHeight = allRowItemCount * (itemHeight + spacingY) + scrollViewOffset * 2;
content.sizeDelta = new Vector2(contentWidth, totalHeight);
for (int i = startIndex; i < endIndex; i++)
{
AssetLibraryItem item = displayData[i];
if (item == null)
continue;
if (item == null) continue;
RectTransform itemRt;
float width;
var width = 0f;
// 폴더 처리
if (item.type == AssetLibraryItemType.folder)
{
AssetLibraryScrollFolderUI itemUI = foldersPool.Get();
width = scrollRect.content.sizeDelta.x;
var itemUI = foldersPool.Get();
itemUI.SetItemData(item);
itemUI.transform.SetParent(content, false);
itemRt = itemUI.GetComponent<RectTransform>();
height = folderHeight;
activeFolders.Add(itemUI);
width = contentWidth;
}
// 파일 처리
else
{
AssetLibraryScrollItemUI itemUI = GetItemUI();
width = itemWidth;
var itemUI = GetItemUI();
itemUI.SetItemData(item);
itemUI.SetSelected(selectedItems);
itemUI.transform.SetParent(content, false);
itemRt = itemUI.GetComponent<RectTransform>();
height = itemHeight;
activeItems.Add(itemUI);
}
width = itemWidth;
}
// 위치 계산
int row = i / rowItemCount;
int col = i % rowItemCount;
float x = item.type == AssetLibraryItemType.folder? 0f:col * (width + spacingX) - ((rowItemCount - 1) * (width + spacingX)) / 2f;
float y = -(row-folderCount) * ( itemHeight + spacingY) + (-folderCount * (folderHeight + spacingY)) - height / 2f;
float x = (item.type == AssetLibraryItemType.folder)
? 0f
: col * (width + spacingX) - ((rowItemCount - 1) * (width + spacingX)) / 2f;
itemRt.sizeDelta = new Vector2(width, height);
float y = -(row - folderRowCount) * (itemHeight + spacingY)
- (folderRowCount * (itemHeight + spacingY))
- itemHeight / 2f - scrollViewOffset;
itemRt.sizeDelta = new Vector2(width, itemHeight);
itemRt.anchoredPosition = new Vector2(x, y);
if (item.type == AssetLibraryItemType.folder)
folderCount++;
folderRowCount++;
}
}
private AssetLibraryScrollItemUI GetItemUI()