53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DiceRollHandler : MonoBehaviour
|
|
{
|
|
[SerializeField] private DiceView diceView;
|
|
[SerializeField] private int diceTestValue = 0;
|
|
|
|
private InputManager inputManager;
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
|
|
|
|
// RollDiceOnClick();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
|
|
}
|
|
|
|
public void OnUserDiceRollComplete(int rolledVal)
|
|
{
|
|
inputManager.SetDiceRollValue(rolledVal);
|
|
}
|
|
|
|
public void HandleDiceViewForUser()
|
|
{
|
|
if (!inputManager.GameplayManager.CanRollDiceForUser) return;
|
|
|
|
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
|
|
soundManager?.PlayGameSoundClip(SoundType.Dice);
|
|
|
|
// OnUserDiceRollComplete(GetDiceTestVal());
|
|
diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false);
|
|
}
|
|
|
|
public void HandleDiceViewForBot(Action<int> onComplete)
|
|
{
|
|
diceView.Roll(onComplete: (val) => onComplete?.Invoke(val), true);
|
|
}
|
|
|
|
public void HandleDiceViewForBot(Action<int> onComplete, int val)
|
|
{
|
|
onComplete?.Invoke(val);
|
|
}
|
|
|
|
private int GetDiceTestVal() => diceTestValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceTestValue;
|
|
}
|