update
This commit is contained in:
178
Assets/WorkSpace/Personal/JYM/UI_MachineKPI.cs
Normal file
178
Assets/WorkSpace/Personal/JYM/UI_MachineKPI.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.EventSystems;
|
||||
using WI;
|
||||
|
||||
public class UI_MachineKPI : UIBase, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public Image Image_eorate;
|
||||
public Image Image_RectMask;
|
||||
public Image Image_Name;
|
||||
public TextMeshProUGUI Text_eorate;
|
||||
public TextMeshProUGUI Text_lct;
|
||||
public TextMeshProUGUI Text_wct;
|
||||
public TextMeshProUGUI Text_goodqtyrate;
|
||||
public TextMeshProUGUI Text_porate;
|
||||
|
||||
private float originScaleValue;
|
||||
private float eorate;
|
||||
private float timer;
|
||||
private bool isRotating;
|
||||
|
||||
public bool isExpand;
|
||||
public float duration;
|
||||
public float pauseTimer;
|
||||
|
||||
public float dataExpandScale;
|
||||
public float dataReductionScale;
|
||||
public float nameExpandScale;
|
||||
public float nameReductionScale;
|
||||
public float nameExpandPos;
|
||||
public float nameReductionPos;
|
||||
public void SetData(KPIData kpiData)
|
||||
{
|
||||
eorate = DecimalPointCalculate(kpiData.eorate);
|
||||
|
||||
Text_eorate.SetText(eorate.ToString());
|
||||
Text_lct.SetText(DecimalPointCalculate(kpiData.lct).ToString());
|
||||
Text_wct.SetText(DecimalPointCalculate(kpiData.wct).ToString());
|
||||
Text_goodqtyrate.SetText(DecimalPointCalculate(kpiData.goodqtyrate).ToString());
|
||||
Text_porate.SetText(DecimalPointCalculate(kpiData.porate).ToString());
|
||||
|
||||
Image_eorate.color = eorate >= 50f ? Color.green : Color.red;
|
||||
|
||||
timer = pauseTimer;
|
||||
originScaleValue = rectTransform.localScale.x;
|
||||
}
|
||||
private float DecimalPointCalculate(string value)
|
||||
{
|
||||
var originFloatValue = float.Parse(value);
|
||||
var floatValue = Mathf.Round(originFloatValue * 100f) / 100f;
|
||||
|
||||
return floatValue;
|
||||
}
|
||||
public void Active()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
if (!isRotating)
|
||||
{
|
||||
float rotationAmount = -eorate * Time.deltaTime;
|
||||
Image_eorate.transform.Rotate(new Vector3(0, 0, rotationAmount));
|
||||
|
||||
if (Mathf.Abs(Image_eorate.transform.rotation.eulerAngles.z) <= 180)
|
||||
{
|
||||
Image_eorate.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
||||
isRotating = true;
|
||||
timer = pauseTimer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
if (timer <= 0)
|
||||
{
|
||||
isRotating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Deactive()
|
||||
{
|
||||
var originalScale = Image_RectMask.rectTransform.sizeDelta;
|
||||
var originalNameScale = Image_Name.rectTransform.sizeDelta;
|
||||
var originalNamePos = Image_Name.rectTransform.localPosition;
|
||||
|
||||
var targetScale = new Vector2(0f, originalScale.y);
|
||||
var targetNameScale = new Vector2(originalNameScale.x, 0f);
|
||||
|
||||
var targetNamePos = new Vector3(originalNamePos.x, 0f, originalNamePos.z);
|
||||
|
||||
Image_RectMask.rectTransform.sizeDelta = targetScale;
|
||||
Image_Name.rectTransform.sizeDelta = targetNameScale;
|
||||
Image_Name.rectTransform.localPosition = targetNamePos;
|
||||
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
var expandAbleScale = originScaleValue / 8f;
|
||||
|
||||
if (!isExpand)
|
||||
{
|
||||
if (rectTransform.localScale.x > expandAbleScale)
|
||||
{
|
||||
isRotating = false;
|
||||
timer = 0.0f;
|
||||
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ExpandAnimation());
|
||||
isExpand = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (isExpand)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ReductionAnimation());
|
||||
isExpand = false;
|
||||
}
|
||||
}
|
||||
private IEnumerator ExpandAnimation()
|
||||
{
|
||||
var originalScale = Image_RectMask.rectTransform.sizeDelta;
|
||||
var originalNameScale = Image_Name.rectTransform.sizeDelta;
|
||||
var originalNamePos = Image_Name.rectTransform.localPosition;
|
||||
|
||||
var targetScale = new Vector2(dataExpandScale, originalScale.y);
|
||||
var targetNameScale = new Vector2(originalNameScale.x, nameExpandScale);
|
||||
var targetNamePos = new Vector3(originalNamePos.x, nameExpandPos, originalNamePos.z);
|
||||
|
||||
float elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
var progress = elapsedTime / duration;
|
||||
Image_RectMask.rectTransform.sizeDelta = Vector2.Lerp(originalScale, targetScale, progress);
|
||||
Image_Name.rectTransform.sizeDelta = Vector2.Lerp(originalNameScale, targetNameScale, progress);
|
||||
Image_Name.rectTransform.localPosition = Vector3.Lerp(originalNamePos, targetNamePos, progress);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
Image_RectMask.rectTransform.sizeDelta = targetScale;
|
||||
Image_Name.rectTransform.sizeDelta = targetNameScale;
|
||||
Image_Name.rectTransform.localPosition = targetNamePos;
|
||||
}
|
||||
private IEnumerator ReductionAnimation()
|
||||
{
|
||||
var originalScale = Image_RectMask.rectTransform.sizeDelta;
|
||||
var originalNameScale = Image_Name.rectTransform.sizeDelta;
|
||||
var originalNamePos = Image_Name.rectTransform.localPosition;
|
||||
|
||||
var targetScale = new Vector2(dataReductionScale, originalScale.y);
|
||||
var targetNameScale = new Vector2(originalNameScale.x, nameReductionScale);
|
||||
var targetNamePos = new Vector3(originalNamePos.x, nameReductionPos, originalNamePos.z);
|
||||
|
||||
float elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
var progress = elapsedTime / duration;
|
||||
Image_RectMask.rectTransform.sizeDelta = Vector2.Lerp(originalScale, targetScale, progress);
|
||||
Image_Name.rectTransform.sizeDelta = Vector2.Lerp(originalNameScale, targetNameScale, progress);
|
||||
Image_Name.rectTransform.localPosition = Vector3.Lerp(originalNamePos, targetNamePos, progress);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
Image_RectMask.rectTransform.sizeDelta = targetScale;
|
||||
Image_Name.rectTransform.sizeDelta = targetNameScale;
|
||||
Image_Name.rectTransform.localPosition = targetNamePos;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user