Last active
June 25, 2020 08:44
-
-
Save jfranmora/8dc527305ad5674ae6b21d3763ab4c9c to your computer and use it in GitHub Desktop.
Component to create PostProcessProfile that lives in the Scene. Useful for temporal profiles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Rendering.PostProcessing; | |
[ExecuteInEditMode] | |
[RequireComponent(typeof(PostProcessVolume))] | |
public class LocalPostProcessProfile : MonoBehaviour | |
{ | |
[SerializeField, HideInInspector] | |
private PostProcessProfile _profile; | |
#if UNITY_EDITOR | |
private void Awake() | |
{ | |
if (!Application.isPlaying) | |
{ | |
if (_profile == null) | |
{ | |
_profile = new PostProcessProfile(); | |
_profile.name = $"Local Profile: {gameObject.name}"; | |
} | |
} | |
} | |
#endif | |
private void OnEnable() | |
{ | |
TryAssignProfileToVolume(); | |
} | |
private void TryAssignProfileToVolume() | |
{ | |
if (TryGetComponent<PostProcessVolume>(out var volume)) | |
{ | |
volume.profile = _profile; | |
} | |
} | |
#if UNITY_EDITOR | |
private void OnDestroy() | |
{ | |
if (!Application.isPlaying) | |
{ | |
DestroyImmediate(_profile); | |
} | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment