Started make greybox for main location

This commit is contained in:
2026-08-05 17:49:42 +03:00
parent a259a64e80
commit 90934eca22
648 changed files with 314989 additions and 578 deletions
@@ -0,0 +1,38 @@
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
public sealed class NetworkButtonInteractable : NetworkInteractable
{
[SerializeField] private UnityEvent<bool> buttonStateChanged;
private readonly NetworkVariable<bool> isPressed = new(
false,
NetworkVariableReadPermission.Everyone,
NetworkVariableWritePermission.Server);
public bool IsPressed => isPressed.Value;
public override void OnNetworkSpawn()
{
isPressed.OnValueChanged += HandleStateChanged;
ApplyState(isPressed.Value);
}
public override void OnNetworkDespawn()
{
isPressed.OnValueChanged -= HandleStateChanged;
}
protected override bool CanInteractOnServer(ulong senderClientId) => true;
protected override void InteractOnServer(ulong senderClientId, NetworkObject playerObject)
{
isPressed.Value = !isPressed.Value;
ApplyState(isPressed.Value);
}
private void HandleStateChanged(bool _, bool currentValue) => ApplyState(currentValue);
private void ApplyState(bool currentValue) => buttonStateChanged?.Invoke(currentValue);
}