using System;
using System.Collections.Generic;
namespace UnityEngine.Rendering
{
///
/// Holds the state of a Volume blending update. A global stack is
/// available by default in but you can also create your own using
/// if you need to update the manager with specific
/// settings and store the results for later use.
///
public sealed class VolumeStack : IDisposable
{
// Holds the state of _all_ component types you can possibly add on volumes
internal Dictionary components;
internal VolumeStack()
{
}
internal void Reload(Type[] 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);
}
}
///
/// Gets the current state of the of type
/// in the stack.
///
/// A type of .
/// The current state of the of type
/// in the stack.
public T GetComponent()
where T : VolumeComponent
{
var comp = GetComponent(typeof(T));
return (T)comp;
}
///
/// Gets the current state of the of the specified type in the
/// stack.
///
/// The type of to look for.
/// The current state of the of the specified type,
/// or null if the type is invalid.
public VolumeComponent GetComponent(Type type)
{
components.TryGetValue(type, out var comp);
return comp;
}
///
/// Cleans up the content of this stack. Once a VolumeStack is disposed, it souldn't
/// be used anymore.
///
public void Dispose()
{
foreach (var component in components)
CoreUtils.Destroy(component.Value);
components.Clear();
}
}
}