72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public enum DiceColor
|
|
{
|
|
Black,
|
|
White,
|
|
}
|
|
|
|
public class Die : MonoBehaviour
|
|
{
|
|
public DiceColor color;
|
|
private int _result = 0;
|
|
[SerializeField] private Button dieButton; // assign in the editor
|
|
private Color originalColor;
|
|
public event EventHandler<Die> DieClicked;
|
|
|
|
private void Start()
|
|
{
|
|
dieButton.onClick.AddListener(() => { DiePressed();});
|
|
|
|
originalColor = gameObject.GetComponent<Image>().color;
|
|
}
|
|
|
|
public void SetResult(int result) {
|
|
_result = result;
|
|
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = _result.ToString();
|
|
}
|
|
|
|
public int GetResult()
|
|
{
|
|
return _result;
|
|
}
|
|
|
|
public void ResetDie()
|
|
{
|
|
gameObject.GetComponent<Image>().color = originalColor;
|
|
}
|
|
|
|
public void DieBeingUsed(bool isFirstPair, bool isPairComplete)
|
|
{
|
|
if (isPairComplete)
|
|
{
|
|
// Signify that both dice have been selected
|
|
DieSelectedAndPairComplete();
|
|
}
|
|
else
|
|
{
|
|
// Signify that the die is selected but the pair is not complete
|
|
DieSelectedButPairNotComplete();
|
|
}
|
|
}
|
|
|
|
private void DiePressed()
|
|
{
|
|
DieClicked?.Invoke(this, this);
|
|
}
|
|
|
|
private void DieSelectedButPairNotComplete()
|
|
{
|
|
gameObject.GetComponent<Outline>().enabled = true;
|
|
}
|
|
|
|
private void DieSelectedAndPairComplete()
|
|
{
|
|
gameObject.GetComponent<Outline>().enabled = false;
|
|
gameObject.GetComponent<Image>().color =
|
|
ColorHelper.AddColorTint(gameObject.GetComponent<Image>().color, ColorHelper.OkayGreen, 0.5f);
|
|
}
|
|
}
|