mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-16 05:10:12 +00:00
完善数据操作接口
This commit is contained in:
@@ -24,6 +24,8 @@ namespace XCharts
|
||||
|
||||
[SerializeField] private Bar m_Bar = new Bar();
|
||||
|
||||
public Bar bar { get { return m_Bar; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -52,7 +54,7 @@ namespace XCharts
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsShowSeries(serie.name)) continue;
|
||||
if (!m_Legend.IsActive(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
@@ -112,7 +114,7 @@ namespace XCharts
|
||||
for (int n = 0; n < serieList.Count; n++)
|
||||
{
|
||||
Serie serie = serieList[n];
|
||||
if (!m_Legend.IsShowSeries(serie.name)) continue;
|
||||
if (!m_Legend.IsActive(serie.name)) continue;
|
||||
Color color = m_ThemeInfo.GetColor(serieCount);
|
||||
int maxCount = maxShowDataNumber > 0 ?
|
||||
(maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace XCharts
|
||||
{
|
||||
Value,
|
||||
Category,
|
||||
Time,
|
||||
Log
|
||||
//Time,
|
||||
//Log
|
||||
}
|
||||
|
||||
public enum SplitLineType
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -101,29 +102,65 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(string legend, float value)
|
||||
public void ClearData()
|
||||
{
|
||||
m_Series.ClearData();
|
||||
m_Legend.ClearData();
|
||||
}
|
||||
|
||||
public virtual void AddData(string legend, float value)
|
||||
{
|
||||
m_Legend.AddData(legend);
|
||||
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void AddData(int legend, float value)
|
||||
public virtual void AddData(int legend, float value)
|
||||
{
|
||||
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
public virtual void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(legend, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
public virtual void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(legendIndex, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public virtual void SetActive(string legend,bool active)
|
||||
{
|
||||
m_Legend.SetActive(legend, active);
|
||||
m_Series.SetActive(legend, active);
|
||||
}
|
||||
|
||||
public virtual void SetActive(int index, bool active)
|
||||
{
|
||||
m_Legend.SetActive(index, active);
|
||||
m_Series.SetActive(index, active);
|
||||
}
|
||||
|
||||
public virtual bool IsActive(string name)
|
||||
{
|
||||
return m_Legend.IsActive(name) || m_Series.IsActive(name);
|
||||
}
|
||||
|
||||
public virtual bool IsActive(int index)
|
||||
{
|
||||
return m_Legend.IsActive(index) || m_Series.IsActive(index);
|
||||
}
|
||||
|
||||
public virtual void RemoveData(string legend)
|
||||
{
|
||||
m_Legend.RemoveData(legend);
|
||||
m_Series.RemoveData(legend);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateTheme(Theme theme)
|
||||
{
|
||||
this.m_Theme = theme;
|
||||
@@ -189,14 +226,15 @@ namespace XCharts
|
||||
m_Legend.SetButton(i, btn);
|
||||
m_Legend.UpdateButtonColor(i, m_ThemeInfo.GetColor(i), m_ThemeInfo.unableColor);
|
||||
btn.GetComponentInChildren<Text>().text = m_Legend.data[i];
|
||||
btn.onClick.AddListener(delegate ()
|
||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||
{
|
||||
int index = int.Parse(btn.name.Split('_')[1]);
|
||||
m_Legend.SetShowData(index, !m_Legend.IsShowSeries(index));
|
||||
m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index), m_ThemeInfo.unableColor);
|
||||
OnYMaxValueChanged();
|
||||
OnLegendButtonClicked();
|
||||
RefreshChart();
|
||||
int count = (data as PointerEventData).clickCount;
|
||||
int index = int.Parse(data.selectedObject.name.Split('_')[1]);
|
||||
SetActive(index, !m_Legend.IsActive(index));
|
||||
m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index), m_ThemeInfo.unableColor);
|
||||
OnYMaxValueChanged();
|
||||
OnLegendButtonClicked();
|
||||
RefreshChart();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -260,7 +298,7 @@ namespace XCharts
|
||||
|
||||
private void CheckTooltip()
|
||||
{
|
||||
if (!m_Tooltip.show) return;
|
||||
if (!m_Tooltip.show || !m_Tooltip.isInited) return;
|
||||
m_Tooltip.dataIndex = 0;
|
||||
Vector2 local;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace XCharts
|
||||
[SerializeField] private int m_ItemFontSize = 18;
|
||||
[SerializeField] private List<string> m_Data = new List<string>();
|
||||
|
||||
[NonSerialized] private List<bool> m_DataShowList = new List<bool>();
|
||||
[NonSerialized] private List<bool> m_DataActiveList = new List<bool>();
|
||||
[NonSerialized] private List<Button> m_DataBtnList = new List<Button>();
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
@@ -109,33 +109,67 @@ namespace XCharts
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public bool IsShowSeries(string name)
|
||||
public bool IsActive(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return true;
|
||||
for(int i = 0; i < data.Count; i++)
|
||||
{
|
||||
if (name.Equals(data[i])) return m_DataShowList[i];
|
||||
if (data[i].Equals(name)) return m_DataActiveList[i];
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsShowSeries(int seriesIndex)
|
||||
public bool IsActive(int seriesIndex)
|
||||
{
|
||||
if (seriesIndex < 0 || seriesIndex > data.Count - 1) seriesIndex = 0;
|
||||
if (seriesIndex >= data.Count) return false;
|
||||
if (seriesIndex < 0 || seriesIndex > m_DataShowList.Count - 1)
|
||||
{
|
||||
if (seriesIndex >= data.Count) return true;
|
||||
if (seriesIndex < 0 || seriesIndex > m_DataActiveList.Count - 1)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return m_DataActiveList[seriesIndex];
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Data.Clear();
|
||||
}
|
||||
|
||||
public bool ContainsData(string name)
|
||||
{
|
||||
return m_Data.Contains(name);
|
||||
}
|
||||
|
||||
public void RemoveData(string name)
|
||||
{
|
||||
if (m_Data.Contains(name))
|
||||
{
|
||||
return m_DataShowList[seriesIndex];
|
||||
m_Data.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(int index, bool flag)
|
||||
public void AddData(string name)
|
||||
{
|
||||
m_DataShowList[index] = flag;
|
||||
if (!m_Data.Contains(name))
|
||||
{
|
||||
m_Data.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(int index, bool flag)
|
||||
{
|
||||
m_DataActiveList[index] = flag;
|
||||
}
|
||||
|
||||
public void SetActive(string name, bool flag)
|
||||
{
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
if (data[i].Equals(name))
|
||||
{
|
||||
m_DataActiveList[i] = flag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetButton(int index, Button btn)
|
||||
@@ -144,7 +178,7 @@ namespace XCharts
|
||||
if (index < 0 || index > m_DataBtnList.Count - 1)
|
||||
{
|
||||
m_DataBtnList.Add(btn);
|
||||
m_DataShowList.Add(true);
|
||||
m_DataActiveList.Add(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,7 +190,7 @@ namespace XCharts
|
||||
|
||||
public void UpdateButtonColor(int index,Color ableColor,Color unableColor)
|
||||
{
|
||||
if (IsShowSeries(index))
|
||||
if (IsActive(index))
|
||||
{
|
||||
m_DataBtnList[index].GetComponent<Image>().color = ableColor;
|
||||
}
|
||||
@@ -166,18 +200,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(string name, bool flag)
|
||||
{
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
if (data[i].Equals(name))
|
||||
{
|
||||
m_DataShowList[i] = flag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
m_Location.OnChanged();
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace XCharts
|
||||
[System.Serializable]
|
||||
public class Indicator: IEquatable<Indicator>
|
||||
{
|
||||
public string m_Name;
|
||||
public float m_Max;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private float m_Max;
|
||||
|
||||
public string name { get { return m_Name; }set { m_Name = value; } }
|
||||
public float max { get { return m_Max; }set { m_Max = value; } }
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace XCharts
|
||||
public SerieType type { get { return m_Type; } set { m_Type = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public string stack { get { return m_Stack; } set { m_Stack = value; } }
|
||||
public List<float> data { get { return m_Data; } }
|
||||
public List<float> data { get { return m_Data; }set { m_Data = value; } }
|
||||
|
||||
public float Max
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace XCharts
|
||||
m_Data.RemoveAt(index);
|
||||
}
|
||||
|
||||
public void AddData(float value, int maxDataNumber)
|
||||
public void AddData(float value, int maxDataNumber = 0)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
|
||||
@@ -46,47 +46,121 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void AddData(string legend, float value, int maxDataNumber = 0)
|
||||
public Serie GetSerie(string name)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series[i].name.Equals(legend))
|
||||
if (name.Equals(m_Series[i].name))
|
||||
{
|
||||
m_Series[i].AddData(value, maxDataNumber);
|
||||
break;
|
||||
return m_Series[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddData(int legend, float value, int maxDataNumber = 0)
|
||||
public Serie GetSerie(int index)
|
||||
{
|
||||
if (legend >= 0 && legend < Count)
|
||||
if (index >= 0 && index < m_Series.Count)
|
||||
{
|
||||
m_Series[legend].AddData(value, maxDataNumber);
|
||||
return m_Series[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
public bool Contains(string name)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Series[i].name.Equals(legend))
|
||||
if (name.Equals(m_Series[i].name))
|
||||
{
|
||||
m_Series[i].UpdateData(dataIndex, value);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveData(string name)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
m_Series.Remove(serie);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
public Serie AddData(string name, float value, int maxDataNumber = 0)
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
if (m_Series == null)
|
||||
{
|
||||
if (i == legendIndex)
|
||||
{
|
||||
m_Series[i].UpdateData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
m_Series = new List<Serie>();
|
||||
}
|
||||
var serie = GetSerie(name);
|
||||
if (serie == null)
|
||||
{
|
||||
serie = new Serie();
|
||||
serie.name = name;
|
||||
serie.data = new List<float>();
|
||||
m_Series.Add(serie);
|
||||
}
|
||||
serie.AddData(value, maxDataNumber);
|
||||
return serie;
|
||||
}
|
||||
|
||||
public Serie AddData(int index, float value, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddData(value, maxDataNumber);
|
||||
}
|
||||
return serie;
|
||||
}
|
||||
|
||||
public void UpdateData(string name, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateData(dataIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(int index, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateData(dataIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsActive(string name)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
return serie == null ? false : serie.show;
|
||||
}
|
||||
|
||||
public bool IsActive(int index)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
return serie == null ? false : serie.show;
|
||||
}
|
||||
|
||||
public void SetActive(string name, bool active)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.show = active;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(int index, bool active)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.show = active;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +199,7 @@ namespace XCharts
|
||||
{
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (legend.IsShowSeries(i))
|
||||
if (legend.IsActive(i))
|
||||
{
|
||||
if (m_Series[i].Max > max) max = m_Series[i].Max;
|
||||
if (m_Series[i].Min < min) min = m_Series[i].Min;
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace XCharts
|
||||
public int lastDataIndex { get; set; }
|
||||
public float width { get { return m_BackgroudRect.sizeDelta.x; } }
|
||||
public float height { get { return m_BackgroudRect.sizeDelta.y; } }
|
||||
public bool isInited { get { return m_GameObject != null; } }
|
||||
|
||||
public static Tooltip defaultTooltip
|
||||
{
|
||||
@@ -45,13 +46,19 @@ namespace XCharts
|
||||
|
||||
public void SetTextColor(Color color)
|
||||
{
|
||||
m_Text.color = color;
|
||||
if (m_Text)
|
||||
{
|
||||
m_Text.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTooltipText(string txt)
|
||||
{
|
||||
m_Text.text = txt;
|
||||
m_BackgroudRect.sizeDelta = new Vector2(m_Text.preferredWidth + 8, m_Text.preferredHeight + 8);
|
||||
if (m_Text)
|
||||
{
|
||||
m_Text.text = txt;
|
||||
m_BackgroudRect.sizeDelta = new Vector2(m_Text.preferredWidth + 8, m_Text.preferredHeight + 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
@@ -68,7 +75,10 @@ namespace XCharts
|
||||
|
||||
public Vector3 GetPos()
|
||||
{
|
||||
return m_GameObject.transform.localPosition;
|
||||
if (m_GameObject)
|
||||
return m_GameObject.transform.localPosition;
|
||||
else
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ namespace XCharts
|
||||
{
|
||||
[SerializeField] private Line m_Line = Line.defaultLine;
|
||||
|
||||
public Line line { get { return line; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -43,7 +45,7 @@ namespace XCharts
|
||||
float scaleWid = m_XAxis.GetDataWidth(coordinateWid);
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(j)) continue;
|
||||
if (!IsActive(j)) continue;
|
||||
Serie serie = m_Series.series[j];
|
||||
Color32 color = m_ThemeInfo.GetColor(j);
|
||||
Vector3 lp = Vector3.zero;
|
||||
@@ -131,7 +133,7 @@ namespace XCharts
|
||||
float scaleWid = m_YAxis.GetDataWidth(coordinateHig);
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(j)) continue;
|
||||
if (!IsActive(j)) continue;
|
||||
Serie serie = m_Series.series[j];
|
||||
Color32 color = m_ThemeInfo.GetColor(j);
|
||||
Vector3 lp = Vector3.zero;
|
||||
|
||||
@@ -15,6 +15,30 @@ namespace XCharts
|
||||
private Vector2 m_PieCenter;
|
||||
private List<float> m_AngleList = new List<float>();
|
||||
|
||||
public Pie pie { get { return m_Pie; } }
|
||||
|
||||
public override void AddData(string legend, float value)
|
||||
{
|
||||
m_Legend.AddData(legend);
|
||||
var serie = m_Series.AddData(legend,value);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.ClearData();
|
||||
serie.AddData(value);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = m_Series.GetSerie(legend);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateData(0, value);
|
||||
RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -36,7 +60,7 @@ namespace XCharts
|
||||
m_AngleList.Clear();
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(i))
|
||||
if (!IsActive(i))
|
||||
{
|
||||
m_AngleList.Add(0);
|
||||
continue;
|
||||
@@ -70,7 +94,7 @@ namespace XCharts
|
||||
float total = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Legend.IsShowSeries(i))
|
||||
if (IsActive(i))
|
||||
{
|
||||
total += m_Series.series[i].GetData(0);
|
||||
}
|
||||
@@ -83,7 +107,7 @@ namespace XCharts
|
||||
float max = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (m_Legend.IsShowSeries(i) && m_Series.series[i].GetData(0) > max)
|
||||
if (IsActive(i) && m_Series.series[i].GetData(0) > max)
|
||||
{
|
||||
max = m_Series.series[i].GetData(0);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace XCharts
|
||||
private List<Text> indicatorTextList = new List<Text>();
|
||||
private List<List<Vector3>> dataPosList = new List<List<Vector3>>();
|
||||
|
||||
public Radar radar { get { return m_Radar; } }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -144,7 +145,7 @@ namespace XCharts
|
||||
dataPosList.Capacity = m_Series.Count;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(i))
|
||||
if (!IsActive(i))
|
||||
{
|
||||
dataPosList.Add(new List<Vector3>());
|
||||
continue;
|
||||
@@ -286,7 +287,7 @@ namespace XCharts
|
||||
m_Tooltip.dataIndex = 0;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
if (!m_Legend.IsShowSeries(i)) continue;
|
||||
if (!IsActive(i)) continue;
|
||||
for (int j = 0; j < dataPosList[i].Count; j++)
|
||||
{
|
||||
if (Vector3.Distance(local, dataPosList[i][j]) <= m_Radar.linePointSize * 1.2f)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
@@ -42,6 +43,18 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFullName(Transform transform)
|
||||
{
|
||||
string name = transform.name;
|
||||
Transform obj = transform;
|
||||
while (obj.transform.parent)
|
||||
{
|
||||
name += "/"+obj.transform.parent.name;
|
||||
obj = obj.transform.parent;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static T GetOrAddComponent<T>(Transform transform) where T : Component
|
||||
{
|
||||
return GetOrAddComponent<T>(transform.gameObject);
|
||||
@@ -462,5 +475,17 @@ namespace XCharts
|
||||
if (max < 0) return (int)-mm;
|
||||
else return (int)mm;
|
||||
}
|
||||
|
||||
public static void AddEventListener(GameObject obj, EventTriggerType type,
|
||||
UnityEngine.Events.UnityAction<BaseEventData> call)
|
||||
{
|
||||
EventTrigger trigger = GetOrAddComponent<EventTrigger>(obj.gameObject);
|
||||
EventTrigger.Entry entry1 = new EventTrigger.Entry();
|
||||
entry1.eventID = type;
|
||||
entry1.callback = new EventTrigger.TriggerEvent();
|
||||
entry1.callback.AddListener(call);
|
||||
trigger.triggers.Clear();
|
||||
trigger.triggers.Add(entry1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user