Rework diapason with octo arms

This commit is contained in:
2026-02-19 17:16:54 +01:00
parent ec89813b1b
commit 5b1bdaeb90
48 changed files with 2075 additions and 583 deletions
@@ -0,0 +1,229 @@
using System.Collections;
using UnityEngine;
using Unheimlich.Audio;
using Unheimlich.Core;
using Unheimlich.Utility;
using Unheimlich.Gameplay.Player;
using Unheimlich.Gameplay.CameraControl;
using Unheimlich.Data.CameraSettings;
using InputManager = Unheimlich.Managers.InputManager;
namespace Unheimlich.Gameplay.Player
{
public class DiapasonListeningHandlerV2 : Singleton<DiapasonListeningHandlerV2>
{
[Header("Systems")]
[SerializeField] private DiapasonEquipmentManager _equipmentManager;
[SerializeField] private CameraPanController _cameraPanController;
[Header("Settings")]
[SerializeField] private bool _disablePlayerMovementDuringListen = true;
[SerializeField] private bool _enablePanMode = true;
[Header("Visual Feedback")]
[SerializeField] private float _vignetteIntensity = 0.5f;
[SerializeField] private ListeningVignetteEffect _vignetteEffect;
[Header("Audio")]
[SerializeField] private AudioClip _breathInClip;
[SerializeField] [Range(0f, 1f)] private float _breathInVolume = 1f;
[SerializeField] private float _concentrationDuration = 1f;
[SerializeField] private float _breathInDuration = 0.5f;
public bool IsListening { get; private set; }
public bool IsConcentrating { get; private set; }
private AudioSource _playerAudioSource;
private Coroutine _listeningCoroutine;
private CameraHeadBob _cameraHeadBob;
private CameraPanSettings _originalCameraSettings;
private AudioListenable _lastDetectedEmitter;
private bool _isFadingOut;
protected override void OnAwake()
{
_playerAudioSource = GetComponent<AudioSource>();
if (_playerAudioSource == null)
_playerAudioSource = gameObject.AddComponent<AudioSource>();
if (_cameraPanController == null)
{
_cameraPanController = GetComponent<CameraPanController>();
if (_cameraPanController == null)
{
Debug.LogWarning("[DiapasonV2] CameraPanController not found!");
}
}
if (_vignetteEffect == null)
{
_vignetteEffect = GetComponentInChildren<ListeningVignetteEffect>();
}
_cameraHeadBob = GetComponentInChildren<CameraHeadBob>();
if (_equipmentManager != null)
{
SubscribeToEquipmentEvents();
}
}
void OnDestroy()
{
if (_equipmentManager != null)
{
UnsubscribeFromEquipmentEvents();
}
}
private void SubscribeToEquipmentEvents()
{
}
private void UnsubscribeFromEquipmentEvents()
{
}
void Update()
{
var diapasonAction = InputManager.GetDiapasonAction();
if (diapasonAction != null && diapasonAction.WasPressedThisFrame())
{
if (!IsListening && !IsConcentrating)
{
StartListeningMode();
}
else if (IsListening || IsConcentrating)
{
StopListeningMode();
}
}
if (IsListening && _cameraPanController != null)
{
_cameraPanController.UpdatePan();
}
}
private void StartListeningMode()
{
if (_isFadingOut || _equipmentManager == null)
return;
if (_listeningCoroutine != null)
StopCoroutine(_listeningCoroutine);
_listeningCoroutine = StartCoroutine(ListeningSequence());
}
private IEnumerator ListeningSequence()
{
IsConcentrating = true;
InputManager.SetContext(InputManager.InputContext.Listening);
if (_disablePlayerMovementDuringListen && PlayerController.Instance?.Movement != null)
{
PlayerController.Instance.Movement.enabled = false;
}
_equipmentManager.EquipDiapason();
PlayBreathIn();
yield return new WaitForSeconds(_breathInDuration);
if (_cameraHeadBob != null)
{
float resetDuration = _concentrationDuration - _breathInDuration;
_cameraHeadBob.LerpToZero(resetDuration);
}
yield return new WaitForSeconds(_concentrationDuration - _breathInDuration);
IsConcentrating = false;
IsListening = true;
EnableVignette(true);
if (_enablePanMode && _cameraPanController != null)
{
_cameraPanController.SaveOriginalState();
_cameraPanController.StartPan();
}
Cursor.lockState = CursorLockMode.Confined;
Cursor.visible = false;
}
private void StopListeningMode()
{
if (_listeningCoroutine != null)
{
StopCoroutine(_listeningCoroutine);
_listeningCoroutine = null;
}
IsListening = false;
IsConcentrating = false;
_isFadingOut = true;
_equipmentManager.UnequipDiapason();
EnableVignette(false);
if (_enablePanMode && _cameraPanController != null)
{
_cameraPanController.StopPan();
_cameraPanController.ReturnToOriginalPosition(() =>
{
if (_originalCameraSettings != null)
{
_cameraPanController.Settings = _originalCameraSettings;
_originalCameraSettings = null;
}
if (_disablePlayerMovementDuringListen && PlayerController.Instance?.Movement != null)
{
PlayerController.Instance.Movement.enabled = true;
}
_isFadingOut = false;
});
}
else
{
if (_disablePlayerMovementDuringListen && PlayerController.Instance?.Movement != null)
{
PlayerController.Instance.Movement.enabled = true;
}
_isFadingOut = false;
}
InputManager.SetContext(InputManager.InputContext.Normal);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void PlayBreathIn()
{
if (_breathInClip != null && _playerAudioSource != null)
{
_playerAudioSource.PlayOneShot(_breathInClip, _breathInVolume);
}
}
private void EnableVignette(bool enable)
{
if (_vignetteEffect == null)
return;
if (enable)
{
_vignetteEffect.SetIntensity(_vignetteIntensity);
}
_vignetteEffect.EnableVignette(enable);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 46c1f473fbd3cac4397aabaa76d18357