blob: dbbed3410986a56cb20cbc470fe5bdbb3bcf6c57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
using System;
using System.Collections.Generic;
namespace UnityEngine.PostProcessing;
public sealed class MaterialFactory : IDisposable
{
private Dictionary<string, Material> m_Materials;
public MaterialFactory()
{
m_Materials = new Dictionary<string, Material>();
}
public Material Get(string shaderName)
{
if (!m_Materials.TryGetValue(shaderName, out var value))
{
Shader shader = Shader.Find(shaderName);
if (shader == null)
{
throw new ArgumentException($"Shader not found ({shaderName})");
}
Material material = new Material(shader);
material.name = string.Format("PostFX - {0}", shaderName.Substring(shaderName.LastIndexOf("/") + 1));
material.hideFlags = HideFlags.DontSave;
value = material;
m_Materials.Add(shaderName, value);
}
return value;
}
public void Dispose()
{
Dictionary<string, Material>.Enumerator enumerator = m_Materials.GetEnumerator();
while (enumerator.MoveNext())
{
Material value = enumerator.Current.Value;
GraphicsUtils.Destroy(value);
}
m_Materials.Clear();
}
}
|