mirror of
https://github.com/ConjureETS/Unity_Utils.git
synced 2026-03-24 04:50:58 +00:00
40 lines
909 B
C#
40 lines
909 B
C#
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace JohnsonUtils.Canvases
|
|
{
|
|
public class ImageUIComponent : UIComponentBase
|
|
{
|
|
[Header("Association")]
|
|
#if ODIN_INSPECTOR
|
|
[Required]
|
|
#endif
|
|
[SerializeField] private Image image;
|
|
|
|
private Color _initialColor;
|
|
|
|
private void Awake() => _initialColor = image.color;
|
|
|
|
private void Start() => Debug.Assert(image, $"A {nameof(image)} must be assigned to a {nameof(ImageUIComponent)}");
|
|
|
|
public void ResetColor() => image.color = _initialColor;
|
|
|
|
public Sprite Sprite
|
|
{
|
|
set => image.sprite = value;
|
|
}
|
|
|
|
public Color Color
|
|
{
|
|
set => image.color = value;
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (!image)
|
|
image = GetComponent<Image>();
|
|
}
|
|
}
|
|
} |