72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using WI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class UI_GraphChartData : UIBase, ISingle
|
|
{
|
|
public TextMeshProUGUI DataName;
|
|
public TextMeshProUGUI DataValue;
|
|
public TextMeshProUGUI DateTime;
|
|
|
|
public Vector3 offset;
|
|
private OrbitalController orbitalController;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
orbitalController = FindSingle<OrbitalController>();
|
|
SetActive(false);
|
|
}
|
|
public void SetData(string dataName, float dataValue, string dateTime, Vector3 pos)
|
|
{
|
|
ShowUINextToClickedUI(pos);
|
|
|
|
DataName.SetText(dataName);
|
|
DateTime.SetText(dateTime);
|
|
|
|
float truncatedFloat = Mathf.Floor(dataValue * 10f) / 10f;
|
|
DataValue.SetText(SetUnit(dataName, truncatedFloat));
|
|
}
|
|
private string SetUnit(string dataName, float dataValue)
|
|
{
|
|
var value = "";
|
|
float truncatedFloat = Mathf.Floor(dataValue * 10f) / 10f;
|
|
|
|
switch (dataName)
|
|
{
|
|
case "보압 (Peak)":
|
|
value = truncatedFloat + " bar";
|
|
break;
|
|
case "주변 습도":
|
|
value = truncatedFloat + " %";
|
|
break;
|
|
case "주변 온도":
|
|
value = truncatedFloat + " °C";
|
|
break;
|
|
case "싸이클 타임":
|
|
value = truncatedFloat + " 초";
|
|
break;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
|
|
void ShowUINextToClickedUI(Vector3 topPosition)
|
|
{
|
|
RectTransform parentRectTransform = rectTransform.parent.GetComponent<RectTransform>();
|
|
|
|
var parentSize = parentRectTransform.rect.size;
|
|
var uiSize = rectTransform.rect.size;
|
|
|
|
Vector2 localPoint;
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, Input.mousePosition, null, out localPoint);
|
|
|
|
float clampedX = Mathf.Clamp(topPosition.x + offset.x, -parentSize.x / 2 + uiSize.x / 2, parentSize.x / 2 - uiSize.x / 2);
|
|
|
|
rectTransform.localPosition = new Vector2(clampedX, localPoint.y + offset.y);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|