Map mehanic ready to multiplayer
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -13,6 +14,9 @@ public sealed class NetworkButtonInteractable : NetworkInteractable
|
||||
|
||||
public bool IsPressed => isPressed.Value;
|
||||
|
||||
public event Action Pressed;
|
||||
public event Action<bool> StateChanged;
|
||||
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
isPressed.OnValueChanged += HandleStateChanged;
|
||||
@@ -28,11 +32,15 @@ public sealed class NetworkButtonInteractable : NetworkInteractable
|
||||
|
||||
protected override void InteractOnServer(ulong senderClientId, NetworkObject playerObject)
|
||||
{
|
||||
Pressed?.Invoke();
|
||||
isPressed.Value = !isPressed.Value;
|
||||
ApplyState(isPressed.Value);
|
||||
}
|
||||
|
||||
private void HandleStateChanged(bool _, bool currentValue) => ApplyState(currentValue);
|
||||
|
||||
private void ApplyState(bool currentValue) => buttonStateChanged?.Invoke(currentValue);
|
||||
private void ApplyState(bool currentValue)
|
||||
{
|
||||
StateChanged?.Invoke(currentValue);
|
||||
buttonStateChanged?.Invoke(currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user