26 lines
809 B
C#
26 lines
809 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using XCharts.Runtime;
|
||
|
|
||
|
public class PercentTool : MonoBehaviour
|
||
|
{
|
||
|
public BaseChart chart;
|
||
|
public int index;
|
||
|
public float value;
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
value = (float)(chart.series[0].data[index].data[1] / chart.series[1].data[index].data[1]);
|
||
|
if (value > 0)
|
||
|
{
|
||
|
GetComponent<Text>().text = string.Format("{0:f2}%", value * 100);
|
||
|
}
|
||
|
else {
|
||
|
GetComponent<Text>().text = "";
|
||
|
}
|
||
|
transform.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Lerp(-150, 175, Mathf.Clamp(value, 0.5f, 1)), transform.GetComponent<RectTransform>().localPosition.y, transform.GetComponent<RectTransform>().localPosition.z);
|
||
|
}
|
||
|
}
|