47 lines
1.3 KiB
C#
47 lines
1.3 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(truncatedFloat.ToString());
|
|
}
|
|
|
|
|
|
void ShowUINextToClickedUI(Vector3 topPosition)
|
|
{
|
|
RectTransform parentRectTransform = rectTransform.parent.GetComponent<RectTransform>();
|
|
|
|
var parentSize = parentRectTransform.rect.size;
|
|
var uiSize = rectTransform.rect.size;
|
|
|
|
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, offset.y);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|