Files
2026-03-04 10:03:45 +08:00

39 lines
1.0 KiB
C#

using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
namespace CTS
{
public static class CTSMaterials
{
private static Dictionary<string, Material> m_materialLookup = new Dictionary<string, Material>();
public static Material GetMaterial(string shaderType, CTSProfile profile)
{
if (profile.m_useMaterialControlBlock && m_materialLookup.TryGetValue(shaderType + ":" + profile.name, out var value))
{
return value;
}
Shader shader = CTSShaders.GetShader(shaderType);
if (shader == null)
{
UnityEngine.Debug.LogErrorFormat("Could not create CTS material for shader : {0}. Make sure you add your CTS shader is pre-loaded!", shaderType);
return null;
}
Stopwatch stopwatch = Stopwatch.StartNew();
value = new Material(shader)
{
name = shaderType + ":" + profile.name
};
if (profile.m_useMaterialControlBlock)
{
value.hideFlags = HideFlags.DontSave;
m_materialLookup.Add(value.name, value);
}
_ = stopwatch.ElapsedMilliseconds;
_ = 5;
return value;
}
}
}