작업 시간 분석 UI 기능 개발
This commit is contained in:
68
Assets/WorkSpace/Personal/JYM/UI_BarChartData.cs
Normal file
68
Assets/WorkSpace/Personal/JYM/UI_BarChartData.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using WI;
|
||||
using UnityEngine.EventSystems;
|
||||
public class UI_BarChartData : UIBase
|
||||
{
|
||||
private TextMeshProUGUI CoolingTimeData;
|
||||
private TextMeshProUGUI HoldingPressureTimeData;
|
||||
private TextMeshProUGUI WeighingTimeData;
|
||||
private TextMeshProUGUI ETCData;
|
||||
|
||||
public TextMeshProUGUI DateTime;
|
||||
|
||||
public Vector3 offset;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
SetActive(false);
|
||||
}
|
||||
public void SetData(BarChartData data)
|
||||
{
|
||||
ShowUINextToClickedUI();
|
||||
|
||||
CoolingTimeData.SetText(ConvertFloatToString(data.coolingTime));
|
||||
HoldingPressureTimeData.SetText(ConvertFloatToString(data.holdingPressureTime));
|
||||
WeighingTimeData.SetText(ConvertFloatToString(data.weighingTime));
|
||||
ETCData.SetText(ConvertFloatToString(data.etc));
|
||||
|
||||
DateTime.SetText(data._time);
|
||||
}
|
||||
private string ConvertFloatToString(float value)
|
||||
{
|
||||
float truncatedFloat = Mathf.Floor(value * 100f) / 100f;
|
||||
return truncatedFloat.ToString();
|
||||
}
|
||||
|
||||
|
||||
void ShowUINextToClickedUI()
|
||||
{
|
||||
RectTransform parentRectTransform = rectTransform.parent.GetComponent<RectTransform>();
|
||||
|
||||
Vector2 localPoint;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, Input.mousePosition, null, out localPoint);
|
||||
|
||||
Vector2 parentSize = parentRectTransform.rect.size;
|
||||
Vector2 uiSize = rectTransform.rect.size;
|
||||
|
||||
float clampedX = Mathf.Clamp(localPoint.x + offset.x, -parentSize.x / 2 + uiSize.x / 2, parentSize.x / 2 - uiSize.x / 2);
|
||||
float clampedY = Mathf.Clamp(localPoint.y + offset.y, -parentSize.y / 2 + uiSize.y / 2, parentSize.y / 2 - uiSize.y / 2);
|
||||
|
||||
rectTransform.localPosition = new Vector2(clampedX, clampedY);
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (EventSystem.current.currentSelectedGameObject != null)
|
||||
return;
|
||||
|
||||
SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user