90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using WI;
|
|
using static MQTT;
|
|
|
|
namespace CHN
|
|
{
|
|
public class ProductionStatusManager : MonoBehaviour, ISingle
|
|
{
|
|
public Building building;
|
|
|
|
public List<CompleteInfo> productionStatusInfos = new();
|
|
|
|
public Dictionary<string,CompleteInfo> firstFloorInfo = new Dictionary<string, CompleteInfo>();
|
|
public Dictionary<string, CompleteInfo> secondFloorInfo = new Dictionary<string, CompleteInfo>();
|
|
|
|
public Action<List<CompleteInfo>> onFirstFloorInfo;
|
|
public Action<List<CompleteInfo>> onSecondFloorInfo;
|
|
|
|
public Action<List<WorkShopInfo>> onWorkShopInfo;
|
|
|
|
public Action onActiveFirstBoard;
|
|
public Action onActiveSecondBoard;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
building = FindSingle<Building>();
|
|
}
|
|
|
|
public void SetWorkProgressStatus(List<WorkShopInfo> workShopInfos)
|
|
{
|
|
onWorkShopInfo?.Invoke(workShopInfos);
|
|
}
|
|
public void SetFloorProductionStatus(List<CompleteInfo> completeInfos)
|
|
{
|
|
productionStatusInfos = completeInfos;
|
|
|
|
foreach (var completeInfo in completeInfos)
|
|
{
|
|
SetFloorInfo(building.floors[0], completeInfo, firstFloorInfo);
|
|
SetFloorInfo(building.floors[1], completeInfo, secondFloorInfo);
|
|
}
|
|
|
|
List<CompleteInfo> firstFloorInfoList = firstFloorInfo.Values.ToList();
|
|
List<CompleteInfo> secondFloorInfoList = secondFloorInfo.Values.ToList();
|
|
|
|
productionStatusInfos.Clear();
|
|
productionStatusInfos.AddRange(firstFloorInfoList);
|
|
productionStatusInfos.AddRange(secondFloorInfoList);
|
|
|
|
onFirstFloorInfo?.Invoke(firstFloorInfoList);
|
|
onSecondFloorInfo?.Invoke(secondFloorInfoList);
|
|
}
|
|
public void SetFloorInfo(Floor floor, CompleteInfo completeInfo, Dictionary<string, CompleteInfo> floorInfo)
|
|
{
|
|
foreach (var machine in floor.machines)
|
|
{
|
|
if (machine.code == completeInfo.workcd)
|
|
{
|
|
if (!floorInfo.ContainsKey(completeInfo.workcd))
|
|
{
|
|
floorInfo.Add(completeInfo.workcd, completeInfo);
|
|
|
|
}
|
|
else
|
|
{
|
|
floorInfo[completeInfo.workcd] = completeInfo;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void ActiveBoardToType(BoardType boardType)
|
|
{
|
|
switch (boardType)
|
|
{
|
|
case BoardType.Injection:
|
|
onActiveFirstBoard?.Invoke();
|
|
break;
|
|
case BoardType.Assembly:
|
|
onActiveSecondBoard?.Invoke();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|