Files
XCharts/Runtime/Component/Child/MLValue.cs

73 lines
1.9 KiB
C#
Raw Normal View History

2023-07-26 08:41:06 +08:00
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// 多样式数值。
/// </summary>
[Since("v3.8.0")]
[System.Serializable]
public class MLValue : ChildComponent
{
2023-07-27 07:17:37 +08:00
/// <summary>
/// the type of value.
/// |数值类型。
/// </summary>
2023-07-26 08:41:06 +08:00
public enum Type
{
/// <summary>
2023-07-27 07:17:37 +08:00
/// Percent value form.
2023-07-26 08:41:06 +08:00
/// |百分比形式。
/// </summary>
Percent,
/// <summary>
2023-07-27 07:17:37 +08:00
/// Absolute value form.
2023-07-26 08:41:06 +08:00
/// |绝对值形式。
/// </summary>
Absolute,
/// <summary>
2023-07-27 07:17:37 +08:00
/// Extra value form.
2023-07-26 08:41:06 +08:00
/// |额外形式。
/// </summary>
Extra
}
[SerializeField] private Type m_Type;
[SerializeField] private float m_Value;
public Type type { get { return m_Type; } set { m_Type = value; } }
public float value { get { return m_Value; } set { m_Value = value; } }
2023-07-27 07:17:37 +08:00
public MLValue(float value)
2023-07-26 08:41:06 +08:00
{
2023-07-27 07:17:37 +08:00
m_Type = Type.Percent;
2023-07-26 08:41:06 +08:00
m_Value = value;
}
2023-07-27 07:17:37 +08:00
public MLValue(Type type, float value)
2023-07-26 08:41:06 +08:00
{
2023-07-27 07:17:37 +08:00
m_Type = type;
2023-07-26 08:41:06 +08:00
m_Value = value;
}
2023-07-27 07:17:37 +08:00
/// <summary>
/// Get the value by type.
/// |根据类型获取值。
/// </summary>
/// <param name="total">默认值</param>
/// <returns></returns>
2023-07-26 08:41:06 +08:00
public float GetValue(float total)
{
switch (m_Type)
{
case Type.Percent:
return m_Value * total;
case Type.Absolute:
return m_Value;
case Type.Extra:
return total + m_Value;
default: return 0;
}
}
}
}