Map mehanic ready to multiplayer

This commit is contained in:
2026-08-18 17:17:48 +03:00
parent c01ff800f6
commit bb2f4a3b16
20 changed files with 4691 additions and 1648 deletions
@@ -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);
}
}