Initial check-in of a static library to collate shaders on first use.
parent
b268970a79
commit
f7f7535a7c
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d4dc4c08600582419712a4f2370c81b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue