Skip to content

Instantly share code, notes, and snippets.

@jfranmora
Last active June 25, 2020 08:44
Show Gist options
  • Save jfranmora/8dc527305ad5674ae6b21d3763ab4c9c to your computer and use it in GitHub Desktop.
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.
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