Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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