설비 KPI 디자인 및 기능 수정
This commit is contained in:
@@ -15,16 +15,18 @@ namespace CHN
|
||||
private Machine[] machines;
|
||||
private List<Machine> matchingMachines = new();
|
||||
private SDictionary<string, UI_MachineKPI> machineKPIs = new();
|
||||
private List<UI_MachineKPI> kpis = new List<UI_MachineKPI>();
|
||||
|
||||
private UI_MachineKPI current_MachineKPI;
|
||||
|
||||
public float defaultNameHeight;
|
||||
public float radius;
|
||||
public Vector3 originScale;
|
||||
public float verticalSpacing = 100f;
|
||||
|
||||
[Range(0.1f, 0.5f)]
|
||||
[Range(0.1f, 0.8f)]
|
||||
public float minScale;
|
||||
[Range(0.5f, 1f)]
|
||||
[Range(0.5f, 1.5f)]
|
||||
public float maxScale;
|
||||
[Range(0.1f, 2f)]
|
||||
public float scaleClamp;
|
||||
@@ -50,7 +52,9 @@ namespace CHN
|
||||
machineKPI.onClickKPI += OnClickMachineKPI;
|
||||
machineKPI.name = data.workcd;
|
||||
machineKPI.SetActive(false);
|
||||
uiElements.Add(machineKPI.rectTransform);
|
||||
|
||||
kpis.Add(machineKPI);
|
||||
machineKPIs.Add(data.workcd, machineKPI);
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ namespace CHN
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
SettingPos();
|
||||
GroupOverlappingUIElements();
|
||||
RangeDetection();
|
||||
RectangleContainsPoint();
|
||||
}
|
||||
@@ -100,19 +104,86 @@ namespace CHN
|
||||
}
|
||||
}
|
||||
}
|
||||
void SettingPos()
|
||||
{
|
||||
foreach (var machine in matchingMachines)
|
||||
{
|
||||
var machinePos = machine.centerPos;
|
||||
public List<RectTransform> uiElements = new List<RectTransform>();
|
||||
public List<List<RectTransform>> groupedElements = new List<List<RectTransform>>();
|
||||
|
||||
Vector3 screenPos = cam.camera.WorldToScreenPoint(new Vector3(machinePos.x, machinePos.y + defaultNameHeight, machinePos.z));
|
||||
if (screenPos.z > 0)
|
||||
void GroupOverlappingUIElements()
|
||||
{
|
||||
foreach(var matchingMachine in matchingMachines)
|
||||
{
|
||||
var machinePos = matchingMachine.centerPos;
|
||||
var screenPos = cam.camera.WorldToScreenPoint(new Vector3(machinePos.x, machinePos.y + defaultNameHeight, machinePos.z));
|
||||
|
||||
matchingMachine.machineKPI.transform.position = screenPos;
|
||||
}
|
||||
|
||||
// 그룹화된 UI 요소들을 초기화
|
||||
groupedElements.Clear();
|
||||
|
||||
// UI 요소들을 겹침 여부에 따라 그룹화
|
||||
var uncheckedElements = new HashSet<RectTransform>(uiElements); // 겹침 여부 체크 안된 UI 요소들
|
||||
|
||||
// 겹침을 확인할 UI 요소들을 순차적으로 그룹화
|
||||
while (uncheckedElements.Count > 0)
|
||||
{
|
||||
var currentElement = uncheckedElements.First();
|
||||
uncheckedElements.Remove(currentElement);
|
||||
var group = new List<RectTransform> { currentElement };
|
||||
|
||||
// 그룹화된 UI 요소들을 추가
|
||||
var overlappingElements = uncheckedElements.Where(element => AreRectanglesOverlapping(currentElement, element)).ToList();
|
||||
foreach (var overlappingElement in overlappingElements)
|
||||
{
|
||||
machine.machineKPI.transform.position = screenPos;
|
||||
uncheckedElements.Remove(overlappingElement);
|
||||
group.Add(overlappingElement);
|
||||
}
|
||||
|
||||
groupedElements.Add(group);
|
||||
}
|
||||
|
||||
foreach (var group in groupedElements)
|
||||
{
|
||||
var centerPos = GroupCenterCalculate(group);
|
||||
|
||||
for (int i = 0; i < group.Count; i++)
|
||||
{
|
||||
var kpi = group[i];
|
||||
var newPos = new Vector3(centerPos.x, centerPos.y + kpi.rect.height * i * kpi.transform.localScale.y, centerPos.z);
|
||||
|
||||
kpi.transform.localPosition = newPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool AreRectanglesOverlapping(RectTransform rectA, RectTransform rectB)
|
||||
{
|
||||
Rect rectAWorld = GetWorldRect(rectA);
|
||||
Rect rectBWorld = GetWorldRect(rectB);
|
||||
|
||||
return rectAWorld.Overlaps(rectBWorld);
|
||||
}
|
||||
private Rect GetWorldRect(RectTransform rectTransform)
|
||||
{
|
||||
Vector3[] worldCorners = new Vector3[4];
|
||||
rectTransform.GetWorldCorners(worldCorners);
|
||||
|
||||
Vector2 min = new Vector2(worldCorners[0].x, worldCorners[0].y);
|
||||
Vector2 max = new Vector2(worldCorners[2].x, worldCorners[2].y);
|
||||
|
||||
return new Rect(min, max - min);
|
||||
}
|
||||
private Vector3 GroupCenterCalculate(List<RectTransform> group)
|
||||
{
|
||||
var centerPos = Vector3.zero;
|
||||
group.Sort((a, b) => a.transform.localPosition.y.CompareTo(b.transform.localPosition.y));
|
||||
|
||||
foreach (var kpi in group)
|
||||
{
|
||||
centerPos += kpi.transform.localPosition;
|
||||
}
|
||||
centerPos /= group.Count;
|
||||
|
||||
return centerPos;
|
||||
}
|
||||
void RangeDetection()
|
||||
{
|
||||
var layerMask = LayerMask.GetMask("Camera", "Floor Wall");
|
||||
@@ -128,6 +199,7 @@ namespace CHN
|
||||
{
|
||||
if (machine.GetComponentInParent<Floor>() != currentFloor)
|
||||
{
|
||||
machine.machineKPI.Deactive();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ public class UI_MachineKPI : UIBase, IPointerClickHandler
|
||||
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;
|
||||
@@ -30,8 +32,11 @@ public class UI_MachineKPI : UIBase, IPointerClickHandler
|
||||
data = kpiData;
|
||||
eorate = DecimalPointCalculate(kpiData.eorate);
|
||||
|
||||
Default_eorate.SetText(eorate.ToString());
|
||||
Details_eorate.SetText(eorate.ToString());
|
||||
Default_machineName.SetText(kpiData.worknm);
|
||||
Details_machineName.SetText(kpiData.worknm);
|
||||
|
||||
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());
|
||||
@@ -42,7 +47,7 @@ public class UI_MachineKPI : UIBase, IPointerClickHandler
|
||||
private float DecimalPointCalculate(string value)
|
||||
{
|
||||
var originFloatValue = float.Parse(value);
|
||||
var floatValue = Mathf.Round(originFloatValue * 100f) / 100f;
|
||||
var floatValue = Mathf.Round(originFloatValue * 10f) / 10f;
|
||||
|
||||
return floatValue;
|
||||
}
|
||||
|
||||
71
Assets/WorkSpace/Personal/JYM/UI_StatusContent.cs
Normal file
71
Assets/WorkSpace/Personal/JYM/UI_StatusContent.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static MQTT;
|
||||
|
||||
public class UI_StatusContent : MonoBehaviour
|
||||
{
|
||||
public Dictionary<string, UI_MachineStatus> machineStatuses = new Dictionary<string, UI_MachineStatus>();
|
||||
private UI_MachineStatus prf_machineStatus;
|
||||
public Vector3 resetPosition;
|
||||
|
||||
private float moveSpeed;
|
||||
private Vector3 centerPosition;
|
||||
private Vector3 endContentPosition;
|
||||
public override void AfterAwake()
|
||||
{
|
||||
prf_machineStatus = Resources.Load<UI_MachineStatus>("Prefabs/UI/UI_StatusItem");
|
||||
}
|
||||
public void SetEndPosition(Vector3 centerPos, Vector3 endPos, float speed)
|
||||
{
|
||||
centerPosition = centerPos;
|
||||
endContentPosition = endPos;
|
||||
moveSpeed = speed;
|
||||
}
|
||||
public void SetProductionStatusItem(List<CompleteInfo> machineInfos)
|
||||
{
|
||||
bool odd = true;
|
||||
foreach (var machineInfo in machineInfos)
|
||||
{
|
||||
if (!machineStatuses.ContainsKey(machineInfo.worknm))
|
||||
{
|
||||
var machineStatus = Instantiate(prf_machineStatus, transform);
|
||||
machineStatuses.Add(machineInfo.worknm, machineStatus);
|
||||
}
|
||||
|
||||
if (odd)
|
||||
{
|
||||
machineStatuses[machineInfo.worknm].SetStatusData(machineInfo, new Color(0.07058824f, 0.1294118f, 0.2941177f));
|
||||
}
|
||||
else
|
||||
{
|
||||
machineStatuses[machineInfo.worknm].SetStatusData(machineInfo, new Color(0.04313726f, 0.09019608f, 0.2235294f));
|
||||
}
|
||||
odd = !odd;
|
||||
}
|
||||
}
|
||||
public void StartMoveAnimation()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(MoveAnimation());
|
||||
}
|
||||
private IEnumerator MoveAnimation()
|
||||
{
|
||||
while (transform.localPosition.x >= resetPosition.x)
|
||||
{
|
||||
transform.localPosition += Vector3.left * moveSpeed;
|
||||
|
||||
if (transform.localPosition.x == centerPosition.x)
|
||||
{
|
||||
yield return new WaitForSeconds(2f);
|
||||
}
|
||||
|
||||
if (transform.localPosition.x == resetPosition.x)
|
||||
{
|
||||
yield return new WaitForSeconds(2f);
|
||||
transform.localPosition = endContentPosition;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/WorkSpace/Personal/JYM/UI_StatusContent.cs.meta
Normal file
2
Assets/WorkSpace/Personal/JYM/UI_StatusContent.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d89c0cf7b93c1d46897f7c95cd0e6ff
|
||||
Reference in New Issue
Block a user