[Add] Dice to Scene
This commit is contained in:
@@ -9,8 +9,6 @@ using Random = UnityEngine.Random;
|
||||
/// </summary>
|
||||
public sealed class DiceRoller : MonoBehaviour
|
||||
{
|
||||
// ─────────────────────────── Inspector ───────────────────────────
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private Dice dice;
|
||||
[SerializeField] private Rigidbody rb;
|
||||
@@ -41,30 +39,29 @@ public sealed class DiceRoller : MonoBehaviour
|
||||
|
||||
[SerializeField]
|
||||
private AnimationCurve snapCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
||||
|
||||
// ─────────────────────────── Events ──────────────────────────────
|
||||
|
||||
/// <summary>Вызывается когда кубик полностью остановился. Аргумент — выпавшее значение.</summary>
|
||||
|
||||
/// <summary>
|
||||
/// Вызывается когда кубик полностью остановился. Аргумент — выпавшее значение.
|
||||
/// </summary>
|
||||
public event Action<int> OnRollFinished;
|
||||
|
||||
// ─────────────────────────── State ───────────────────────────────
|
||||
|
||||
/// <summary>Идёт ли сейчас бросок.</summary>
|
||||
|
||||
/// <summary>
|
||||
/// Идёт ли сейчас бросок.
|
||||
/// </summary>
|
||||
public bool IsRolling { get; private set; }
|
||||
|
||||
private Coroutine rollRoutine;
|
||||
|
||||
// ─────────────────────────── Unity ───────────────────────────────
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
dice = GetComponent<Dice>();
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// ─────────────────────────── Public API ──────────────────────────
|
||||
|
||||
/// <summary>Бросить кубик. Повторный вызов во время броска игнорируется.</summary>
|
||||
/// <summary>
|
||||
/// Бросить кубик. Повторный вызов во время броска игнорируется.
|
||||
/// </summary>
|
||||
public void Roll()
|
||||
{
|
||||
if (IsRolling) return;
|
||||
@@ -74,9 +71,7 @@ public sealed class DiceRoller : MonoBehaviour
|
||||
|
||||
rollRoutine = StartCoroutine(RollSequence());
|
||||
}
|
||||
|
||||
// ─────────────────────────── Core ────────────────────────────────
|
||||
|
||||
|
||||
private IEnumerator RollSequence()
|
||||
{
|
||||
IsRolling = true;
|
||||
@@ -152,6 +147,6 @@ public sealed class DiceRoller : MonoBehaviour
|
||||
IsRolling = false;
|
||||
OnRollFinished?.Invoke(topValue);
|
||||
|
||||
Debug.Log($"🎲 Выпало: <b>{topValue}</b>");
|
||||
Debug.Log($"{gameObject.name} | Выпало: <b>{topValue}</b>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b23705818517634fa50cd00f9228af9
|
||||
Reference in New Issue
Block a user