Last active
January 9, 2021 00:57
-
-
Save gamemachine/94cffac535625c9da6b8711faa6b94ee to your computer and use it in GitHub Desktop.
This file contains 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
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