90 lines
2.3 KiB
C#
90 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.EventSystems;
|
|
using WI;
|
|
using System;
|
|
using static MQTT;
|
|
using CHN;
|
|
|
|
public class UI_MachineKPI : UIBase, IPointerClickHandler
|
|
{
|
|
public SimpleField data;
|
|
public CompleteInfo completeInfoData;
|
|
public RectTransform DefaultKPI;
|
|
public RectTransform DetailsKPI;
|
|
|
|
private TextMeshProUGUI Default_machineName;
|
|
private TextMeshProUGUI Details_machineName;
|
|
private TextMeshProUGUI Default_eorate;
|
|
private TextMeshProUGUI Details_eorate;
|
|
private TextMeshProUGUI porate;
|
|
private TextMeshProUGUI goodqtyrate;
|
|
|
|
public bool isExpand;
|
|
private float eorate;
|
|
|
|
public Action<UI_MachineKPI> onClickKPI;
|
|
|
|
public void SetData(SimpleField data)
|
|
{
|
|
this.data = data;
|
|
SetKPIData(data.kpiDataInfo);
|
|
SetMQTTData(data.machineInfo);
|
|
|
|
DetailsKPI.gameObject.SetActive(false);
|
|
}
|
|
private void SetKPIData(UsageKPIData kpiData)
|
|
{
|
|
eorate = DecimalPointCalculate(data.kpiDataInfo.eorate);
|
|
Default_eorate.SetText(eorate.ToString() + "%");
|
|
Details_eorate.SetText(eorate.ToString() + "%");
|
|
|
|
goodqtyrate.SetText(DecimalPointCalculate(data.kpiDataInfo.goodqtyrate).ToString());
|
|
porate.SetText(DecimalPointCalculate(data.kpiDataInfo.porate).ToString());
|
|
}
|
|
private bool CheckDataExists(string value)
|
|
{
|
|
if(value == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public void SetMQTTData(UsageMQTTData mqttData)
|
|
{
|
|
Default_machineName.SetText(mqttData.worknm);
|
|
Details_machineName.SetText(mqttData.worknm);
|
|
}
|
|
private float DecimalPointCalculate(string value)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return 0f;
|
|
}
|
|
|
|
var originFloatValue = float.Parse(value);
|
|
var floatValue = Mathf.Round(originFloatValue * 10f) / 10f;
|
|
|
|
return floatValue;
|
|
}
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
onClickKPI?.Invoke(this);
|
|
}
|
|
|
|
public void Active()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
public void Deactive()
|
|
{
|
|
DefaultKPI.gameObject.SetActive(true);
|
|
DetailsKPI.gameObject.SetActive(false);
|
|
isExpand = false;
|
|
|
|
gameObject.SetActive(false);
|
|
}
|
|
} |