백업
This commit is contained in:
@@ -7,6 +7,9 @@ using XED.Manage;
|
|||||||
using Unity.Hierarchy;
|
using Unity.Hierarchy;
|
||||||
using XED.Core;
|
using XED.Core;
|
||||||
using XED.Command;
|
using XED.Command;
|
||||||
|
using UnityEditor.UIElements;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using UnityEditor.Localization.Plugins.XLIFF.V20;
|
||||||
|
|
||||||
namespace XED.AssetLibraryTree
|
namespace XED.AssetLibraryTree
|
||||||
{
|
{
|
||||||
@@ -35,6 +38,7 @@ namespace XED.AssetLibraryTree
|
|||||||
public UnityEvent<AssetLibraryItem> onHover;
|
public UnityEvent<AssetLibraryItem> onHover;
|
||||||
|
|
||||||
public bool isSiblingEditable;
|
public bool isSiblingEditable;
|
||||||
|
private int rowItemCount = 3;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@@ -178,10 +182,36 @@ namespace XED.AssetLibraryTree
|
|||||||
foreach (var item in activeItems) pool.Release(item);
|
foreach (var item in activeItems) pool.Release(item);
|
||||||
activeItems.Clear();
|
activeItems.Clear();
|
||||||
|
|
||||||
int itemsPerRow = 3;
|
int startIndex = Mathf.Clamp(currentIndex * rowItemCount, 0, data.Count);
|
||||||
int startIndex = Mathf.Clamp(currentIndex * itemsPerRow, 0, data.Count);
|
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * rowItemCount, 0, data.Count);
|
||||||
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * itemsPerRow, 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);
|
SetScrollItemUI(startIndex, endIndex);
|
||||||
}
|
}
|
||||||
private void RebuildVisibleItems(AssetLibraryItem focusItem)
|
private void RebuildVisibleItems(AssetLibraryItem focusItem)
|
||||||
@@ -195,24 +225,47 @@ namespace XED.AssetLibraryTree
|
|||||||
foreach (var item in activeItems) pool.Release(item);
|
foreach (var item in activeItems) pool.Release(item);
|
||||||
activeItems.Clear();
|
activeItems.Clear();
|
||||||
|
|
||||||
int itemsPerRow = 3;
|
int startIndex = Mathf.Clamp(currentIndex * rowItemCount, 0, data.Count);
|
||||||
int startIndex = Mathf.Clamp(currentIndex * itemsPerRow, 0, data.Count);
|
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * rowItemCount, 0, data.Count);
|
||||||
int endIndex = Mathf.Clamp((currentIndex + visibleItemCount) * itemsPerRow, 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)
|
private void SetScrollItemUI(int startIndex, int endIndex)
|
||||||
{
|
{
|
||||||
int itemsPerRow = 3;
|
float spacingX = 20f;
|
||||||
float spacingX = 10f;
|
|
||||||
float spacingY = 10f;
|
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>();
|
int allRowItemCount = Mathf.CeilToInt(data.Count / rowItemCount);
|
||||||
float contentWidth = viewport.sizeDelta.x;
|
float totalHeight = allRowItemCount * (itemHeight + spacingY);
|
||||||
float itemWidth = (contentWidth - spacingX * (itemsPerRow - 1)) / itemsPerRow;
|
|
||||||
|
|
||||||
int rowCount = Mathf.CeilToInt((float)data.Count / itemsPerRow);
|
|
||||||
float totalHeight = rowCount * (itemHeight + spacingY);
|
|
||||||
content.sizeDelta = new Vector2(contentWidth, totalHeight);
|
content.sizeDelta = new Vector2(contentWidth, totalHeight);
|
||||||
|
|
||||||
for (int i = startIndex; i < endIndex; i++)
|
for (int i = startIndex; i < endIndex; i++)
|
||||||
@@ -222,11 +275,39 @@ namespace XED.AssetLibraryTree
|
|||||||
itemUI.SetItemData(item);
|
itemUI.SetItemData(item);
|
||||||
itemUI.SetSelected(selectedItems);
|
itemUI.SetSelected(selectedItems);
|
||||||
itemUI.transform.SetParent(content, false);
|
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;
|
//if (i == startIndex)
|
||||||
int col = i % itemsPerRow;
|
// 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;
|
float y = -row * (itemHeight + spacingY) - itemHeight / 2f;
|
||||||
|
|
||||||
RectTransform rt = itemUI.GetComponent<RectTransform>();
|
RectTransform rt = itemUI.GetComponent<RectTransform>();
|
||||||
@@ -234,6 +315,7 @@ namespace XED.AssetLibraryTree
|
|||||||
rt.anchoredPosition = new Vector2(x, y);
|
rt.anchoredPosition = new Vector2(x, y);
|
||||||
|
|
||||||
activeItems.Add(itemUI);
|
activeItems.Add(itemUI);
|
||||||
|
preItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private AssetLibraryScrollItemUI GetItemUI()
|
private AssetLibraryScrollItemUI GetItemUI()
|
||||||
|
|||||||
Reference in New Issue
Block a user