暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerieData.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using XUGL;
  5. namespace XCharts.Runtime
  6. {
  7. /// <summary>
  8. /// A data item of serie.
  9. /// |系列中的一个数据项。可存储数据名和1-n维个数据。
  10. /// </summary>
  11. [System.Serializable]
  12. public class SerieData : ChildComponent
  13. {
  14. public static List<string> extraFieldList = new List<string>()
  15. {
  16. "m_Id",
  17. "m_ParentId",
  18. "m_State",
  19. "m_Ignore",
  20. "m_Selected",
  21. "m_Radius",
  22. };
  23. public static Dictionary<Type, string> extraComponentMap = new Dictionary<Type, string>
  24. { { typeof(ItemStyle), "m_ItemStyles" },
  25. { typeof(LabelStyle), "m_Labels" },
  26. { typeof(LabelLine), "m_LabelLines" },
  27. { typeof(SerieSymbol), "m_Symbols" },
  28. { typeof(LineStyle), "m_LineStyles" },
  29. { typeof(AreaStyle), "m_AreaStyles" },
  30. { typeof(TitleStyle), "m_TitleStyles" },
  31. { typeof(EmphasisStyle), "m_EmphasisStyles" },
  32. { typeof(BlurStyle), "m_BlurStyles" },
  33. { typeof(SelectStyle), "m_SelectStyles" },
  34. };
  35. [SerializeField] private int m_Index;
  36. [SerializeField] private string m_Name;
  37. [SerializeField] private string m_Id;
  38. [SerializeField] private string m_ParentId;
  39. [SerializeField] private bool m_Ignore;
  40. [SerializeField] private bool m_Selected;
  41. [SerializeField] private float m_Radius;
  42. [SerializeField][Since("v3.2.0")] private SerieState m_State = SerieState.Auto;
  43. [SerializeField][IgnoreDoc] private List<ItemStyle> m_ItemStyles = new List<ItemStyle>();
  44. [SerializeField][IgnoreDoc] private List<LabelStyle> m_Labels = new List<LabelStyle>();
  45. [SerializeField][IgnoreDoc] private List<LabelLine> m_LabelLines = new List<LabelLine>();
  46. [SerializeField][IgnoreDoc] private List<SerieSymbol> m_Symbols = new List<SerieSymbol>();
  47. [SerializeField][IgnoreDoc] private List<LineStyle> m_LineStyles = new List<LineStyle>();
  48. [SerializeField][IgnoreDoc] private List<AreaStyle> m_AreaStyles = new List<AreaStyle>();
  49. [SerializeField][IgnoreDoc] private List<TitleStyle> m_TitleStyles = new List<TitleStyle>();
  50. [SerializeField][IgnoreDoc] private List<EmphasisStyle> m_EmphasisStyles = new List<EmphasisStyle>();
  51. [SerializeField][IgnoreDoc] private List<BlurStyle> m_BlurStyles = new List<BlurStyle>();
  52. [SerializeField][IgnoreDoc] private List<SelectStyle> m_SelectStyles = new List<SelectStyle>();
  53. [SerializeField] private List<double> m_Data = new List<double>();
  54. [NonSerialized] public SerieDataContext context = new SerieDataContext();
  55. [NonSerialized] public InteractData interact = new InteractData();
  56. public ChartLabel labelObject { get; set; }
  57. public ChartLabel titleObject { get; set; }
  58. private bool m_Show = true;
  59. /// <summary>
  60. /// the index of SerieData.
  61. /// |数据项索引。
  62. /// </summary>
  63. public override int index { get { return m_Index; } set { m_Index = value; } }
  64. /// <summary>
  65. /// the name of data item.
  66. /// |数据项名称。
  67. /// </summary>
  68. public string name { get { return m_Name; } set { m_Name = value; } }
  69. /// <summary>
  70. /// the id of data.
  71. /// |数据项的唯一id。唯一id不是必须设置的。
  72. /// </summary>
  73. public string id { get { return m_Id; } set { m_Id = value; } }
  74. /// <summary>
  75. /// the id of parent SerieData.
  76. /// |父节点id。父节点id不是必须设置的。
  77. /// </summary>
  78. public string parentId { get { return m_ParentId; } set { m_ParentId = value; } }
  79. /// <summary>
  80. /// 是否忽略数据。当为 true 时,数据不进行绘制。
  81. /// </summary>
  82. public bool ignore
  83. {
  84. get { return m_Ignore; }
  85. set { if (PropertyUtil.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); }
  86. }
  87. /// <summary>
  88. /// 自定义半径。可用在饼图中自定义某个数据项的半径。
  89. /// </summary>
  90. public float radius { get { return m_Radius; } set { m_Radius = value; } }
  91. /// <summary>
  92. /// Whether the data item is selected.
  93. /// |该数据项是否被选中。
  94. /// </summary>
  95. public bool selected { get { return m_Selected; } set { m_Selected = value; } }
  96. /// <summary>
  97. /// the state of serie data.
  98. /// |数据项的默认状态。
  99. /// </summary>
  100. public SerieState state { get { return m_State; } set { m_State = value; } }
  101. /// <summary>
  102. /// 数据项图例名称。当数据项名称不为空时,图例名称即为系列名称;反之则为索引index。
  103. /// </summary>
  104. /// <value></value>
  105. public string legendName { get { return string.IsNullOrEmpty(name) ? ChartCached.IntToStr(index) : name; } }
  106. /// <summary>
  107. /// 单个数据项的标签设置。
  108. /// </summary>
  109. public LabelStyle labelStyle { get { return m_Labels.Count > 0 ? m_Labels[0] : null; } }
  110. public LabelLine labelLine { get { return m_LabelLines.Count > 0 ? m_LabelLines[0] : null; } }
  111. /// <summary>
  112. /// 单个数据项的样式设置。
  113. /// </summary>
  114. public ItemStyle itemStyle { get { return m_ItemStyles.Count > 0 ? m_ItemStyles[0] : null; } }
  115. /// <summary>
  116. /// 单个数据项的标记设置。
  117. /// </summary>
  118. public SerieSymbol symbol { get { return m_Symbols.Count > 0 ? m_Symbols[0] : null; } }
  119. public LineStyle lineStyle { get { return m_LineStyles.Count > 0 ? m_LineStyles[0] : null; } }
  120. public AreaStyle areaStyle { get { return m_AreaStyles.Count > 0 ? m_AreaStyles[0] : null; } }
  121. public TitleStyle titleStyle { get { return m_TitleStyles.Count > 0 ? m_TitleStyles[0] : null; } }
  122. /// <summary>
  123. /// 高亮状态的样式
  124. /// </summary>
  125. public EmphasisStyle emphasisStyle { get { return m_EmphasisStyles.Count > 0 ? m_EmphasisStyles[0] : null; } }
  126. /// <summary>
  127. /// 淡出状态的样式。
  128. /// </summary>
  129. public BlurStyle blurStyle { get { return m_BlurStyles.Count > 0 ? m_BlurStyles[0] : null; } }
  130. /// <summary>
  131. /// 选中状态的样式。
  132. /// </summary>
  133. public SelectStyle selectStyle { get { return m_SelectStyles.Count > 0 ? m_SelectStyles[0] : null; } }
  134. /// <summary>
  135. /// An arbitrary dimension data list of data item.
  136. /// |可指定任意维数的数值列表。
  137. /// </summary>
  138. public List<double> data { get { return m_Data; } set { m_Data = value; } }
  139. /// <summary>
  140. /// [default:true] Whether the data item is showed.
  141. /// |该数据项是否要显示。
  142. /// </summary>
  143. public bool show { get { return m_Show; } set { m_Show = value; } }
  144. private List<double> m_PreviousData = new List<double>();
  145. private List<float> m_DataUpdateTime = new List<float>();
  146. private List<bool> m_DataUpdateFlag = new List<bool>();
  147. private List<Vector2> m_PolygonPoints = new List<Vector2>();
  148. public override bool vertsDirty
  149. {
  150. get
  151. {
  152. return m_VertsDirty ||
  153. IsVertsDirty(labelLine) ||
  154. IsVertsDirty(itemStyle) ||
  155. IsVertsDirty(symbol) ||
  156. IsVertsDirty(lineStyle) ||
  157. IsVertsDirty(areaStyle) ||
  158. IsVertsDirty(emphasisStyle) ||
  159. IsVertsDirty(blurStyle) ||
  160. IsVertsDirty(selectStyle);
  161. }
  162. }
  163. public override bool componentDirty
  164. {
  165. get
  166. {
  167. return m_ComponentDirty ||
  168. IsComponentDirty(labelStyle) ||
  169. IsComponentDirty(labelLine) ||
  170. IsComponentDirty(titleStyle) ||
  171. IsComponentDirty(emphasisStyle) ||
  172. IsComponentDirty(blurStyle) ||
  173. IsComponentDirty(selectStyle);
  174. }
  175. }
  176. public override void ClearVerticesDirty()
  177. {
  178. base.ClearVerticesDirty();
  179. ClearVerticesDirty(labelLine);
  180. ClearVerticesDirty(itemStyle);
  181. ClearVerticesDirty(lineStyle);
  182. ClearVerticesDirty(areaStyle);
  183. ClearVerticesDirty(emphasisStyle);
  184. ClearVerticesDirty(blurStyle);
  185. ClearVerticesDirty(selectStyle);
  186. }
  187. public override void ClearComponentDirty()
  188. {
  189. base.ClearComponentDirty();
  190. ClearComponentDirty(labelLine);
  191. ClearComponentDirty(itemStyle);
  192. ClearComponentDirty(lineStyle);
  193. ClearComponentDirty(areaStyle);
  194. ClearComponentDirty(symbol);
  195. ClearComponentDirty(emphasisStyle);
  196. ClearComponentDirty(blurStyle);
  197. ClearComponentDirty(selectStyle);
  198. }
  199. public void Reset()
  200. {
  201. index = 0;
  202. m_Id = null;
  203. m_ParentId = null;
  204. labelObject = null;
  205. m_Name = string.Empty;
  206. m_Show = true;
  207. context.Reset();
  208. interact.Reset();
  209. m_Data.Clear();
  210. m_PreviousData.Clear();
  211. m_DataUpdateTime.Clear();
  212. m_DataUpdateFlag.Clear();
  213. m_Labels.Clear();
  214. m_LabelLines.Clear();
  215. m_ItemStyles.Clear();
  216. m_Symbols.Clear();
  217. m_LineStyles.Clear();
  218. m_AreaStyles.Clear();
  219. m_TitleStyles.Clear();
  220. m_EmphasisStyles.Clear();
  221. m_BlurStyles.Clear();
  222. m_SelectStyles.Clear();
  223. }
  224. [Obsolete("GetOrAddComponent is obsolete. Use EnsureComponent instead.")]
  225. public T GetOrAddComponent<T>() where T : ChildComponent, ISerieDataComponent
  226. {
  227. return EnsureComponent<T>();
  228. }
  229. /// <summary>
  230. /// Get the component of the serie data. return null if not exist.
  231. /// |获取数据项的指定类型的组件,如果不存在则返回null。
  232. /// </summary>
  233. /// <typeparam name="T"></typeparam>
  234. /// <returns></returns>
  235. public T GetComponent<T>() where T : ChildComponent, ISerieDataComponent
  236. {
  237. return GetComponentInternal(typeof(T), false) as T;
  238. }
  239. /// <summary>
  240. /// Ensure the serie data has the component, if not, add it.
  241. /// |确保数据项有指定类型的组件,如果没有则添加。
  242. /// </summary>
  243. /// <typeparam name="T"></typeparam>
  244. /// <returns></returns>
  245. [Since("v3.6.0")]
  246. public T EnsureComponent<T>() where T : ChildComponent, ISerieDataComponent
  247. {
  248. return GetComponentInternal(typeof(T), true) as T;
  249. }
  250. /// <summary>
  251. /// Ensure the serie data has the component, if not, add it.
  252. /// |确保数据项有指定类型的组件,如果没有则添加。
  253. /// </summary>
  254. /// <param name="type"></param>
  255. /// <returns></returns>
  256. [Since("v3.6.0")]
  257. public ISerieDataComponent EnsureComponent(Type type)
  258. {
  259. return GetComponentInternal(type, true);
  260. }
  261. private ISerieDataComponent GetComponentInternal(Type type, bool addIfNotExist)
  262. {
  263. if (type == typeof(ItemStyle))
  264. {
  265. if (m_ItemStyles.Count == 0)
  266. {
  267. if (addIfNotExist)
  268. m_ItemStyles.Add(new ItemStyle() { show = true });
  269. else
  270. return null;
  271. }
  272. return m_ItemStyles[0];
  273. }
  274. else if (type == typeof(LabelStyle))
  275. {
  276. if (m_Labels.Count == 0)
  277. {
  278. if (addIfNotExist)
  279. m_Labels.Add(new LabelStyle() { show = true });
  280. else
  281. return null;
  282. }
  283. return m_Labels[0];
  284. }
  285. else if (type == typeof(LabelLine))
  286. {
  287. if (m_LabelLines.Count == 0)
  288. {
  289. if (addIfNotExist)
  290. m_LabelLines.Add(new LabelLine() { show = true });
  291. else
  292. return null;
  293. }
  294. return m_LabelLines[0];
  295. }
  296. else if (type == typeof(EmphasisStyle))
  297. {
  298. if (m_EmphasisStyles.Count == 0)
  299. {
  300. if (addIfNotExist)
  301. m_EmphasisStyles.Add(new EmphasisStyle() { show = true });
  302. else
  303. return null;
  304. }
  305. return m_EmphasisStyles[0];
  306. }
  307. else if (type == typeof(BlurStyle))
  308. {
  309. if (m_BlurStyles.Count == 0)
  310. {
  311. if (addIfNotExist)
  312. m_BlurStyles.Add(new BlurStyle() { show = true });
  313. else
  314. return null;
  315. }
  316. return m_BlurStyles[0];
  317. }
  318. else if (type == typeof(SelectStyle))
  319. {
  320. if (m_SelectStyles.Count == 0)
  321. {
  322. if (addIfNotExist)
  323. m_SelectStyles.Add(new SelectStyle() { show = true });
  324. else
  325. return null;
  326. }
  327. return m_SelectStyles[0];
  328. }
  329. else if (type == typeof(SerieSymbol))
  330. {
  331. if (m_Symbols.Count == 0)
  332. {
  333. if (addIfNotExist)
  334. m_Symbols.Add(new SerieSymbol() { show = true });
  335. else
  336. return null;
  337. }
  338. return m_Symbols[0];
  339. }
  340. else if (type == typeof(LineStyle))
  341. {
  342. if (m_LineStyles.Count == 0)
  343. {
  344. if (addIfNotExist)
  345. m_LineStyles.Add(new LineStyle() { show = true });
  346. else
  347. return null;
  348. }
  349. return m_LineStyles[0];
  350. }
  351. else if (type == typeof(AreaStyle))
  352. {
  353. if (m_AreaStyles.Count == 0)
  354. {
  355. if (addIfNotExist)
  356. m_AreaStyles.Add(new AreaStyle() { show = true });
  357. else
  358. return null;
  359. }
  360. return m_AreaStyles[0];
  361. }
  362. else if (type == typeof(TitleStyle))
  363. {
  364. if (m_TitleStyles.Count == 0)
  365. {
  366. if (addIfNotExist)
  367. m_TitleStyles.Add(new TitleStyle() { show = true });
  368. else
  369. return null;
  370. }
  371. return m_TitleStyles[0];
  372. }
  373. else
  374. {
  375. throw new System.Exception("SerieData not support component:" + type);
  376. }
  377. }
  378. public void RemoveAllComponent()
  379. {
  380. m_ItemStyles.Clear();
  381. m_Labels.Clear();
  382. m_LabelLines.Clear();
  383. m_Symbols.Clear();
  384. m_EmphasisStyles.Clear();
  385. m_BlurStyles.Clear();
  386. m_SelectStyles.Clear();
  387. m_LineStyles.Clear();
  388. m_AreaStyles.Clear();
  389. m_TitleStyles.Clear();
  390. }
  391. public void RemoveComponent<T>() where T : ISerieDataComponent
  392. {
  393. RemoveComponent(typeof(T));
  394. }
  395. public void RemoveComponent(Type type)
  396. {
  397. if (type == typeof(ItemStyle))
  398. m_ItemStyles.Clear();
  399. else if (type == typeof(LabelStyle))
  400. m_Labels.Clear();
  401. else if (type == typeof(LabelLine))
  402. m_LabelLines.Clear();
  403. else if (type == typeof(EmphasisStyle))
  404. m_EmphasisStyles.Clear();
  405. else if (type == typeof(BlurStyle))
  406. m_BlurStyles.Clear();
  407. else if (type == typeof(SelectStyle))
  408. m_SelectStyles.Clear();
  409. else if (type == typeof(SerieSymbol))
  410. m_Symbols.Clear();
  411. else if (type == typeof(LineStyle))
  412. m_LineStyles.Clear();
  413. else if (type == typeof(AreaStyle))
  414. m_AreaStyles.Clear();
  415. else if (type == typeof(TitleStyle))
  416. m_TitleStyles.Clear();
  417. else
  418. throw new System.Exception("SerieData not support component:" + type);
  419. }
  420. public double GetData(int index, bool inverse = false)
  421. {
  422. if (index >= 0 && index < m_Data.Count)
  423. {
  424. return inverse ? -m_Data[index] : m_Data[index];
  425. }
  426. else return 0;
  427. }
  428. public double GetData(int index, double min, double max)
  429. {
  430. if (index >= 0 && index < m_Data.Count)
  431. {
  432. var value = m_Data[index];
  433. if (value < min) return min;
  434. else if (value > max) return max;
  435. else return value;
  436. }
  437. else return 0;
  438. }
  439. public double GetPreviousData(int index, bool inverse = false)
  440. {
  441. if (index >= 0 && index < m_PreviousData.Count)
  442. {
  443. return inverse ? -m_PreviousData[index] : m_PreviousData[index];
  444. }
  445. else return 0;
  446. }
  447. public double GetFirstData(bool unscaledTime, float animationDuration = 500f)
  448. {
  449. if (m_Data.Count > 0) return GetCurrData(0, animationDuration, unscaledTime);
  450. return 0;
  451. }
  452. public double GetLastData()
  453. {
  454. if (m_Data.Count > 0) return m_Data[m_Data.Count - 1];
  455. return 0;
  456. }
  457. public double GetCurrData(int index, float animationDuration = 500f, bool unscaledTime = false, bool inverse = false)
  458. {
  459. return GetCurrData(index, animationDuration, inverse, 0, 0, unscaledTime);
  460. }
  461. public double GetCurrData(int index, float animationDuration, bool inverse, double min, double max, bool unscaledTime, bool loop = false)
  462. {
  463. if (index < m_DataUpdateFlag.Count && m_DataUpdateFlag[index] && animationDuration > 0)
  464. {
  465. var time = (unscaledTime ? Time.unscaledTime : Time.time) - m_DataUpdateTime[index];
  466. var total = animationDuration / 1000;
  467. var rate = time / total;
  468. if (rate > 1) rate = 1;
  469. if (rate < 1)
  470. {
  471. CheckLastData(unscaledTime);
  472. var prev = GetPreviousData(index);
  473. var next = GetData(index);
  474. if (loop)
  475. {
  476. if (next <= min && prev != 0) next = max;
  477. }
  478. var curr = MathUtil.Lerp(prev, next, rate);
  479. if (min != 0 || max != 0)
  480. {
  481. if (inverse)
  482. {
  483. var temp = min;
  484. min = -max;
  485. max = -temp;
  486. }
  487. var pre = m_PreviousData[index];
  488. if (pre < min)
  489. {
  490. m_PreviousData[index] = min;
  491. curr = min;
  492. }
  493. else if (pre > max)
  494. {
  495. m_PreviousData[index] = max;
  496. curr = max;
  497. }
  498. }
  499. curr = inverse ? -curr : curr;
  500. return curr;
  501. }
  502. else
  503. {
  504. m_DataUpdateFlag[index] = false;
  505. return GetData(index, inverse);
  506. }
  507. }
  508. else
  509. {
  510. return GetData(index, inverse);
  511. }
  512. }
  513. /// <summary>
  514. /// the maxinum value.
  515. /// |最大值。
  516. /// </summary>
  517. public double GetMaxData(bool inverse = false)
  518. {
  519. if (m_Data.Count == 0) return 0;
  520. var temp = double.MinValue;
  521. for (int i = 0; i < m_Data.Count; i++)
  522. {
  523. var value = GetData(i, inverse);
  524. if (value > temp) temp = value;
  525. }
  526. return temp;
  527. }
  528. /// <summary>
  529. /// the mininum value.
  530. /// |最小值。
  531. /// </summary>
  532. public double GetMinData(bool inverse = false)
  533. {
  534. if (m_Data.Count == 0) return 0;
  535. var temp = double.MaxValue;
  536. for (int i = 0; i < m_Data.Count; i++)
  537. {
  538. var value = GetData(i, inverse);
  539. if (value < temp) temp = value;
  540. }
  541. return temp;
  542. }
  543. public void GetMinMaxData(int startDimensionIndex, bool inverse, out double min, out double max)
  544. {
  545. if (m_Data.Count == 0)
  546. {
  547. min = 0;
  548. max = 0;
  549. }
  550. min = double.MaxValue;
  551. max = double.MinValue;
  552. for (int i = startDimensionIndex; i < m_Data.Count; i++)
  553. {
  554. var value = GetData(i, inverse);
  555. if (value < min) min = value;
  556. if (value > max) max = value;
  557. }
  558. }
  559. public double GetTotalData()
  560. {
  561. var total = 0d;
  562. foreach (var value in m_Data)
  563. total += value;
  564. return total;
  565. }
  566. public bool UpdateData(int dimension, double value, bool updateAnimation, bool unscaledTime, float animationDuration = 500f)
  567. {
  568. if (dimension >= 0 && dimension < data.Count)
  569. {
  570. CheckLastData(unscaledTime);
  571. m_PreviousData[dimension] = GetCurrData(dimension, animationDuration, unscaledTime);
  572. //m_PreviousData[dimension] = data[dimension];;
  573. m_DataUpdateTime[dimension] = (unscaledTime ? Time.unscaledTime : Time.time);
  574. m_DataUpdateFlag[dimension] = updateAnimation;
  575. data[dimension] = value;
  576. return true;
  577. }
  578. return false;
  579. }
  580. public bool UpdateData(int dimension, double value)
  581. {
  582. if (dimension >= 0 && dimension < data.Count)
  583. {
  584. data[dimension] = value;
  585. return true;
  586. }
  587. return false;
  588. }
  589. private void CheckLastData(bool unscaledTime)
  590. {
  591. if (m_PreviousData.Count != m_Data.Count)
  592. {
  593. m_PreviousData.Clear();
  594. m_DataUpdateTime.Clear();
  595. m_DataUpdateFlag.Clear();
  596. for (int i = 0; i < m_Data.Count; i++)
  597. {
  598. m_PreviousData.Add(m_Data[i]);
  599. m_DataUpdateTime.Add((unscaledTime ? Time.unscaledTime : Time.time));
  600. m_DataUpdateFlag.Add(false);
  601. }
  602. }
  603. }
  604. public bool IsDataChanged()
  605. {
  606. for (int i = 0; i < m_DataUpdateFlag.Count; i++)
  607. if (m_DataUpdateFlag[i]) return true;
  608. return false;
  609. }
  610. public float GetLabelWidth()
  611. {
  612. if (labelObject != null) return labelObject.GetTextWidth();
  613. else return 0;
  614. }
  615. public float GetLabelHeight()
  616. {
  617. if (labelObject != null) return labelObject.GetTextHeight();
  618. return 0;
  619. }
  620. public void SetLabelActive(bool flag)
  621. {
  622. if (labelObject != null) labelObject.SetActive(flag);
  623. foreach (var labelObject in context.dataLabels)
  624. {
  625. labelObject.SetActive(false);
  626. }
  627. }
  628. public void SetIconActive(bool flag)
  629. {
  630. if (labelObject != null) labelObject.SetActive(flag);
  631. }
  632. public void SetPolygon(params Vector2[] points)
  633. {
  634. m_PolygonPoints.Clear();
  635. m_PolygonPoints.AddRange(points);
  636. }
  637. public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
  638. {
  639. m_PolygonPoints.Clear();
  640. m_PolygonPoints.Add(p1);
  641. m_PolygonPoints.Add(p2);
  642. m_PolygonPoints.Add(p3);
  643. m_PolygonPoints.Add(p4);
  644. }
  645. public void SetPolygon(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 p5)
  646. {
  647. SetPolygon(p1, p2, p3, p4);
  648. m_PolygonPoints.Add(p5);
  649. }
  650. public bool IsInPolygon(Vector2 p)
  651. {
  652. return UGLHelper.IsPointInPolygon(p, m_PolygonPoints);
  653. }
  654. }
  655. }