Skip to content

Instantly share code, notes, and snippets.

@gamemachine
Last active January 9, 2021 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamemachine/94cffac535625c9da6b8711faa6b94ee to your computer and use it in GitHub Desktop.
Save gamemachine/94cffac535625c9da6b8711faa6b94ee to your computer and use it in GitHub Desktop.
namespace UnityEngine.Rendering
{
public class VolumeInstanceHelper : MonoBehaviour
{
[HideInInspector]
public Volume Volume;
private void OnValidate()
{
if (Volume == null)
{
Volume = GetComponent<Volume>();
}
}
public void CreateProfileInstance()
{
var instance = Volume.profile;
}
public void ClearProfileInstance()
{
if (Volume.HasInstantiatedProfile())
{
var profile = Volume.profile;
if (profile != Volume.sharedProfile)
{
if (Application.isPlaying)
{
Destroy(profile);
}
else
{
DestroyImmediate(profile);
}
}
Volume.profile = null;
}
}
}
}
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering
{
[CustomEditor(typeof(VolumeInstanceHelper))]
public class VolumeInstanceHelperEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
VolumeInstanceHelper modifier = (VolumeInstanceHelper)target;
if (modifier.Volume.HasInstantiatedProfile())
{
EditorGUILayout.Space();
if (GUILayout.Button("Clear instance"))
{
modifier.ClearProfileInstance();
}
} else
{
EditorGUILayout.Space();
if (GUILayout.Button("Create instance"))
{
modifier.CreateProfileInstance();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment