설비 KPI UI 가시성 개선
This commit is contained in:
@@ -16,6 +16,8 @@ namespace CHN
|
||||
private List<Machine> matchingMachines = new();
|
||||
private SDictionary<string, UI_MachineKPI> machineKPIs = new();
|
||||
|
||||
private UI_MachineKPI current_MachineKPI;
|
||||
|
||||
public float defaultNameHeight;
|
||||
public float radius;
|
||||
public Vector3 originScale;
|
||||
@@ -39,6 +41,7 @@ namespace CHN
|
||||
|
||||
var machineKPI = Instantiate(prefab_MachineKPI, transform);
|
||||
machineKPI.SetData(data);
|
||||
machineKPI.onClickKPI += OnClickMachineKPI;
|
||||
machineKPI.name = data.workcd;
|
||||
|
||||
machineKPIs.Add(data.workcd, machineKPI);
|
||||
@@ -59,10 +62,34 @@ namespace CHN
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnClickMachineKPI(UI_MachineKPI machineKPI)
|
||||
{
|
||||
if (current_MachineKPI != null)
|
||||
{
|
||||
current_MachineKPI.Shrink();
|
||||
}
|
||||
current_MachineKPI = machineKPI;
|
||||
current_MachineKPI.Expand();
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
SettingPos();
|
||||
RangeDetection();
|
||||
RectangleContainsPoint();
|
||||
}
|
||||
private void RectangleContainsPoint()
|
||||
{
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
if (current_MachineKPI == null)
|
||||
return;
|
||||
|
||||
if(!RectTransformUtility.RectangleContainsScreenPoint(current_MachineKPI.DetailsKPI, Input.mousePosition))
|
||||
{
|
||||
current_MachineKPI.Shrink();
|
||||
current_MachineKPI = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool Test(Machine machine)
|
||||
{
|
||||
|
||||
@@ -5,47 +5,48 @@ using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.EventSystems;
|
||||
using WI;
|
||||
using System;
|
||||
|
||||
public class UI_MachineKPI : UIBase, IPointerEnterHandler, IPointerExitHandler
|
||||
public class UI_MachineKPI : UIBase, IPointerClickHandler
|
||||
{
|
||||
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;
|
||||
public RectTransform DefaultKPI;
|
||||
public RectTransform DetailsKPI;
|
||||
|
||||
private float originScaleValue;
|
||||
private float eorate;
|
||||
private float timer;
|
||||
private bool isRotating;
|
||||
private TextMeshProUGUI Default_eorate;
|
||||
private TextMeshProUGUI Details_eorate;
|
||||
private TextMeshProUGUI porate;
|
||||
private TextMeshProUGUI goodqtyrate;
|
||||
private TextMeshProUGUI lct;
|
||||
private TextMeshProUGUI wct;
|
||||
|
||||
public bool isExpand;
|
||||
public float duration;
|
||||
public float pauseTimer;
|
||||
private float eorate;
|
||||
|
||||
public float targetHeight;
|
||||
public float duration;
|
||||
|
||||
private float initialHeight;
|
||||
private Vector2 initialSizeDelta;
|
||||
private Vector2 initialPosition;
|
||||
|
||||
public Action<UI_MachineKPI> onClickKPI;
|
||||
|
||||
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());
|
||||
Default_eorate.SetText(eorate.ToString());
|
||||
Details_eorate.SetText(eorate.ToString());
|
||||
lct.SetText(DecimalPointCalculate(kpiData.lct).ToString());
|
||||
wct.SetText(DecimalPointCalculate(kpiData.wct).ToString());
|
||||
goodqtyrate.SetText(DecimalPointCalculate(kpiData.goodqtyrate).ToString());
|
||||
porate.SetText(DecimalPointCalculate(kpiData.porate).ToString());
|
||||
|
||||
Image_eorate.color = eorate >= 50f ? Color.green : Color.red;
|
||||
initialSizeDelta = DetailsKPI.sizeDelta;
|
||||
initialPosition = DetailsKPI.anchoredPosition;
|
||||
initialHeight = DetailsKPI.rect.height;
|
||||
|
||||
timer = pauseTimer;
|
||||
originScaleValue = rectTransform.localScale.x;
|
||||
DetailsKPI.gameObject.SetActive(false);
|
||||
}
|
||||
private float DecimalPointCalculate(string value)
|
||||
{
|
||||
@@ -54,125 +55,86 @@ public class UI_MachineKPI : UIBase, IPointerEnterHandler, IPointerExitHandler
|
||||
|
||||
return floatValue;
|
||||
}
|
||||
public void Active()
|
||||
|
||||
IEnumerator ResizeCoroutine()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
DefaultKPI.gameObject.SetActive(false);
|
||||
DetailsKPI.gameObject.SetActive(true);
|
||||
|
||||
if (!isRotating)
|
||||
var elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
float rotationAmount = -eorate * Time.deltaTime;
|
||||
Image_eorate.transform.Rotate(new Vector3(0, 0, rotationAmount));
|
||||
var progress = elapsedTime / duration;
|
||||
|
||||
if (Mathf.Abs(Image_eorate.transform.rotation.eulerAngles.z) <= 180)
|
||||
{
|
||||
Image_eorate.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
||||
isRotating = true;
|
||||
timer = pauseTimer;
|
||||
}
|
||||
var newHeight = Mathf.Lerp(initialHeight, targetHeight, progress);
|
||||
DetailsKPI.sizeDelta = new Vector2(initialSizeDelta.x, newHeight);
|
||||
|
||||
var newPosY = Mathf.Lerp(initialPosition.y, initialPosition.y - (targetHeight - initialHeight) / 2f, progress);
|
||||
DetailsKPI.anchoredPosition = new Vector2(initialPosition.x, newPosY);
|
||||
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
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);
|
||||
DetailsKPI.sizeDelta = new Vector2(initialSizeDelta.x, targetHeight);
|
||||
DetailsKPI.anchoredPosition = new Vector2(initialPosition.x, initialPosition.y - (targetHeight - initialHeight) / 2f);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
IEnumerator ShrinkCoroutine()
|
||||
{
|
||||
var expandAbleScale = originScaleValue / 8f;
|
||||
var elapsedTime = 0f;
|
||||
var currentHeight = DetailsKPI.rect.height;
|
||||
var currentPosY = DetailsKPI.anchoredPosition.y;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
var progress = elapsedTime / duration;
|
||||
|
||||
var newHeight = Mathf.Lerp(currentHeight, initialHeight, progress);
|
||||
DetailsKPI.sizeDelta = new Vector2(initialSizeDelta.x, newHeight);
|
||||
|
||||
var newPosY = Mathf.Lerp(currentPosY, initialPosition.y, progress);
|
||||
DetailsKPI.anchoredPosition = new Vector2(initialPosition.x, newPosY);
|
||||
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
DetailsKPI.sizeDelta = new Vector2(initialSizeDelta.x, initialHeight);
|
||||
DetailsKPI.anchoredPosition = new Vector2(initialPosition.x, initialPosition.y);
|
||||
|
||||
DefaultKPI.gameObject.SetActive(true);
|
||||
DetailsKPI.gameObject.SetActive(false);
|
||||
}
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
onClickKPI?.Invoke(this);
|
||||
}
|
||||
public void Expand()
|
||||
{
|
||||
if (!isExpand)
|
||||
{
|
||||
if (rectTransform.localScale.x > expandAbleScale)
|
||||
{
|
||||
isRotating = false;
|
||||
timer = 0.0f;
|
||||
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ExpandAnimation());
|
||||
isExpand = true;
|
||||
}
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ResizeCoroutine());
|
||||
isExpand = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
public void Shrink()
|
||||
{
|
||||
if (isExpand)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ReductionAnimation());
|
||||
StartCoroutine(ShrinkCoroutine());
|
||||
|
||||
isExpand = false;
|
||||
}
|
||||
}
|
||||
private IEnumerator ExpandAnimation()
|
||||
public void Active()
|
||||
{
|
||||
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;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
private IEnumerator ReductionAnimation()
|
||||
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(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;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user