Ludo-3D/Assets/Scripts/Input/DiceRoller.cs

48 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DiceRoller : MonoBehaviour
{
[SerializeField] private int diceTestValue = 0;
private InputManager inputManager;
private void OnMouseDown()
{
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
if (!inputManager.GameplayManager.CanRollDice) return;
OnDiceRolled();
}
private void Update()
{
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
if (!inputManager.GameplayManager.CanRollDice) return;
if (Input.GetKeyDown(KeyCode.Space))
OnDiceRolled();
}
private void OnDiceRolled()
{
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
soundManager?.PlayGameSoundClip(SoundType.Dice);
inputManager.SetDiceRollValue(rolledVal);
}
public void HandleDiceViewForUser()
{
if (!inputManager.GameplayManager.CanRollDiceForUser) return;
diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false);
}
public void HandleDiceViewForBot(Action<int> onComplete)
{
diceView.Roll(onComplete: (val) => onComplete?.Invoke(val), true);
}
}