Files
XCharts/Runtime/Component/Background/Background.cs

118 lines
3.8 KiB
C#
Raw Normal View History

2020-05-21 08:32:52 +08:00
using System;
using UnityEngine;
using UnityEngine.UI;
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2020-05-21 08:32:52 +08:00
{
/// <summary>
2020-07-17 08:52:32 +08:00
/// Background component.
2023-11-11 23:32:24 +08:00
/// ||背景组件。
2020-05-21 08:32:52 +08:00
/// </summary>
[Serializable]
2021-11-23 13:20:07 +08:00
[DisallowMultipleComponent]
2024-01-13 22:11:01 +08:00
[ComponentHandler(typeof(BackgroundHandler), false, 0)]
2020-05-21 08:32:52 +08:00
public class Background : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Sprite m_Image;
[SerializeField] private Image.Type m_ImageType;
[SerializeField] private Color m_ImageColor = Color.white;
2024-01-16 22:29:15 +08:00
[SerializeField][Since("v3.10.0")] private float m_ImageWidth = 0;
[SerializeField][Since("v3.10.0")] private float m_ImageHeight = 0;
[SerializeField] private bool m_AutoColor = true;
[SerializeField][Since("v3.10.0")] private BorderStyle m_BorderStyle = new BorderStyle();
2020-05-21 08:32:52 +08:00
/// <summary>
2022-03-24 08:37:06 +08:00
/// Whether to enable the background component.
2023-11-11 23:32:24 +08:00
/// ||是否启用背景组件。
2020-05-21 08:32:52 +08:00
/// </summary>
public bool show
{
get { return m_Show; }
2022-12-07 13:16:06 +08:00
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
2020-05-21 08:32:52 +08:00
}
/// <summary>
2020-07-17 08:52:32 +08:00
/// the image of background.
2023-11-11 23:32:24 +08:00
/// ||背景图。
2020-05-21 08:32:52 +08:00
/// </summary>
public Sprite image
{
get { return m_Image; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetClass(ref m_Image, value)) SetComponentDirty(); }
2020-05-21 08:32:52 +08:00
}
/// <summary>
2020-07-17 08:52:32 +08:00
/// the fill type of background image.
2023-11-11 23:32:24 +08:00
/// ||背景图填充类型。
2020-05-21 08:32:52 +08:00
/// </summary>
public Image.Type imageType
{
get { return m_ImageType; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetComponentDirty(); }
2020-05-21 08:32:52 +08:00
}
/// <summary>
/// 背景图颜色。
/// </summary>
public Color imageColor
{
get { return m_ImageColor; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetColor(ref m_ImageColor, value)) SetComponentDirty(); }
2020-05-21 08:32:52 +08:00
}
2024-01-16 22:29:15 +08:00
/// <summary>
/// the width of background image.
/// ||背景图宽度。
/// </summary>
public float imageWidth
{
get { return m_ImageWidth; }
set { if (PropertyUtil.SetStruct(ref m_ImageWidth, value)) SetComponentDirty(); }
}
/// <summary>
/// the height of background image.
/// ||背景图高度。
/// </summary>
public float imageHeight
{
get { return m_ImageHeight; }
set { if (PropertyUtil.SetStruct(ref m_ImageHeight, value)) SetComponentDirty(); }
}
2020-05-21 08:32:52 +08:00
/// <summary>
/// Whether to use theme background color for component color when the background component is on.
2023-11-11 23:32:24 +08:00
/// ||当background组件开启时是否自动使用主题背景色作为backgrounnd组件的颜色。当设置为false时用imageColor作为颜色。
2020-05-21 08:32:52 +08:00
/// </summary>
public bool autoColor
2020-05-21 08:32:52 +08:00
{
get { return m_AutoColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); }
2020-05-21 08:32:52 +08:00
}
/// <summary>
/// the border style of background.
/// ||背景边框样式。
/// </summary>
public BorderStyle borderStyle
{
get { return m_BorderStyle; }
set { if (PropertyUtil.SetClass(ref m_BorderStyle, value)) SetComponentDirty(); }
}
2024-12-17 22:19:22 +08:00
/// <summary>
/// the rect of background.
/// ||背景的矩形区域。
/// </summary>
public Rect rect { get; set; }
2021-11-23 13:20:07 +08:00
public override void SetDefaultValue()
2020-05-21 08:32:52 +08:00
{
2022-03-29 22:06:10 +08:00
m_Show = true;
2021-11-23 13:20:07 +08:00
m_Image = null;
m_ImageType = Image.Type.Sliced;
m_ImageColor = Color.white;
m_AutoColor = true;
2020-05-21 08:32:52 +08:00
}
}
}