[Add] Dice to Scene

This commit is contained in:
2026-02-26 16:06:30 +07:00
parent 55e4857af4
commit 6da112fb97
7 changed files with 985 additions and 285 deletions
+13 -18
View File
@@ -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>");
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b23705818517634fa50cd00f9228af9