Fixed
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class CannonControlBinder : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private NetworkCannonController cannon;
|
||||
[SerializeField] private NetworkPhysicalLeverInteractable fireLever;
|
||||
[SerializeField] private NetworkButtonInteractable decreaseTimerButton;
|
||||
[SerializeField] private NetworkButtonInteractable increaseTimerButton;
|
||||
|
||||
private bool bound;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!bound)
|
||||
TryBind();
|
||||
}
|
||||
|
||||
private void OnDisable() => Unbind();
|
||||
|
||||
private void TryBind()
|
||||
{
|
||||
if (cannon == null || !cannon.IsSpawned || !cannon.IsServer)
|
||||
return;
|
||||
|
||||
if (fireLever != null)
|
||||
fireLever.StateChanged += HandleFireLever;
|
||||
if (decreaseTimerButton != null)
|
||||
decreaseTimerButton.Pressed += HandleDecreaseTimer;
|
||||
if (increaseTimerButton != null)
|
||||
increaseTimerButton.Pressed += HandleIncreaseTimer;
|
||||
bound = true;
|
||||
}
|
||||
|
||||
private void Unbind()
|
||||
{
|
||||
if (!bound)
|
||||
return;
|
||||
if (fireLever != null)
|
||||
fireLever.StateChanged -= HandleFireLever;
|
||||
if (decreaseTimerButton != null)
|
||||
decreaseTimerButton.Pressed -= HandleDecreaseTimer;
|
||||
if (increaseTimerButton != null)
|
||||
increaseTimerButton.Pressed -= HandleIncreaseTimer;
|
||||
bound = false;
|
||||
}
|
||||
|
||||
private void HandleFireLever(bool isActivated) => cannon.SetFireRequested(isActivated);
|
||||
private void HandleDecreaseTimer() => cannon.RequestDecreaseShotDelay();
|
||||
private void HandleIncreaseTimer() => cannon.RequestIncreaseShotDelay();
|
||||
}
|
||||
Reference in New Issue
Block a user