MLValue.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// 多样式数值。
  7. /// </summary>
  8. [Since("v3.8.0")]
  9. [System.Serializable]
  10. public class MLValue : ChildComponent
  11. {
  12. /// <summary>
  13. /// the type of value.
  14. /// ||数值类型。
  15. /// </summary>
  16. public enum Type
  17. {
  18. /// <summary>
  19. /// Percent value form.
  20. /// ||百分比形式。
  21. /// </summary>
  22. Percent,
  23. /// <summary>
  24. /// Absolute value form.
  25. /// ||绝对值形式。
  26. /// </summary>
  27. Absolute,
  28. /// <summary>
  29. /// Extra value form.
  30. /// ||额外形式。
  31. /// </summary>
  32. Extra
  33. }
  34. [SerializeField] private Type m_Type;
  35. [SerializeField] private float m_Value;
  36. public Type type { get { return m_Type; } set { m_Type = value; } }
  37. public float value { get { return m_Value; } set { m_Value = value; } }
  38. public MLValue(float value)
  39. {
  40. m_Type = Type.Percent;
  41. m_Value = value;
  42. }
  43. public MLValue(Type type, float value)
  44. {
  45. m_Type = type;
  46. m_Value = value;
  47. }
  48. /// <summary>
  49. /// Get the value by type.
  50. /// ||根据类型获取值。
  51. /// </summary>
  52. /// <param name="total">默认值</param>
  53. /// <returns></returns>
  54. public float GetValue(float total)
  55. {
  56. switch (m_Type)
  57. {
  58. case Type.Percent:
  59. return m_Value * total;
  60. case Type.Absolute:
  61. return m_Value;
  62. case Type.Extra:
  63. return total + m_Value;
  64. default: return 0;
  65. }
  66. }
  67. }
  68. }