111
This commit is contained in:
52
Assets/ThirdParty/PostProcessing/Runtime/Utils/MaterialFactory.cs
vendored
Normal file
52
Assets/ThirdParty/PostProcessing/Runtime/Utils/MaterialFactory.cs
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.PostProcessing
|
||||
{
|
||||
using UnityObject = Object;
|
||||
|
||||
public sealed class MaterialFactory : IDisposable
|
||||
{
|
||||
Dictionary<string, Material> m_Materials;
|
||||
|
||||
public MaterialFactory()
|
||||
{
|
||||
m_Materials = new Dictionary<string, Material>();
|
||||
}
|
||||
|
||||
public Material Get(string shaderName)
|
||||
{
|
||||
Material material;
|
||||
|
||||
if (!m_Materials.TryGetValue(shaderName, out material))
|
||||
{
|
||||
var shader = Shader.Find(shaderName);
|
||||
|
||||
if (shader == null)
|
||||
throw new ArgumentException(string.Format("Shader not found ({0})", shaderName));
|
||||
|
||||
material = new Material(shader)
|
||||
{
|
||||
name = string.Format("PostFX - {0}", shaderName.Substring(shaderName.LastIndexOf("/") + 1)),
|
||||
hideFlags = HideFlags.DontSave
|
||||
};
|
||||
|
||||
m_Materials.Add(shaderName, material);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
var enumerator = m_Materials.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
var material = enumerator.Current.Value;
|
||||
GraphicsUtils.Destroy(material);
|
||||
}
|
||||
|
||||
m_Materials.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user