using System; using System.Collections.Generic; namespace UnityEngine.Experimental.Rendering { public sealed class VolumeStack : IDisposable { // Holds the state of _all_ component types you can possibly add on volumes public Dictionary components; internal VolumeStack() { } internal void Reload(IEnumerable baseTypes) { if (components == null) components = new Dictionary(); else components.Clear(); foreach (var type in baseTypes) { var inst = (VolumeComponent)ScriptableObject.CreateInstance(type); components.Add(type, inst); } } public T GetComponent() where T : VolumeComponent { var comp = GetComponent(typeof(T)); return (T)comp; } public VolumeComponent GetComponent(Type type) { VolumeComponent comp; components.TryGetValue(type, out comp); return comp; } public void Dispose() { foreach (var component in components) CoreUtils.Destroy(component.Value); components.Clear(); } } }