Merged in dev/staticShaderLibrary (pull request #105)

Initial check-in of a static library to collate shaders on first use.
release
Simon Jackson 2020-10-27 01:30:40 +00:00
commit 38dd4ed507
10 changed files with 49 additions and 9 deletions

View File

@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
{
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UIAdditive"));
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UIAdditive"));
}
}
else

View File

@ -32,7 +32,7 @@ namespace UnityEngine.UI.Extensions
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
{
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UI Image Crop"));
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UI Image Crop"));
}
mat = mGraphic.material;
}

View File

@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
{
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UILinearDodge"));
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UILinearDodge"));
}
}
else

View File

@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
{
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UIMultiply"));
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UIMultiply"));
}
}
else

View File

@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
{
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UIScreen"));
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UIScreen"));
}
}
else

View File

@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
{
//Applying default material with UI Image Crop shader
mGraphic.material = new Material(Shader.Find("UI Extensions/UISoftAdditive"));
mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UISoftAdditive"));
}
}
else

View File

@ -48,7 +48,7 @@ namespace UnityEngine.UI.Extensions
var text = GetComponent<Text>();
if (text != null)
{
mat = new Material(Shader.Find("UI Extensions/SoftMaskShader"));
mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
text.material = mat;
cachedCanvas = text.canvas;
cachedCanvasTransform = cachedCanvas.transform;
@ -64,7 +64,7 @@ namespace UnityEngine.UI.Extensions
var graphic = GetComponent<Graphic>();
if (graphic != null)
{
mat = new Material(Shader.Find("UI Extensions/SoftMaskShader"));
mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
graphic.material = mat;
cachedCanvas = graphic.canvas;
cachedCanvasTransform = cachedCanvas.transform;

View File

@ -76,7 +76,7 @@ namespace UnityEngine.UI.Extensions
if (material == null)
{
var foundShader = Shader.Find("UI Extensions/Particles/Additive");
var foundShader = ShaderLibrary.GetShaderInstance("UI Extensions/Particles/Additive");
if (foundShader)
{
material = new Material(foundShader);

View File

@ -0,0 +1,29 @@
/// Credit SimonDarksideJ
using System.Collections.Generic;
using UnityEditor;
namespace UnityEngine.UI.Extensions
{
[InitializeOnLoadAttribute]
public static class ShaderLibrary
{
public static Dictionary<string, Shader> shaderInstances = new Dictionary<string, Shader>();
public static Shader[] preLoadedShaders;
public static Shader GetShaderInstance(string shaderName)
{
if (shaderInstances.ContainsKey(shaderName))
{
return shaderInstances[shaderName];
}
var newInstance = Shader.Find(shaderName);
if (newInstance != null)
{
shaderInstances.Add(shaderName, newInstance);
}
return newInstance;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d4dc4c08600582419712a4f2370c81b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: