26.04.03 가상공장 화면 디자인 반영 • 좌측 도구 창, 상단 UI, 하단 UI • 생산 현황판, 알림 현황판 • 설비 라벨, 요약 팝업, 대시보드, 데이터 보드 • 설정창, 미니맵, AI 시뮬레이션 결과창, 나가기 팝업 가상 공장 화면 디자인 변경에 따른 기능 추가 • 미니맵 드래그 및 위치 조정 기능 추가 • UI 상호 작용(호버링, 선택, 위치 이동, 재설정) • UI 기능 추가(상태 표시, 색상)
221 lines
7.8 KiB
C#
221 lines
7.8 KiB
C#
using AZTECHWB.Constants;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
|
||
namespace AZTECHWB.Management
|
||
{
|
||
public class DataManager : Manager
|
||
{
|
||
private Dictionary<string, int> orderMap = new();
|
||
private List<Machine> sortedMachineList = new();
|
||
|
||
private List<CompleteInfo> matchedMachineInfos = new List<CompleteInfo>();
|
||
//private Dictionary<string, List<CompleteInfo>> equipmentInfos = new();
|
||
//private Dictionary<string, List<CompleteInfo>> alarmInfos = new();
|
||
|
||
public Machine currentMachine;
|
||
public Action<List<CompleteInfo>> onMatchedMachineData;
|
||
public Action<Machine, CompleteInfo> onSetMachineData;
|
||
//public Action<Machine, CompleteInfo> onSetEquipmentDatas;
|
||
//public Action<List<CompleteInfo>> onSetAlarmInfos;
|
||
//public Action<Dictionary<string, List<CompleteInfo>>> onSetMatchAlarmInfos;
|
||
|
||
private void Start()
|
||
{
|
||
var dataOrder = Resources.Load<TextAsset>($"{ResourceURL.dataFolderPath}DataOrder").text;
|
||
var workcdOrder = JsonConvert.DeserializeObject<List<string>>(dataOrder);
|
||
orderMap = workcdOrder.Select((workcd, index) => new { workcd, index }).ToDictionary(x => x.workcd, x => x.index);
|
||
|
||
var machines = FindObjectsByType<Machine>(FindObjectsSortMode.None);
|
||
sortedMachineList = SortedMachineList(machines);
|
||
|
||
var testDataText = Resources.Load<TextAsset>($"{ResourceURL.dataFolderPath}Test_MachineData").text;
|
||
var testData = JsonConvert.DeserializeObject<List<CompleteInfo>>(testDataText);
|
||
|
||
MatchedMachineData(testData);
|
||
}
|
||
|
||
public void MatchedMachineData(List<CompleteInfo> infos)
|
||
{
|
||
// infos<6F><73> worknm <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Dictionary<72><79> <20><>ȯ<EFBFBD>ϸ鼭 <20><><EFBFBD><EFBFBD>
|
||
var infoDict = new Dictionary<string, CompleteInfo>();
|
||
foreach (var info in infos)
|
||
{
|
||
infoDict[info.worknm] = info; // <20><><EFBFBD><EFBFBD> Ű<><C5B0> <20>ֽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> <20><><EFBFBD><EFBFBD><EEBEB2>
|
||
}
|
||
|
||
matchedMachineInfos.Clear();
|
||
|
||
foreach (var machine in sortedMachineList)
|
||
{
|
||
if (string.IsNullOrEmpty(machine.machineName))
|
||
continue;
|
||
|
||
if (infoDict.TryGetValue(machine.machineName, out var info))
|
||
{
|
||
matchedMachineInfos.Add(info);
|
||
}
|
||
}
|
||
onMatchedMachineData?.Invoke(matchedMachineInfos);
|
||
UpdateShowMachineData(matchedMachineInfos);
|
||
}
|
||
public void SetSelectedMachine(Machine machine, CompleteInfo info)
|
||
{
|
||
currentMachine = machine;
|
||
onSetMachineData?.Invoke(currentMachine, info);
|
||
}
|
||
public void UpdateShowMachineData(List<CompleteInfo> infos)
|
||
{
|
||
if (currentMachine == null || currentMachine.machineName == null)
|
||
return;
|
||
|
||
foreach(var info in infos)
|
||
{
|
||
if(info.worknm == currentMachine.machineName)
|
||
{
|
||
onSetMachineData?.Invoke(currentMachine,info);
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
public List<Machine> SortedMachineList(Machine[] machines)
|
||
{
|
||
return machines.Where(field => orderMap.ContainsKey(field.machineName)).OrderBy(field => orderMap[field.machineName]).ToList();
|
||
}
|
||
|
||
//public void SetEquipementDataListArrangement(List<CompleteInfo> infos)
|
||
//{
|
||
// if (infos == null || infos.Count == 0)
|
||
// return;
|
||
|
||
// var cleaned = infos.Where(i => i != null).ToList();
|
||
|
||
// var grouped = cleaned.GroupBy(i => string.IsNullOrWhiteSpace(i.worknm) ? "<UNKNOWN>" : i.worknm.Trim());
|
||
|
||
// foreach (var g in grouped)
|
||
// {
|
||
// var groupList = g.ToList();
|
||
// equipmentInfos[g.Key] = groupList;
|
||
// }
|
||
// UpdateShowEquipmentData();
|
||
//}
|
||
//public void SetSelectedEquipmentData(Machine machine)
|
||
//{
|
||
// currentMachine = machine;
|
||
// UpdateShowEquipmentData();
|
||
//}
|
||
//public void UpdateShowEquipmentData()
|
||
//{
|
||
// if (currentMachine == null || currentMachine.machineName == null)
|
||
// return;
|
||
|
||
// var dataClearList = new List<CompleteInfo>();
|
||
|
||
// if (equipmentInfos.Count() <= 0)
|
||
// {
|
||
// onSetEquipmentDatas?.Invoke(currentMachine, dataClearList);
|
||
// }
|
||
// else
|
||
// {
|
||
// if (equipmentInfos.ContainsKey(currentMachine.machineName))
|
||
// {
|
||
// onSetEquipmentDatas?.Invoke(currentMachine, equipmentInfos[currentMachine.machineName]);
|
||
// }
|
||
// else
|
||
// {
|
||
// onSetEquipmentDatas?.Invoke(currentMachine, dataClearList);
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
|
||
//public void SetAlarmDataList(List<CompleteInfo> infos)
|
||
//{
|
||
// var alarmDataList = new List<CompleteInfo>();
|
||
|
||
// foreach (var info in infos)
|
||
// {
|
||
// var matchedData = matchedMachineInfos.Find(x => x.worknm == info.worknm);
|
||
// if (matchedData == null || matchedData.statusnm == "<22><EFBFBD><F1B0A1B5><EFBFBD>" || matchedData.statusnm == "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
|
||
// continue;
|
||
|
||
// alarmDataList.Add(info);
|
||
// machines.FirstOrDefault(x => x.machineName == info.worknm).SetAlarm(info.state);
|
||
// }
|
||
// onSetAlarmInfos?.Invoke(alarmDataList);
|
||
// SetAlarmDataListArrangement(alarmDataList);
|
||
//}
|
||
//public void SetAlarmDataListArrangement(List<CompleteInfo> infos)
|
||
//{
|
||
// if (infos == null) return;
|
||
|
||
// foreach (var info in infos)
|
||
// {
|
||
// if (info == null || string.IsNullOrEmpty(info.worknm))
|
||
// continue;
|
||
|
||
// if (!alarmInfos.TryGetValue(info.worknm, out var list))
|
||
// {
|
||
// list = new List<CompleteInfo>();
|
||
// alarmInfos[info.worknm] = list;
|
||
// }
|
||
|
||
// int index = list.FindIndex(x => !string.IsNullOrEmpty(x.id) && x.id == info.id);
|
||
|
||
// if (index >= 0)
|
||
// {
|
||
// list[index] = info;
|
||
// }
|
||
// else
|
||
// {
|
||
// list.Add(info);
|
||
// }
|
||
// }
|
||
// onSetMatchAlarmInfos?.Invoke(alarmInfos);
|
||
//}
|
||
}
|
||
[Serializable]
|
||
public class CompleteInfo
|
||
{
|
||
public string datagbn;
|
||
public string wordno;
|
||
public string workdt;
|
||
public string sitecd;
|
||
public string wccd;
|
||
public string workcd;
|
||
public string worknm;
|
||
public string workseq;
|
||
public string status;
|
||
public string statusnm;
|
||
public string itemcd;
|
||
public string itemdesc;
|
||
public string pjtcd;
|
||
public string matcd;
|
||
public string cycletime;
|
||
public string cavity;
|
||
public string planqty;
|
||
public string goalqty;
|
||
public string workqty;
|
||
public string goodqty;
|
||
public string badqty;
|
||
public string badrate;
|
||
public string efficiency;
|
||
public string progressrate;
|
||
public string sttm;
|
||
public string totm;
|
||
public string goaltime;
|
||
public string ptotm;
|
||
public string psttm;
|
||
public string moldcd;
|
||
public string moldseq;
|
||
public string porate;
|
||
public string goodqtyrate;
|
||
public string eorate;
|
||
public string lct;
|
||
public string wct;
|
||
}
|
||
}
|