2019-10-22 04:09:04 +08:00
|
|
|
|
/******************************************/
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/* Copyright (c) 2018 monitor1394 */
|
|
|
|
|
|
/* https://github.com/monitor1394 */
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/******************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using UnityEngine;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
using UnityEngine.UI;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
|
|
|
|
|
|
namespace XCharts
|
|
|
|
|
|
{
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// Radar coordinate conponnet for radar charts.
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// 雷达图坐标系组件,只适用于雷达图。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[System.Serializable]
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public class Radar : MainComponent
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
|
|
|
|
|
|
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum Shape
|
|
|
|
|
|
{
|
|
|
|
|
|
Polygon,
|
|
|
|
|
|
Circle
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// The position type of radar.
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// 显示位置。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum PositionType
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// Display at the vertex.
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// 显示在顶点处。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Vertice,
|
|
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// Display at the middle of line.
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// 显示在两者之间。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Between,
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
|
|
|
|
|
|
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[System.Serializable]
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public class Indicator
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-05-15 09:44:18 +08:00
|
|
|
|
[SerializeField] private string m_Name;
|
|
|
|
|
|
[SerializeField] private float m_Max;
|
2019-08-01 23:49:30 +08:00
|
|
|
|
[SerializeField] private float m_Min;
|
2019-11-05 18:58:32 +08:00
|
|
|
|
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
|
|
|
|
|
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// The name of indicator.
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// 指示器名称。
|
|
|
|
|
|
/// </summary>
|
2019-06-20 19:11:06 +08:00
|
|
|
|
public string name { get { return m_Name; } set { m_Name = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The maximum value of indicator, with default value of 0, but we recommend to set it manually.
|
|
|
|
|
|
/// 指示器的最大值,默认为 0 无限制。
|
|
|
|
|
|
/// </summary>
|
2019-06-20 19:11:06 +08:00
|
|
|
|
public float max { get { return m_Max; } set { m_Max = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The minimum value of indicator, with default value of 0.
|
|
|
|
|
|
/// 指示器的最小值,默认为 0 无限制。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public float min { get { return m_Min; } set { m_Min = value; } }
|
|
|
|
|
|
/// <summary>
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// the style of text.
|
|
|
|
|
|
/// 文本样式。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2019-11-05 18:58:32 +08:00
|
|
|
|
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the text conponent of indicator.
|
|
|
|
|
|
/// 指示器的文本组件。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Text text { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
[SerializeField] private Shape m_Shape;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[SerializeField] private float m_Radius = 100;
|
|
|
|
|
|
[SerializeField] private int m_SplitNumber = 5;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
|
2020-02-12 19:13:44 +08:00
|
|
|
|
[SerializeField] private AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[SerializeField] private bool m_Indicator = true;
|
2019-11-05 18:58:32 +08:00
|
|
|
|
[SerializeField] private PositionType m_PositionType = PositionType.Vertice;
|
|
|
|
|
|
[SerializeField] private float m_IndicatorGap = 10;
|
2020-07-25 14:09:57 +08:00
|
|
|
|
[SerializeField] private int m_CeilRate = 0;
|
|
|
|
|
|
[SerializeField] private bool m_IsAxisTooltip;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
|
|
|
|
|
|
/// 雷达图绘制类型,支持 'Polygon' 和 'Circle'。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <value></value>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public Shape shape
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Shape; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_Shape, value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the radius of radar.
|
|
|
|
|
|
/// 雷达图的半径。
|
|
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float radius
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Radius; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_Radius, value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Segments of indicator axis.
|
|
|
|
|
|
/// 指示器轴的分割段数。
|
|
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public int splitNumber
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_SplitNumber; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_SplitNumber, value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// the center of radar chart.
|
|
|
|
|
|
/// 雷达图的中心点。数组的第一项是横坐标,第二项是纵坐标。
|
|
|
|
|
|
/// 当值为0-1之间时表示百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float[] center
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Center; }
|
|
|
|
|
|
set { if (value != null) { m_Center = value; SetAllDirty(); } }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2020-02-12 19:13:44 +08:00
|
|
|
|
/// split line.
|
|
|
|
|
|
/// 分割线。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public AxisSplitLine splitLine
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_SplitLine; }
|
|
|
|
|
|
set { if (PropertyUtility.SetClass(ref m_SplitLine, value, true)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// Split area of axis in grid area.
|
|
|
|
|
|
/// 分割区域。
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public AxisSplitArea splitArea
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_SplitArea; }
|
|
|
|
|
|
set { if (PropertyUtility.SetClass(ref m_SplitArea, value, true)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Whether to show indicator.
|
|
|
|
|
|
/// 是否显示指示器。
|
|
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public bool indicator
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_Indicator; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_Indicator, value)) SetComponentDirty(); }
|
|
|
|
|
|
}
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// The gap of indicator and radar.
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// 指示器和雷达的间距。
|
|
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public float indicatorGap
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_IndicatorGap; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_IndicatorGap, value)) SetComponentDirty(); }
|
|
|
|
|
|
}
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// The ratio of maximum and minimum values rounded upward. The default is 0, which is automatically calculated.
|
2020-06-02 20:20:56 +08:00
|
|
|
|
/// 最大最小值向上取整的倍率。默认为0时自动计算。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int ceilRate
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_CeilRate; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_CeilRate, value < 0 ? 0 : value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2020-07-25 14:09:57 +08:00
|
|
|
|
/// 是否Tooltip显示轴线上的所有数据。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool isAxisTooltip
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_IsAxisTooltip; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_IsAxisTooltip, value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2020-07-10 09:13:26 +08:00
|
|
|
|
/// The position type of indicator.
|
|
|
|
|
|
/// 显示位置类型。
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// </summary>
|
2020-03-05 20:25:19 +08:00
|
|
|
|
public PositionType positionType
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return m_PositionType; }
|
|
|
|
|
|
set { if (PropertyUtility.SetStruct(ref m_PositionType, value)) SetAllDirty(); }
|
|
|
|
|
|
}
|
2019-11-05 18:58:32 +08:00
|
|
|
|
/// <summary>
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// the indicator list.
|
|
|
|
|
|
/// 指示器列表。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public List<Indicator> indicatorList { get { return m_IndicatorList; } }
|
|
|
|
|
|
|
2020-07-31 22:36:34 +08:00
|
|
|
|
public int index { get; internal set; }
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the center position of radar in container.
|
|
|
|
|
|
/// 雷达图在容器中的具体中心点。
|
|
|
|
|
|
/// </summary>
|
2020-03-20 08:31:22 +08:00
|
|
|
|
public Vector3 runtimeCenterPos { get; internal set; }
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the true radius of radar.
|
|
|
|
|
|
/// 雷达图的运行时实际半径。
|
|
|
|
|
|
/// </summary>
|
2019-11-02 08:24:37 +08:00
|
|
|
|
public float runtimeRadius { get; internal set; }
|
2019-11-05 18:58:32 +08:00
|
|
|
|
public float runtimeDataRadius { get; internal set; }
|
2019-08-04 15:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// the data position list of radar.
|
|
|
|
|
|
/// 雷达图的所有数据坐标点列表。
|
|
|
|
|
|
/// </summary>
|
2019-11-02 08:24:37 +08:00
|
|
|
|
public Dictionary<int, List<Vector3>> runtimeDataPosList = new Dictionary<int, List<Vector3>>();
|
2019-08-04 15:24:31 +08:00
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public static Radar defaultRadar
|
|
|
|
|
|
{
|
2019-06-20 19:11:06 +08:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2019-05-11 04:33:54 +08:00
|
|
|
|
var radar = new Radar
|
|
|
|
|
|
{
|
2019-08-04 15:24:31 +08:00
|
|
|
|
m_Shape = Shape.Polygon,
|
2020-02-26 22:52:57 +08:00
|
|
|
|
m_Radius = 0.35f,
|
2019-05-11 04:33:54 +08:00
|
|
|
|
m_SplitNumber = 5,
|
|
|
|
|
|
m_Indicator = true,
|
2019-07-15 00:24:04 +08:00
|
|
|
|
m_IndicatorList = new List<Indicator>(5){
|
2020-05-30 09:41:46 +08:00
|
|
|
|
new Indicator(){name="indicator1",max = 0},
|
|
|
|
|
|
new Indicator(){name="indicator2",max = 0},
|
|
|
|
|
|
new Indicator(){name="indicator3",max = 0},
|
|
|
|
|
|
new Indicator(){name="indicator4",max = 0},
|
|
|
|
|
|
new Indicator(){name="indicator5",max = 0},
|
2019-07-15 00:24:04 +08:00
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
};
|
2019-08-04 15:24:31 +08:00
|
|
|
|
radar.center[0] = 0.5f;
|
2020-02-26 22:52:57 +08:00
|
|
|
|
radar.center[1] = 0.4f;
|
2020-02-12 19:13:44 +08:00
|
|
|
|
radar.splitLine.show = true;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
radar.splitArea.show = true;
|
2020-02-12 19:13:44 +08:00
|
|
|
|
radar.splitLine.lineStyle.width = 0.6f;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
return radar;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-20 19:11:06 +08:00
|
|
|
|
private bool IsEqualsIndicatorList(List<Indicator> indicators1, List<Indicator> indicators2)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (indicators1.Count != indicators2.Count) return false;
|
2019-06-20 19:11:06 +08:00
|
|
|
|
for (int i = 0; i < indicators1.Count; i++)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
var indicator1 = indicators1[i];
|
|
|
|
|
|
var indicator2 = indicators2[i];
|
|
|
|
|
|
if (!indicator1.Equals(indicator2)) return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ParseJsonData(string jsonData)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
|
|
|
|
|
string pattern = "[\"|'](.*?)[\"|']";
|
|
|
|
|
|
if (Regex.IsMatch(jsonData, pattern))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_IndicatorList.Clear();
|
|
|
|
|
|
MatchCollection m = Regex.Matches(jsonData, pattern);
|
|
|
|
|
|
foreach (Match match in m)
|
|
|
|
|
|
{
|
2019-06-20 19:11:06 +08:00
|
|
|
|
m_IndicatorList.Add(new Indicator()
|
|
|
|
|
|
{
|
2019-05-11 04:33:54 +08:00
|
|
|
|
name = match.Groups[1].Value
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
pattern = "(\\d+)";
|
|
|
|
|
|
if (Regex.IsMatch(jsonData, pattern))
|
|
|
|
|
|
{
|
|
|
|
|
|
MatchCollection m = Regex.Matches(jsonData, pattern);
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
foreach (Match match in m)
|
|
|
|
|
|
{
|
2019-06-20 19:11:06 +08:00
|
|
|
|
if (m_IndicatorList[index] != null)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_IndicatorList[index].max = int.Parse(match.Groups[1].Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-07-13 16:38:38 +08:00
|
|
|
|
|
2019-08-04 15:24:31 +08:00
|
|
|
|
public float GetIndicatorMin(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index >= 0 && index < m_IndicatorList.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_IndicatorList[index].min;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2019-07-13 16:38:38 +08:00
|
|
|
|
public float GetIndicatorMax(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index >= 0 && index < m_IndicatorList.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_IndicatorList[index].max;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
|
2020-04-28 12:28:05 +08:00
|
|
|
|
internal void UpdateRadarCenter(Vector3 chartPosition, float chartWidth, float chartHeight)
|
2019-08-04 15:24:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (center.Length < 2) return;
|
|
|
|
|
|
var centerX = center[0] <= 1 ? chartWidth * center[0] : center[0];
|
|
|
|
|
|
var centerY = center[1] <= 1 ? chartHeight * center[1] : center[1];
|
2020-04-28 12:28:05 +08:00
|
|
|
|
runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
|
2019-08-04 15:24:31 +08:00
|
|
|
|
if (radius <= 0)
|
|
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
runtimeRadius = 0;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (radius <= 1)
|
|
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
runtimeRadius = Mathf.Min(chartWidth, chartHeight) * radius;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-02 08:24:37 +08:00
|
|
|
|
runtimeRadius = radius;
|
2019-08-04 15:24:31 +08:00
|
|
|
|
}
|
2019-11-05 18:58:32 +08:00
|
|
|
|
if (shape == Radar.Shape.Polygon && positionType == PositionType.Between)
|
|
|
|
|
|
{
|
|
|
|
|
|
var angle = Mathf.PI / indicatorList.Count;
|
|
|
|
|
|
runtimeDataRadius = runtimeRadius * Mathf.Cos(angle);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
runtimeDataRadius = runtimeRadius;
|
|
|
|
|
|
}
|
2019-08-04 15:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector3 GetIndicatorPosition(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
int indicatorNum = indicatorList.Count;
|
2019-11-05 18:58:32 +08:00
|
|
|
|
var angle = 0f;
|
|
|
|
|
|
switch (positionType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PositionType.Vertice:
|
|
|
|
|
|
angle = 2 * Mathf.PI / indicatorNum * index;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case PositionType.Between:
|
|
|
|
|
|
angle = 2 * Mathf.PI / indicatorNum * (index + 0.5f);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
var x = runtimeCenterPos.x + (runtimeRadius + indicatorGap) * Mathf.Sin(angle);
|
|
|
|
|
|
var y = runtimeCenterPos.y + (runtimeRadius + indicatorGap) * Mathf.Cos(angle);
|
2019-08-04 15:24:31 +08:00
|
|
|
|
return new Vector3(x, y);
|
|
|
|
|
|
}
|
2019-12-20 09:17:15 +08:00
|
|
|
|
|
|
|
|
|
|
public Radar.Indicator AddIndicator(string name, float min, float max)
|
|
|
|
|
|
{
|
|
|
|
|
|
var indicator = new Radar.Indicator();
|
|
|
|
|
|
indicator.name = name;
|
|
|
|
|
|
indicator.min = min;
|
|
|
|
|
|
indicator.max = max;
|
|
|
|
|
|
indicatorList.Add(indicator);
|
2020-03-05 20:25:19 +08:00
|
|
|
|
SetAllDirty();
|
2019-12-20 09:17:15 +08:00
|
|
|
|
return indicator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool UpdateIndicator(int indicatorIndex, string name, float min, float max)
|
|
|
|
|
|
{
|
|
|
|
|
|
var indicator = GetIndicator(indicatorIndex);
|
|
|
|
|
|
if (indicator == null) return false;
|
|
|
|
|
|
indicator.name = name;
|
|
|
|
|
|
indicator.min = min;
|
|
|
|
|
|
indicator.max = max;
|
2020-03-05 20:25:19 +08:00
|
|
|
|
SetAllDirty();
|
2019-12-20 09:17:15 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Radar.Indicator GetIndicator(int indicatorIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (indicatorIndex < 0 || indicatorIndex > indicatorList.Count - 1) return null;
|
|
|
|
|
|
return indicatorList[indicatorIndex];
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|