ProjectDDD/Assets/_Datas/SLShared/SLUnity/SLUI/SLUIImageSelect.cs
2025-06-17 20:47:57 +09:00

61 lines
1.3 KiB (Stored with Git LFS)
C#

using System;
using UnityEngine;
using UnityEngine.UI;
namespace Superlazy.UI
{
public class SLUIImageSelect : SLUIComponent
{
public SLValueComparison[] comparisons;
public Sprite[] images;
[NonSerialized]
public Image image;
protected override void Validate()
{
image = GetComponent<Image>();
}
protected override void Init()
{
}
protected override void Enable()
{
foreach (var c in comparisons)
{
c.OnEnable(bindParent.BindPath, OnChange);
}
}
protected override void Disable()
{
foreach (var c in comparisons)
{
c.OnDisable();
}
}
private void OnChange()
{
if (bindParent.Active == false) return;
var idx = 0;
foreach (var c in comparisons)
{
if (c.Result)
{
image.sprite = images[idx];
return;
}
idx++;
}
if (images.Length > idx)
{
image.sprite = images[idx];
}
}
}
}