76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UVC.UI.List;
|
|
using UVC.UI.Window;
|
|
|
|
public class LibraryWindowSample : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private LibraryWindow libraryWindow;
|
|
|
|
public void Start()
|
|
{
|
|
if (libraryWindow == null)
|
|
{
|
|
libraryWindow = FindFirstObjectByType<LibraryWindow>();
|
|
}
|
|
|
|
// PrefabGrid 이벤트 구독
|
|
if (libraryWindow != null && libraryWindow.PrefabGrid != null)
|
|
{
|
|
libraryWindow.PrefabGrid.OnItemClick += OnClickGridItem;
|
|
libraryWindow.PrefabGrid.OnItemDrop += OnDropGridItem;
|
|
}
|
|
|
|
List<string> imagePath = new List<string>()
|
|
{
|
|
"Simulator/Images/lib_forklift_400x300",
|
|
"Simulator/Images/lib_pallet_400x300",
|
|
"Simulator/Images/lib_worker_400x300",
|
|
};
|
|
|
|
List<string> prefabPath = new List<string>()
|
|
{
|
|
"Prefabs/Forklift",
|
|
"Prefabs/PalletEmpty",
|
|
"Prefabs/Male Young Guy",
|
|
};
|
|
|
|
List<PrefabGridItemData> list = new List<PrefabGridItemData>();
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
list.Add(new PrefabGridItemData()
|
|
{
|
|
Id = i.ToString(),
|
|
ItemName = $"Item {i}",
|
|
ImagePrefabPath = imagePath[i % 3],
|
|
ObjectPrefabPath = prefabPath[i % 3],
|
|
Tag = $"item_{i}"
|
|
});
|
|
}
|
|
|
|
libraryWindow.SetData(list);
|
|
}
|
|
|
|
private void OnClickGridItem(PrefabGridItemData data)
|
|
{
|
|
Debug.Log($"Clicked Item: {data.ItemName}, PrefabPath: {data.ObjectPrefabPath}");
|
|
}
|
|
|
|
private void OnDropGridItem(PrefabGridItemData data)
|
|
{
|
|
Debug.Log($"Dropped Item: {data.ItemName}, PrefabPath: {data.ObjectPrefabPath}");
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
// 이벤트 구독 해제
|
|
if (libraryWindow != null && libraryWindow.PrefabGrid != null)
|
|
{
|
|
libraryWindow.PrefabGrid.OnItemClick -= OnClickGridItem;
|
|
libraryWindow.PrefabGrid.OnItemDrop -= OnDropGridItem;
|
|
}
|
|
}
|
|
}
|