This commit is contained in:
2026-08-21 17:59:13 +03:00
parent b98901c366
commit f6a7547e84
951 changed files with 909007 additions and 70938 deletions
@@ -9,12 +9,35 @@ public sealed class MapControlBinder : MonoBehaviour
[SerializeField] private NetworkPhysicalLeverInteractable fireLever;
[SerializeField] private NetworkButtonInteractable scanButton;
private bool controlsBound;
private bool initialValuesApplied;
private void Reset() => mapController = GetComponent<MapController>();
private void OnEnable()
private void OnEnable() => TryBindControls();
private void OnDisable() => UnbindControls();
private void Update()
{
TryBindControls();
if (!controlsBound || initialValuesApplied ||
horizontalWheel == null || verticalWheel == null)
{
return;
}
initialValuesApplied = true;
HandleHorizontalChanged(horizontalWheel.NormalizedValue);
HandleVerticalChanged(verticalWheel.NormalizedValue);
}
private void TryBindControls()
{
if (controlsBound || !AreNetworkObjectsReady())
return;
if (horizontalWheel != null)
horizontalWheel.ValueChanged += HandleHorizontalChanged;
if (verticalWheel != null)
@@ -23,10 +46,15 @@ public sealed class MapControlBinder : MonoBehaviour
fireLever.StateChanged += HandleFireChanged;
if (scanButton != null)
scanButton.Pressed += HandleScanPressed;
controlsBound = true;
}
private void OnDisable()
private void UnbindControls()
{
if (!controlsBound)
return;
if (horizontalWheel != null)
horizontalWheel.ValueChanged -= HandleHorizontalChanged;
if (verticalWheel != null)
@@ -35,20 +63,18 @@ public sealed class MapControlBinder : MonoBehaviour
fireLever.StateChanged -= HandleFireChanged;
if (scanButton != null)
scanButton.Pressed -= HandleScanPressed;
controlsBound = false;
initialValuesApplied = false;
}
private void Update()
private bool AreNetworkObjectsReady()
{
if (initialValuesApplied || mapController == null || !mapController.IsSpawned ||
horizontalWheel == null || verticalWheel == null ||
!horizontalWheel.IsSpawned || !verticalWheel.IsSpawned)
{
return;
}
initialValuesApplied = true;
HandleHorizontalChanged(horizontalWheel.NormalizedValue);
HandleVerticalChanged(verticalWheel.NormalizedValue);
return mapController != null && mapController.IsSpawned &&
(horizontalWheel == null || horizontalWheel.IsSpawned) &&
(verticalWheel == null || verticalWheel.IsSpawned) &&
(fireLever == null || fireLever.IsSpawned) &&
(scanButton == null || scanButton.IsSpawned);
}
private void HandleHorizontalChanged(float value) =>