init
This commit is contained in:
52
Assets/TcgEngine/Scripts/UI/IconValue.cs
Normal file
52
Assets/TcgEngine/Scripts/UI/IconValue.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TcgEngine.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Icon that changes based on the value assigned
|
||||
/// </summary>
|
||||
|
||||
public class IconValue : MonoBehaviour
|
||||
{
|
||||
public int value;
|
||||
public bool auto_refresh = true;
|
||||
|
||||
public Sprite[] values;
|
||||
|
||||
private Image image;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
image = GetComponent<Image>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (auto_refresh)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (image == null)
|
||||
image = GetComponent<Image>();
|
||||
|
||||
if (value >= 0 && value < values.Length)
|
||||
{
|
||||
image.sprite = values[value];
|
||||
image.enabled = image.sprite != null;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMat(Material mat)
|
||||
{
|
||||
if (image == null)
|
||||
image = GetComponent<Image>();
|
||||
|
||||
image.material = mat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user