Rework diapason with octo arms
This commit is contained in:
+229
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46c1f473fbd3cac4397aabaa76d18357
|
||||
+57
-47
@@ -94,14 +94,13 @@ namespace Unheimlich.Interactions.FloatingWords
|
||||
|
||||
_isEffectActive = true;
|
||||
|
||||
_scribbleTweenId = TweenHelper.AnimateMaterialFloat(
|
||||
gameObject,
|
||||
_scribbleMaterialInstance,
|
||||
ProgressID,
|
||||
0f,
|
||||
1f,
|
||||
scribbleDuration,
|
||||
() => {
|
||||
_scribbleTweenId = LeanTween.value(gameObject, 0f, 1f, scribbleDuration)
|
||||
.setEase(LeanTweenType.easeInOutQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_scribbleMaterialInstance != null)
|
||||
_scribbleMaterialInstance.SetFloat(ProgressID, val);
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_scribbleTweenId = -1;
|
||||
|
||||
float ghostAlphaRatio = _ghostTextComponent != null ? (_originalGhostColor.a / _originalTextColor.a) : 0f;
|
||||
@@ -126,63 +125,74 @@ namespace Unheimlich.Interactions.FloatingWords
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_fadeTweenId = -1;
|
||||
_isEffectActive = false;
|
||||
}).id;
|
||||
},
|
||||
LeanTweenType.easeInOutQuad);
|
||||
}).id;
|
||||
}
|
||||
|
||||
public void ResetEffect()
|
||||
{
|
||||
if (!_overlayCreated || _scribbleOverlay == null)
|
||||
{
|
||||
_isEffectActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
bool overlayIsActive = _scribbleOverlay.gameObject.activeSelf;
|
||||
|
||||
if (!overlayIsActive)
|
||||
{
|
||||
_isEffectActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
CancelActiveTweens();
|
||||
_isEffectActive = false;
|
||||
|
||||
if (_scribbleMaterialInstance != null)
|
||||
{
|
||||
float currentProgress = _scribbleMaterialInstance.GetFloat(ProgressID);
|
||||
|
||||
if (currentProgress > 0f)
|
||||
{
|
||||
_scribbleTweenId = TweenHelper.AnimateMaterialFloat(
|
||||
gameObject,
|
||||
_scribbleMaterialInstance,
|
||||
ProgressID,
|
||||
currentProgress,
|
||||
0f,
|
||||
0.3f,
|
||||
() => {
|
||||
_scribbleTweenId = -1;
|
||||
if (_scribbleOverlay != null)
|
||||
_scribbleOverlay.gameObject.SetActive(false);
|
||||
},
|
||||
LeanTweenType.easeOutQuad);
|
||||
}
|
||||
_scribbleTweenId = LeanTween.value(gameObject, currentProgress, 0f, 0.3f)
|
||||
.setEase(LeanTweenType.easeOutQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_scribbleMaterialInstance != null)
|
||||
_scribbleMaterialInstance.SetFloat(ProgressID, val);
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_scribbleTweenId = -1;
|
||||
if (_scribbleOverlay != null)
|
||||
_scribbleOverlay.gameObject.SetActive(false);
|
||||
}).id;
|
||||
}
|
||||
|
||||
if (_textComponent != null)
|
||||
{
|
||||
float currentAlpha = _textComponent.color.a;
|
||||
float ghostAlphaRatio = _ghostTextComponent != null ? (_originalGhostColor.a / _originalTextColor.a) : 0f;
|
||||
|
||||
if (currentAlpha < _originalTextColor.a)
|
||||
{
|
||||
float ghostAlphaRatio = _ghostTextComponent != null ? (_originalGhostColor.a / _originalTextColor.a) : 0f;
|
||||
|
||||
_fadeTweenId = TweenHelper.FadeText(
|
||||
gameObject,
|
||||
_textComponent,
|
||||
_ghostTextComponent,
|
||||
_originalTextColor.a,
|
||||
0.3f,
|
||||
ghostAlphaRatio,
|
||||
() => { _fadeTweenId = -1; },
|
||||
LeanTweenType.easeOutQuad);
|
||||
}
|
||||
_fadeTweenId = LeanTween.value(gameObject, currentAlpha, _originalTextColor.a, 0.3f)
|
||||
.setEase(LeanTweenType.easeOutQuad)
|
||||
.setOnUpdate((float val) => {
|
||||
if (_textComponent != null)
|
||||
{
|
||||
_textComponent.color = _textComponent.color.WithAlpha(val);
|
||||
}
|
||||
|
||||
if (_ghostTextComponent != null)
|
||||
{
|
||||
_ghostTextComponent.color = _ghostTextComponent.color.WithAlpha(val * ghostAlphaRatio);
|
||||
}
|
||||
|
||||
if (_scribbleOverlay != null)
|
||||
{
|
||||
_scribbleOverlay.color = _scribbleOverlay.color.WithAlpha(val);
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_fadeTweenId = -1;
|
||||
}).id;
|
||||
}
|
||||
|
||||
if (_scribbleOverlay != null)
|
||||
{
|
||||
_scribbleOverlay.color = _scribbleOverlay.color.WithAlpha(1f);
|
||||
}
|
||||
|
||||
_isEffectActive = false;
|
||||
}
|
||||
|
||||
private void CancelActiveTweens()
|
||||
|
||||
Reference in New Issue
Block a user