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 readonly Dictionary components; internal VolumeStack(IEnumerable baseTypes) { components = new Dictionary(); 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(); } } }