61 lines
1.3 KiB
C#
61 lines
1.3 KiB
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];
|
|
}
|
|
}
|
|
}
|
|
} |