Files
ChunilENG/Assets/WorkSpace/Personal/JYM/UI_DashboardCheckListBox.cs
2025-03-12 12:04:19 +09:00

61 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using WI;
namespace CHN
{
public class UI_DashboardCheckListBox : UIBase
{
public UI_DashboardCheckListItem prf_item;
private Dictionary<string, GameObject> originDashBoardItems = new();
private Dictionary<string, UI_DashboardCheckListItem> dashboardItemList = new();
public void Init(Dictionary<string, GameObject> items)
{
prf_item = Resources.Load<UI_DashboardCheckListItem>("Prefabs/UI/UI_DashboardCheckListItem");
originDashBoardItems.Clear();
foreach (var item in items)
{
var dashboardItem = CreateItem();
dashboardItemList.Add(item.Key, dashboardItem);
originDashBoardItems.Add(item.Key, item.Value);
}
SetMenuItem(items);
}
private void SetMenuItem(Dictionary<string, GameObject> items)
{
foreach (var item in items)
{
dashboardItemList[item.Key].SetItem(item.Key, item.Value);
}
}
public void OnCloseDashbordItem(string dahboardKey)
{
dashboardItemList[dahboardKey].ToggleOffItem();
}
private UI_DashboardCheckListItem CreateItem()
{
var item = Instantiate(prf_item, transform);
item.transform.localScale = Vector3.one;
return item;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (EventSystem.current.currentSelectedGameObject != null)
return;
transform.parent.gameObject.SetActive(false);
}
}
}
}