Mini demo with all features
This commit is contained in:
@@ -2,11 +2,11 @@ using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
|
||||
namespace Unheimlich.UI
|
||||
{
|
||||
[RequireComponent(typeof(Camera))]
|
||||
public class DialogueBlurEffectURP : Singleton<DialogueBlurEffectURP>
|
||||
public class DialogueBlurEffectURP : Singleton<DialogueBlurEffectURP>
|
||||
{
|
||||
|
||||
[Header("Volume Settings")]
|
||||
@@ -29,6 +29,11 @@ namespace Unheimlich.UI
|
||||
[Tooltip("Layer(s) for dialogue (World Space UI) to render without blur")]
|
||||
[SerializeField] private LayerMask _dialogueLayers;
|
||||
[SerializeField] private bool _autoCreateDialogueCamera = true;
|
||||
|
||||
[Header("Hands Configuration")]
|
||||
[Tooltip("Layer for player hands to render on top of dialogue")]
|
||||
[SerializeField] private LayerMask _handsLayer;
|
||||
[SerializeField] private bool _autoCreateHandsCamera = true;
|
||||
|
||||
private DepthOfField _dof;
|
||||
private ColorAdjustments _color;
|
||||
@@ -42,10 +47,11 @@ namespace Unheimlich.UI
|
||||
|
||||
private Camera _baseCam;
|
||||
private Camera _dialogueCam;
|
||||
private Camera _handsCam;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_baseCam = GetComponent<Camera>();
|
||||
|
||||
|
||||
if (_fadeCurve == null || _fadeCurve.keys.Length == 0)
|
||||
_fadeCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
@@ -96,8 +102,11 @@ namespace Unheimlich.UI
|
||||
|
||||
void Start()
|
||||
{
|
||||
_baseCam = PlayerController.Instance.PlayerCamera;
|
||||
if (_autoCreateDialogueCamera)
|
||||
SetupDialogueOverlayCamera();
|
||||
if (_autoCreateHandsCamera)
|
||||
SetupHandsOverlayCamera();
|
||||
}
|
||||
|
||||
void SetupDialogueOverlayCamera()
|
||||
@@ -113,6 +122,8 @@ namespace Unheimlich.UI
|
||||
Debug.LogWarning("[DialogueBlur] WARNING: dialogueLayers is EMPTY! Ghost words will be blurred!");
|
||||
|
||||
_baseCam.cullingMask &= ~_dialogueLayers;
|
||||
if (_handsLayer.value != 0)
|
||||
_baseCam.cullingMask &= ~_handsLayer;
|
||||
|
||||
var go = new GameObject("Dialogue Camera (Overlay)");
|
||||
go.transform.SetParent(_baseCam.transform);
|
||||
@@ -131,6 +142,38 @@ namespace Unheimlich.UI
|
||||
baseData.cameraStack.Add(_dialogueCam);
|
||||
}
|
||||
|
||||
void SetupHandsOverlayCamera()
|
||||
{
|
||||
if (_handsLayer.value == 0)
|
||||
{
|
||||
Debug.LogWarning("[DialogueBlur] WARNING: handsLayer is EMPTY! Hands camera will not be created.");
|
||||
return;
|
||||
}
|
||||
|
||||
var baseData = _baseCam.GetComponent<UniversalAdditionalCameraData>();
|
||||
if (baseData == null)
|
||||
{
|
||||
Debug.LogError("[DialogueBlur] ERROR: Base camera has no UniversalAdditionalCameraData!");
|
||||
return;
|
||||
}
|
||||
|
||||
var go = new GameObject("Hands Camera (Overlay)");
|
||||
go.transform.SetParent(_baseCam.transform);
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
go.transform.localRotation = Quaternion.identity;
|
||||
|
||||
_handsCam = go.AddComponent<Camera>();
|
||||
_handsCam.CopyFrom(_baseCam);
|
||||
_handsCam.clearFlags = CameraClearFlags.Depth;
|
||||
_handsCam.cullingMask = _handsLayer;
|
||||
|
||||
var overlayData = go.AddComponent<UniversalAdditionalCameraData>();
|
||||
overlayData.renderType = CameraRenderType.Overlay;
|
||||
overlayData.renderPostProcessing = false;
|
||||
|
||||
baseData.cameraStack.Add(_handsCam);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!_fading) return;
|
||||
@@ -186,6 +229,21 @@ namespace Unheimlich.UI
|
||||
|
||||
public void ShowBlur()
|
||||
{
|
||||
if (_dialogueCam == null && _autoCreateDialogueCamera)
|
||||
{
|
||||
if (_baseCam == null && PlayerController.Instance != null)
|
||||
_baseCam = PlayerController.Instance.PlayerCamera;
|
||||
|
||||
if (_baseCam != null)
|
||||
{
|
||||
SetupDialogueOverlayCamera();
|
||||
if (_autoCreateHandsCamera)
|
||||
SetupHandsOverlayCamera();
|
||||
}
|
||||
else
|
||||
Debug.LogWarning("[DialogueBlur] WARNING: Cannot create dialogue camera - PlayerCamera not ready!");
|
||||
}
|
||||
|
||||
if (_fading && _target == 1f) return;
|
||||
|
||||
_start = _current;
|
||||
|
||||
Reference in New Issue
Block a user