26.04.03 가상공장 화면 디자인 반영 • 좌측 도구 창, 상단 UI, 하단 UI • 생산 현황판, 알림 현황판 • 설비 라벨, 요약 팝업, 대시보드, 데이터 보드 • 설정창, 미니맵, AI 시뮬레이션 결과창, 나가기 팝업 가상 공장 화면 디자인 변경에 따른 기능 추가 • 미니맵 드래그 및 위치 조정 기능 추가 • UI 상호 작용(호버링, 선택, 위치 이동, 재설정) • UI 기능 추가(상태 표시, 색상)
128 lines
3.8 KiB
C#
128 lines
3.8 KiB
C#
using AZTECHWB.Constants;
|
||
using AZTECHWB.Management;
|
||
using Cysharp.Threading.Tasks;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace AZTECHWB.UI
|
||
{
|
||
public class MachineDataDashboard : UIPanel
|
||
{
|
||
private TMP_Text Text_MachineName;
|
||
private ScrollRect ScrollView_DataInfo;
|
||
private Button Button_Close;
|
||
|
||
private MachineDataInfoItem dataInfoItem;
|
||
|
||
private FieldInfo[] machineDataFields;
|
||
private Dictionary<string, MachineDataInfoItem> dataInfoItems = new();
|
||
|
||
public override async UniTask Init()
|
||
{
|
||
Text_MachineName = GetElement<TextMeshProUGUI>(nameof(Text_MachineName));
|
||
ScrollView_DataInfo = GetElement<ScrollRect>(nameof(ScrollView_DataInfo));
|
||
Button_Close = GetElement<Button>(nameof(Button_Close));
|
||
|
||
dataInfoItem = Resources.Load<MachineDataInfoItem>($"{ResourceURL.uiPrefabFolderPath}{nameof(MachineDataInfoItem)}");
|
||
|
||
Button_Close.onClick.AddListener(Close);
|
||
machineDataFields = typeof(CompleteInfo).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||
|
||
await UniTask.CompletedTask;
|
||
}
|
||
public void SetDataDashobardInfo(Machine machine, CompleteInfo infos)
|
||
{
|
||
if (Text_MachineName.text == machine.machineName)
|
||
{
|
||
UpdateMachineDataInfo(machineDataFields, infos);
|
||
}
|
||
else
|
||
{
|
||
Text_MachineName.SetText(machine.machineName);
|
||
// Destroy <20><><EFBFBD> <20><>ȯ
|
||
foreach (var item in dataInfoItems.Values)
|
||
{
|
||
ReturnItem(item);
|
||
}
|
||
dataInfoItems.Clear();
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> Ǯ<><C7AE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
CreateMachineDataInfo(machineDataFields, infos);
|
||
}
|
||
}
|
||
|
||
private void CreateMachineDataInfo(FieldInfo[] fields, object data)
|
||
{
|
||
bool odd = true;
|
||
|
||
foreach (var field in fields)
|
||
{
|
||
var item = GetItem();
|
||
|
||
var info = (string)field.GetValue(data);
|
||
item.Setting(field.Name, info);
|
||
|
||
var colorId = odd?"#FBFBFB":"#FFFFFF";
|
||
ColorUtility.TryParseHtmlString(colorId, out var color);
|
||
item.SetBackgroundColor(color);
|
||
|
||
odd = !odd;
|
||
dataInfoItems.Add($"{field}", item);
|
||
}
|
||
}
|
||
|
||
private void UpdateMachineDataInfo(FieldInfo[] fields, object data)
|
||
{
|
||
foreach (var field in fields)
|
||
{
|
||
var info = (string)field.GetValue(data);
|
||
|
||
if (!dataInfoItems.ContainsKey($"{field}"))
|
||
continue;
|
||
|
||
dataInfoItems[$"{field}"].Setting(field.Name, info);
|
||
}
|
||
}
|
||
|
||
private Queue<MachineDataInfoItem> pool = new Queue<MachineDataInfoItem>();
|
||
|
||
public MachineDataInfoItem GetItem()
|
||
{
|
||
MachineDataInfoItem item;
|
||
if (pool.Count > 0)
|
||
{
|
||
item = pool.Dequeue();
|
||
item.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
item = Instantiate(dataInfoItem, ScrollView_DataInfo.content);
|
||
}
|
||
|
||
item.transform.SetAsLastSibling();
|
||
item.Init();
|
||
return item;
|
||
}
|
||
|
||
public void ReturnItem(MachineDataInfoItem item)
|
||
{
|
||
item.gameObject.SetActive(false);
|
||
pool.Enqueue(item);
|
||
}
|
||
|
||
public void ClearPool()
|
||
{
|
||
foreach (var item in pool)
|
||
{
|
||
Destroy(item.gameObject);
|
||
}
|
||
pool.Clear();
|
||
}
|
||
}
|
||
}
|
||
|