Merged in dev/staticShaderLibrary (pull request #105)
Initial check-in of a static library to collate shaders on first use.pull/413/head
commit
38dd4ed507
|
@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
||||||
{
|
{
|
||||||
//Applying default material with UI Image Crop shader
|
//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
|
else
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
||||||
{
|
{
|
||||||
//Applying default material with UI Image Crop shader
|
//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;
|
mat = mGraphic.material;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
||||||
{
|
{
|
||||||
//Applying default material with UI Image Crop shader
|
//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
|
else
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
||||||
{
|
{
|
||||||
//Applying default material with UI Image Crop shader
|
//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
|
else
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
||||||
{
|
{
|
||||||
//Applying default material with UI Image Crop shader
|
//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
|
else
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
if (mGraphic.material == null || mGraphic.material.name == "Default UI Material")
|
||||||
{
|
{
|
||||||
//Applying default material with UI Image Crop shader
|
//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
|
else
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
var text = GetComponent<Text>();
|
var text = GetComponent<Text>();
|
||||||
if (text != null)
|
if (text != null)
|
||||||
{
|
{
|
||||||
mat = new Material(Shader.Find("UI Extensions/SoftMaskShader"));
|
mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
|
||||||
text.material = mat;
|
text.material = mat;
|
||||||
cachedCanvas = text.canvas;
|
cachedCanvas = text.canvas;
|
||||||
cachedCanvasTransform = cachedCanvas.transform;
|
cachedCanvasTransform = cachedCanvas.transform;
|
||||||
|
@ -64,7 +64,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
var graphic = GetComponent<Graphic>();
|
var graphic = GetComponent<Graphic>();
|
||||||
if (graphic != null)
|
if (graphic != null)
|
||||||
{
|
{
|
||||||
mat = new Material(Shader.Find("UI Extensions/SoftMaskShader"));
|
mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader"));
|
||||||
graphic.material = mat;
|
graphic.material = mat;
|
||||||
cachedCanvas = graphic.canvas;
|
cachedCanvas = graphic.canvas;
|
||||||
cachedCanvasTransform = cachedCanvas.transform;
|
cachedCanvasTransform = cachedCanvas.transform;
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
if (material == null)
|
if (material == null)
|
||||||
{
|
{
|
||||||
var foundShader = Shader.Find("UI Extensions/Particles/Additive");
|
var foundShader = ShaderLibrary.GetShaderInstance("UI Extensions/Particles/Additive");
|
||||||
if (foundShader)
|
if (foundShader)
|
||||||
{
|
{
|
||||||
material = new Material(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