DCS/ruiyiweiUX/Assets/Scripts/UI/ChartComponent.cs

125 lines
3.5 KiB
C#
Raw Normal View History

2026-06-09 13:59:11 +08:00
// using System.Collections.Generic;
// using TMPro;
// using UnityEngine;
// using UnityEngine.UI;
// /// <summary>
// /// 用于绘制BFI和血流指数折线图的组件
// /// </summary>
// public class ChartComponent : MonoBehaviour
// {
// [Header("图表设置")]
// public RectTransform chartArea;
// public LineRenderer lineRenderer;
// public TextMeshProUGUI valueLabel;
// public TextMeshProUGUI titleLabel;
// public Color lineColor = Color.green;
// public float lineWidth = 2f;
// [Header("数据设置")]
// public int maxDataPoints = 50;
// public float minValue = 0f;
// public float maxValue = 100f;
// public string unit = "";
// private List<float> dataPoints = new List<float>();
// private Vector3[] linePoints;
// void Awake()
// {
// if (lineRenderer == null)
// {
// lineRenderer = GetComponent<LineRenderer>();
// if (lineRenderer == null)
// {
// var obj = new GameObject("LineRenderer");
// obj.transform.SetParent(transform);
// lineRenderer = obj.AddComponent<LineRenderer>();
// }
// }
// // 设置LineRenderer属性
// lineRenderer.material = new Material(Shader.Find("Sprites/Default"));
// // lineRenderer.color = lineColor;
// lineRenderer.startWidth = lineWidth;
// lineRenderer.endWidth = lineWidth;
// lineRenderer.useWorldSpace = false;
// lineRenderer.sortingOrder = 1;
// linePoints = new Vector3[maxDataPoints];
// }
// /// <summary>
// /// 添加数据点
// /// </summary>
// public void AddDataPoint(float value)
// {
// dataPoints.Add(value);
// // 保持最大数据点数量
// if (dataPoints.Count > maxDataPoints)
// {
// dataPoints.RemoveAt(0);
// }
// UpdateChart();
// UpdateValueLabel(value);
// }
// /// <summary>
// /// 更新图表显示
// /// </summary>
// private void UpdateChart()
// {
// if (dataPoints.Count < 2) return;
// var rect = chartArea.rect;
// var width = rect.width;
// var height = rect.height;
// lineRenderer.positionCount = dataPoints.Count;
// for (int i = 0; i < dataPoints.Count; i++)
// {
// float x = (float)i / (maxDataPoints - 1) * width - width / 2;
// float y = Mathf.Lerp(-height / 2, height / 2,
// Mathf.InverseLerp(minValue, maxValue, dataPoints[i]));
// linePoints[i] = new Vector3(x, y, 0);
// }
// lineRenderer.SetPositions(linePoints);
// }
// /// <summary>
// /// 更新数值标签
// /// </summary>
// private void UpdateValueLabel(float value)
// {
// if (valueLabel != null)
// {
// valueLabel.text = value.ToString("F1") + unit;
// }
// }
// /// <summary>
// /// 设置图表标题
// /// </summary>
// public void SetTitle(string title)
// {
// if (titleLabel != null)
// {
// titleLabel.text = title;
// }
// }
// /// <summary>
// /// 清空数据
// /// </summary>
// public void ClearData()
// {
// dataPoints.Clear();
// lineRenderer.positionCount = 0;
// }
// }