187 lines
5.1 KiB
C#
187 lines
5.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
using static MQTT;
|
|
|
|
public class Panel_FinalInspection : PanelBase, IProductionPanel
|
|
{
|
|
public Dictionary<int, UI_StatusContent> statusContents = new Dictionary<int, UI_StatusContent>();
|
|
private Panel_Effect effect;
|
|
private UI_StatusContent prf_statusContent;
|
|
public RectTransform Content;
|
|
public Image Image_Loading;
|
|
public Button CloseButton;
|
|
public TextMeshProUGUI CurrentDate;
|
|
public TextMeshProUGUI CurrentTime;
|
|
|
|
public int statusItemsCount;
|
|
private int currentContentIndex;
|
|
private bool isChangedData;
|
|
|
|
public float changeDataTime;
|
|
public float fadeTime;
|
|
public Action<Panel_FinalInspection> onSelected;
|
|
public Action onOpen;
|
|
public Action onClose;
|
|
public override void AfterAwake()
|
|
{
|
|
prf_statusContent = Resources.Load<UI_StatusContent>("Prefabs/UI/UI_StatusContent");
|
|
effect = FindSingle<Panel_Effect>();
|
|
CloseButton.onClick.AddListener(OnClickCloseButton);
|
|
SetDate();
|
|
Close();
|
|
}
|
|
public void Update()
|
|
{
|
|
SetTime();
|
|
}
|
|
public void OnSelected()
|
|
{
|
|
onSelected?.Invoke(this);
|
|
Open();
|
|
}
|
|
public void Open()
|
|
{
|
|
onOpen?.Invoke();
|
|
|
|
effect.ActivePanel();
|
|
gameObject.SetActive(true);
|
|
gameObject.transform.SetAsLastSibling();
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(ScaleUp());
|
|
|
|
if (statusContents.Count <= 0)
|
|
{
|
|
isChangedData = false;
|
|
return;
|
|
}
|
|
|
|
StartCoroutine(ChageStatusContent());
|
|
}
|
|
public void Close()
|
|
{
|
|
effect.DeactivePanel();
|
|
gameObject.SetActive(false);
|
|
gameObject.transform.localScale = Vector3.zero;
|
|
ResetStatusContentOrder();
|
|
isChangedData = false;
|
|
}
|
|
private void OnClickCloseButton()
|
|
{
|
|
Close();
|
|
onClose?.Invoke();
|
|
}
|
|
|
|
private IEnumerator ChageStatusContent()
|
|
{
|
|
isChangedData = true;
|
|
currentContentIndex = 0;
|
|
|
|
statusContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
currentContentIndex++;
|
|
|
|
while (true)
|
|
{
|
|
yield return new WaitForSeconds(changeDataTime);
|
|
|
|
if (currentContentIndex >= statusContents.Values.Count)
|
|
{
|
|
currentContentIndex = 0;
|
|
}
|
|
|
|
statusContents[currentContentIndex].gameObject.transform.SetAsFirstSibling();
|
|
currentContentIndex++;
|
|
}
|
|
}
|
|
private void ResetStatusContentOrder()
|
|
{
|
|
foreach (var statusContent in statusContents.Values)
|
|
{
|
|
statusContent.gameObject.transform.SetAsFirstSibling();
|
|
}
|
|
}
|
|
public void ActiveLoadingImage(bool isActive)
|
|
{
|
|
var active = isActive ? false : true;
|
|
Image_Loading.gameObject.SetActive(active);
|
|
}
|
|
|
|
public void SetProductionStatus(List<CompleteInfo> machineInfos)
|
|
{
|
|
ActiveLoadingImage(true);
|
|
|
|
var splitCompleteInfo = SplitArray(machineInfos, statusItemsCount);
|
|
SetProductionContent(splitCompleteInfo);
|
|
}
|
|
public void SetProductionContent(List<List<CompleteInfo>> splitCompleteInfo)
|
|
{
|
|
for (int i = 0; i < splitCompleteInfo.Count; i++)
|
|
{
|
|
if (!statusContents.ContainsKey(i))
|
|
{
|
|
var statusContent = Instantiate(prf_statusContent, Content);
|
|
statusContent.SetProductionStatusItem(splitCompleteInfo[i]);
|
|
statusContents.Add(i, statusContent);
|
|
}
|
|
else
|
|
{
|
|
statusContents[i].SetProductionStatusItem(splitCompleteInfo[i]);
|
|
}
|
|
}
|
|
if (!isChangedData && gameObject.activeSelf)
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(ChageStatusContent());
|
|
}
|
|
}
|
|
private List<List<CompleteInfo>> SplitArray(List<CompleteInfo> machineInfos, int groupSize)
|
|
{
|
|
List<List<CompleteInfo>> result = new List<List<CompleteInfo>>();
|
|
int totalGroups = Mathf.CeilToInt(machineInfos.Count / (float)groupSize);
|
|
|
|
for (int i = 0; i < totalGroups; i++)
|
|
{
|
|
int startIndex = i * groupSize;
|
|
int endIndex = Mathf.Min(startIndex + groupSize, machineInfos.Count);
|
|
|
|
List<CompleteInfo> group = new List<CompleteInfo>();
|
|
for (int j = startIndex; j < endIndex; j++)
|
|
{
|
|
group.Add(machineInfos[j]);
|
|
}
|
|
|
|
result.Add(group);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
public void SetDate()
|
|
{
|
|
CurrentDate.text = DateTime.Now.ToString("yyyy.MM.dd");
|
|
}
|
|
public void SetTime()
|
|
{
|
|
CurrentTime.text = DateTime.Now.ToString("HH:mm");
|
|
}
|
|
IEnumerator ScaleUp()
|
|
{
|
|
float timer = 0f;
|
|
float percent = 0f;
|
|
|
|
while (percent < 1)
|
|
{
|
|
timer += Time.deltaTime;
|
|
percent = timer / fadeTime;
|
|
transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one, percent);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
}
|
|
}
|