forked from oculus-samples/Unity-CrypticCabinet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlackoutVolume.cs
53 lines (46 loc) · 1.66 KB
/
BlackoutVolume.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Meta Platforms, Inc. and affiliates.
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace CrypticCabinet.Utils
{
/// <summary>
/// A volume that triggers a blackout effect for the player.
/// Used to hide the inside of the main puzzle objects during the gameplay.
/// </summary>
public class BlackoutVolume : MonoBehaviour
{
private Camera m_mainCamera;
private UniversalAdditionalCameraData m_universalAdditionalCameraData;
private void Start()
{
m_mainCamera = Camera.main;
if (m_mainCamera != null)
{
m_universalAdditionalCameraData = m_mainCamera.GetComponent<UniversalAdditionalCameraData>();
}
if (m_universalAdditionalCameraData == null)
{
Debug.LogError(
"No m_universalAdditionalCameraData found on the assigned camera. BlackoutVolume cannot work.");
}
else
{
m_universalAdditionalCameraData.allowXRRendering = true;
}
}
private void OnTriggerEnter(Collider other)
{
if (m_universalAdditionalCameraData != null && other.gameObject == m_mainCamera.gameObject)
{
m_universalAdditionalCameraData.renderPostProcessing = true;
}
}
private void OnTriggerExit(Collider other)
{
if (m_universalAdditionalCameraData != null && other.gameObject == m_mainCamera.gameObject)
{
m_universalAdditionalCameraData.renderPostProcessing = false;
}
}
}
}