Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,253 @@
#if UNITY_EDITOR
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace AllIn1SpriteShader
{
public class AllIn1ShaderGradientDrawer : MaterialPropertyDrawer
{
private int resolution;
private Texture2D textureAsset;
public AllIn1ShaderGradientDrawer()
{
resolution = 64;
}
public AllIn1ShaderGradientDrawer(float res)
{
resolution = (int)res;
}
private static bool IsPropertyTypeSuitable(MaterialProperty prop)
{
return prop.type == MaterialProperty.PropType.Texture;
}
public string TextureName(MaterialProperty prop) => $"{prop.name}Tex";
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
{
if (!IsPropertyTypeSuitable(prop))
{
EditorGUI.HelpBox(position, $"[Gradient] used on non-texture property \"{prop.name}\"", MessageType.Error);
return;
}
if (!AssetDatabase.Contains(prop.targets.FirstOrDefault()))
{
EditorGUI.HelpBox(position, "Save Material To Folder to use this effect. Or use the regular Color Ramp instead", MessageType.Error);
return;
}
string textureName = TextureName(prop);
Gradient currentGradient = null;
if (prop.targets.Length == 1)
{
Material target = (Material)prop.targets[0];
string path = AssetDatabase.GetAssetPath(target);
textureAsset = GetTextureAsset(path, textureName);
if (textureAsset != null)
currentGradient = DecodeGradient(prop, textureAsset.name);
if (currentGradient == null)
currentGradient = new Gradient() { };
EditorGUI.showMixedValue = false;
}
else
{
EditorGUI.showMixedValue = true;
}
using (EditorGUI.ChangeCheckScope changeScope = new EditorGUI.ChangeCheckScope())
{
currentGradient = EditorGUILayout.GradientField(label, currentGradient, GUILayout.Height(15));
if (changeScope.changed)
{
string encodedGradient = EncodeGradient(currentGradient);
string fullAssetName = textureName + encodedGradient;
foreach (Object target in prop.targets)
{
if (!AssetDatabase.Contains(target)) continue;
string path = AssetDatabase.GetAssetPath(target);
Texture2D textureAsset = GetTexture(path, textureName);
Undo.RecordObject(textureAsset, "Change Material Gradient");
textureAsset.name = fullAssetName;
BakeGradient(currentGradient, textureAsset);
EditorUtility.SetDirty(textureAsset);
Material material = (Material)target;
material.SetTexture(prop.name, textureAsset);
}
}
}
EditorGUI.showMixedValue = false;
}
private Texture2D GetTexture(string path, string name)
{
textureAsset = GetTextureAsset(path, name);
if (textureAsset == null) CreateTexture(path, name);
if (textureAsset.width != resolution) textureAsset.Reinitialize(resolution, 1);
return textureAsset;
}
private void CreateTexture(string path, string name = "unnamed texture")
{
textureAsset = new Texture2D(resolution, 1, TextureFormat.RGBA32, false);
textureAsset.wrapMode = TextureWrapMode.Clamp;
textureAsset.filterMode = FilterMode.Bilinear;
textureAsset.name = name;
AssetDatabase.AddObjectToAsset(textureAsset, path);
AssetDatabase.Refresh();
}
private string EncodeGradient(Gradient gradient)
{
if (gradient == null) return null;
return JsonUtility.ToJson(new GradientRepresentation(gradient));
}
private Gradient DecodeGradient(MaterialProperty prop, string name)
{
string json = name.Substring(TextureName(prop).Length);
try
{
return JsonUtility.FromJson<GradientRepresentation>(json).ToGradient();
}
catch (Exception)
{
return null;
}
}
private Texture2D GetTextureAsset(string path, string name)
{
return AssetDatabase.LoadAllAssetsAtPath(path).FirstOrDefault(asset => asset.name.StartsWith(name)) as Texture2D;
}
private void BakeGradient(Gradient gradient, Texture2D texture)
{
if (gradient == null) return;
for (int x = 0; x < texture.width; x++)
{
Color color = gradient.Evaluate((float)x / (texture.width - 1));
for (int y = 0; y < texture.height; y++) texture.SetPixel(x, y, color);
}
texture.Apply();
}
[MenuItem("Assets/AllIn1Shader/Remove All Gradient Textures")]
static void RemoveAllSubassets()
{
foreach(Object asset in Selection.GetFiltered<Object>(SelectionMode.Assets))
{
string path = AssetDatabase.GetAssetPath(asset);
AssetDatabase.ImportAsset(path);
foreach(Object subAsset in AssetDatabase.LoadAllAssetRepresentationsAtPath(path))
{
Object.DestroyImmediate(subAsset, true);
}
AssetDatabase.ImportAsset(path);
}
}
class GradientRepresentation
{
public GradientMode mode;
public ColorKey[] colorKeys;
public AlphaKey[] alphaKeys;
public GradientRepresentation() { }
public GradientRepresentation(Gradient source)
{
FromGradient(source);
}
public void FromGradient(Gradient source)
{
mode = source.mode;
colorKeys = source.colorKeys.Select(key => new ColorKey(key)).ToArray();
alphaKeys = source.alphaKeys.Select(key => new AlphaKey(key)).ToArray();
}
public void ToGradient(Gradient gradient)
{
gradient.mode = mode;
gradient.colorKeys = colorKeys.Select(key => key.ToGradientKey()).ToArray();
gradient.alphaKeys = alphaKeys.Select(key => key.ToGradientKey()).ToArray();
}
public Gradient ToGradient()
{
Gradient gradient = new Gradient();
ToGradient(gradient);
return gradient;
}
[Serializable]
public struct ColorKey
{
public Color color;
public float time;
public ColorKey(GradientColorKey source)
{
color = default;
time = default;
FromGradientKey(source);
}
public void FromGradientKey(GradientColorKey source)
{
color = source.color;
time = source.time;
}
public GradientColorKey ToGradientKey()
{
GradientColorKey key;
key.color = color;
key.time = time;
return key;
}
}
[Serializable]
public struct AlphaKey
{
public float alpha;
public float time;
public AlphaKey(GradientAlphaKey source)
{
alpha = default;
time = default;
FromGradientKey(source);
}
public void FromGradientKey(GradientAlphaKey source)
{
alpha = source.alpha;
time = source.time;
}
public GradientAlphaKey ToGradientKey()
{
GradientAlphaKey key;
key.alpha = alpha;
key.time = time;
return key;
}
}
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,285 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
namespace AllIn1SpriteShader
{
[CustomEditor(typeof(AllIn1Shader)), CanEditMultipleObjects]
public class AllIn1ShaderScriptEditor : UnityEditor.Editor
{
private bool showUrpWarning = false;
private double warningTime = 0f;
private SerializedProperty m_NormalStrength, m_NormalSmoothing;
private enum ImageType
{
ShowImage,
HideInComponent,
HideEverywhere
}
private ImageType imageType;
private void OnEnable()
{
m_NormalStrength = serializedObject.FindProperty("normalStrength");
m_NormalSmoothing = serializedObject.FindProperty("normalSmoothing");
}
public override void OnInspectorGUI()
{
ChooseAndDiplayAssetImage();
AllIn1Shader myScript = (AllIn1Shader)target;
SetCurrentShaderType(myScript);
if (GUILayout.Button("Deactivate All Effects"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).ClearAllKeywords();
}
}
if (GUILayout.Button("New Clean Material"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).TryCreateNew();
}
}
if (GUILayout.Button("Create New Material With Same Properties (SEE DOC)"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).MakeCopy();
}
}
if (GUILayout.Button("Save Material To Folder (SEE DOC)"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).SaveMaterial();
}
}
if (GUILayout.Button("Apply Material To All Children"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).ApplyMaterialToHierarchy();
}
}
if (myScript.shaderTypes != AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
if (GUILayout.Button("Render Material To Image"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).RenderToImage();
}
}
}
bool isUrp = false;
Shader temp = Resources.Load("AllIn1Urp2dRenderer", typeof(Shader)) as Shader;
if (temp != null) isUrp = true;
EditorGUILayout.BeginHorizontal();
{
GUILayout.Label("Change Shader Variant:", GUILayout.MaxWidth(140));
int previousShaderType = (int)myScript.shaderTypes;
myScript.shaderTypes = (AllIn1Shader.ShaderTypes)EditorGUILayout.EnumPopup(myScript.shaderTypes);
if (previousShaderType != (int)myScript.shaderTypes)
{
for (int i = 0; i < targets.Length; i++) (targets[i] as AllIn1Shader).CheckIfValidTarget();
if (myScript == null) return;
if (isUrp || myScript.shaderTypes != AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
Debug.Log(myScript.gameObject.name + " shader variant has been changed to: " + myScript.shaderTypes);
myScript.SetSceneDirty();
Renderer sr = myScript.GetComponent<Renderer>();
if (sr != null)
{
if (sr.sharedMaterial != null)
{
int renderingQueue = sr.sharedMaterial.renderQueue;
if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.Default) sr.sharedMaterial.shader = Resources.Load("AllIn1SpriteShader", typeof(Shader)) as Shader;
else if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.ScaledTime) sr.sharedMaterial.shader = Resources.Load("AllIn1SpriteShaderScaledTime", typeof(Shader)) as Shader;
else if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.MaskedUI) sr.sharedMaterial.shader = Resources.Load("AllIn1SpriteShaderUiMask", typeof(Shader)) as Shader;
else if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer) sr.sharedMaterial.shader = Resources.Load("AllIn1Urp2dRenderer", typeof(Shader)) as Shader;
else SetCurrentShaderType(myScript);
sr.sharedMaterial.renderQueue = renderingQueue;
}
}
else
{
Graphic img = myScript.GetComponent<Graphic>();
if (img != null && img.material != null)
{
int renderingQueue = img.material.renderQueue;
if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.Default) img.material.shader = Resources.Load("AllIn1SpriteShader", typeof(Shader)) as Shader;
else if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.ScaledTime) img.material.shader = Resources.Load("AllIn1SpriteShaderScaledTime", typeof(Shader)) as Shader;
else if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.MaskedUI) img.material.shader = Resources.Load("AllIn1SpriteShaderUiMask", typeof(Shader)) as Shader;
else if (myScript.shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer) img.material.shader = Resources.Load("AllIn1Urp2dRenderer", typeof(Shader)) as Shader;
else SetCurrentShaderType(myScript);
img.material.renderQueue = renderingQueue;
}
}
}
else if(!isUrp && myScript.shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
myScript.shaderTypes = (AllIn1Shader.ShaderTypes) previousShaderType;
showUrpWarning = true;
warningTime = EditorApplication.timeSinceStartup + 5;
}
}
}
EditorGUILayout.EndHorizontal();
if (warningTime < EditorApplication.timeSinceStartup) showUrpWarning = false;
if (isUrp) showUrpWarning = false;
if (showUrpWarning) EditorGUILayout.HelpBox(
"You can't set the URP 2D Renderer variant since you didn't import the URP package available in the asset root folder (SEE DOCUMENTATION)",
MessageType.Error,
true);
if (isUrp && myScript.shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
EditorGUILayout.Space();
DrawLine(Color.grey, 1, 3);
EditorGUILayout.Space();
if (GUILayout.Button("Create And Add Normal Map"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).CreateAndAssignNormalMap();
}
}
serializedObject.Update();
EditorGUILayout.PropertyField(m_NormalStrength, new GUIContent("Normal Strength"), GUILayout.Height(20));
EditorGUILayout.PropertyField(m_NormalSmoothing, new GUIContent("Normal Blur"), GUILayout.Height(20));
if (myScript.computingNormal)
{
EditorGUILayout.LabelField("Normal Map is currently being created, be patient", EditorStyles.boldLabel, GUILayout.Height(40));
}
serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space();
}
DrawLine(Color.grey, 1, 3);
EditorGUILayout.Space();
if (GUILayout.Button("Sprite Atlas Auto Setup"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).ToggleSetAtlasUvs(true);
}
}
if (GUILayout.Button("Remove Sprite Atlas Configuration"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).ToggleSetAtlasUvs(false);
}
}
EditorGUILayout.Space();
DrawLine(Color.grey, 1, 3);
if(GUILayout.Button("Remove Component"))
{
for(int i = targets.Length - 1; i >= 0; i--)
{
DestroyImmediate(targets[i] as AllIn1Shader);
(targets[i] as AllIn1Shader).SetSceneDirty();
}
}
if (GUILayout.Button("REMOVE COMPONENT AND MATERIAL"))
{
for (int i = 0; i < targets.Length; i++)
{
(targets[i] as AllIn1Shader).CleanMaterial();
}
for (int i = targets.Length - 1; i >= 0; i--)
{
DestroyImmediate(targets[i] as AllIn1Shader);
}
}
}
private void ChooseAndDiplayAssetImage()
{
if(!EditorPrefs.HasKey("allIn1ImageConfig"))
{
EditorPrefs.SetInt("allIn1ImageConfig", (int) ImageType.ShowImage);
}
imageType = (ImageType) EditorPrefs.GetInt("allIn1ImageConfig");
Texture2D imageInspector = null;
switch(imageType)
{
case ImageType.ShowImage:
{
imageInspector =
(Texture2D) AssetDatabase.LoadAssetAtPath("Assets/AllIn1SpriteShader/Textures/CustomEditorImage.png",
typeof(Texture2D));
break;
}
case ImageType.HideInComponent:
imageInspector =
(Texture2D) AssetDatabase.LoadAssetAtPath("Assets/AllIn1SpriteShader/Textures/CustomEditorImage.png",
typeof(Texture2D));
break;
}
if(imageInspector && imageType != ImageType.HideInComponent && imageType != ImageType.HideEverywhere && imageInspector)
{
Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(40));
GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true);
}
}
private void SetCurrentShaderType(AllIn1Shader myScript)
{
string shaderName = "";
Renderer sr = myScript.GetComponent<Renderer>();
if (sr != null)
{
shaderName = sr.sharedMaterial.shader.name;
}
else
{
Graphic img = myScript.GetComponent<Graphic>();
if (img != null) shaderName = img.material.shader.name;
}
shaderName = shaderName.Replace("AllIn1SpriteShader/", "");
if (shaderName.Equals("AllIn1SpriteShader")) myScript.shaderTypes = AllIn1Shader.ShaderTypes.Default;
else if (shaderName.Equals("AllIn1SpriteShaderScaledTime")) myScript.shaderTypes = AllIn1Shader.ShaderTypes.ScaledTime;
else if (shaderName.Equals("AllIn1SpriteShaderUiMask")) myScript.shaderTypes = AllIn1Shader.ShaderTypes.MaskedUI;
else if (shaderName.Equals("AllIn1Urp2dRenderer")) myScript.shaderTypes = AllIn1Shader.ShaderTypes.Urp2dRenderer;
}
private void DrawLine(Color color, int thickness = 2, int padding = 10)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
r.height = thickness;
r.y += (padding / 2);
r.x -= 2;
r.width += 6;
EditorGUI.DrawRect(r, color);
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,825 @@
#if UNITY_EDITOR
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;
[CanEditMultipleObjects]
public class AllIn1SpriteShaderMaterialInspector : ShaderGUI
{
private Material targetMat;
private BlendMode srcMode, dstMode;
private CompareFunction zTestMode = CompareFunction.LessEqual;
private CullMode cullMode;
private GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle;
private const int bigFontSize = 16, smallFontSize = 11;
private string[] oldKeyWords;
private int effectCount = 1;
private Material originalMaterialCopy;
private MaterialEditor matEditor;
private MaterialProperty[] matProperties;
private uint[] materialDrawers = new uint[] { 1, 2, 4 };
bool[] currEnabledDrawers;
private const uint advancedConfigDrawer = 0;
private const uint colorFxShapeDrawer = 1;
private const uint uvFxShapeDrawer = 2;
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
matEditor = materialEditor;
matProperties = properties;
targetMat = materialEditor.target as Material;
effectCount = 1;
oldKeyWords = targetMat.shaderKeywords;
propertiesStyle = new GUIStyle(EditorStyles.helpBox);
propertiesStyle.margin = new RectOffset(0, 0, 0, 0);
bigLabelStyle = new GUIStyle(EditorStyles.boldLabel);
bigLabelStyle.fontSize = bigFontSize;
smallLabelStyle = new GUIStyle(EditorStyles.boldLabel);
smallLabelStyle.fontSize = smallFontSize;
toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true };
currEnabledDrawers = new bool[materialDrawers.Length];
uint iniDrawers = (uint)ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue;
for(int i = 0; i < materialDrawers.Length; i++) currEnabledDrawers[i] = (materialDrawers[i] & iniDrawers) > 0;
GUILayout.Label("General Properties", bigLabelStyle);
DrawProperty(0);
DrawProperty(1);
DrawProperty(2);
currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("<size=12>Show Advanced Configuration</size>"), toggleButtonStyle);
if(currEnabledDrawers[advancedConfigDrawer])
{
EditorGUILayout.BeginVertical(propertiesStyle);
Blending();
DrawLine(Color.grey, 1, 3);
Culling();
DrawLine(Color.grey, 1, 3);
ZTest();
DrawLine(Color.grey, 1, 3);
ZWrite();
DrawLine(Color.grey, 1, 3);
GenericEffect("Unity Fog", "FOG_ON", -1, -1, false, boldToggleLetters: false);
DrawLine(Color.grey, 1, 3);
Billboard("Bilboard active", "BILBOARD_ON");
DrawLine(Color.grey, 1, 3);
SpriteAtlas("Sprite inside an atlas?", "ATLAS_ON");
DrawLine(Color.grey, 1, 3);
materialEditor.EnableInstancingField();
DrawLine(Color.grey, 1, 3);
materialEditor.RenderQueueField();
EditorGUILayout.EndVertical();
}
EditorGUILayout.Separator();
DrawLine(Color.grey, 1, 3);
GUILayout.Label("Color Effects", bigLabelStyle);
currEnabledDrawers[colorFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[colorFxShapeDrawer], new GUIContent("Show Color Effects"), toggleButtonStyle);
if(currEnabledDrawers[colorFxShapeDrawer])
{
Glow("Glow", "GLOW_ON");
GenericEffect("Fade", "FADE_ON", 7, 13);
Outline("Outline", "OUTBASE_ON");
GenericEffect("Alpha Outline", "ALPHAOUTLINE_ON", 26, 30, true, "A more performant but less flexible outline");
InnerOutline("Inner Outline", "INNEROUTLINE_ON", 66, 69);
Gradient("Gradient & Radial Gradient", "GRADIENT_ON");
GenericEffect("Color Swap", "COLORSWAP_ON", 36, 42, true, "You will need a mask texture (see Documentation)", new int[] { 154 });
GenericEffect("Hue Shift", "HSV_ON", 43, 45);
ColorChange("Change 1 Color", "CHANGECOLOR_ON");
ColorRamp("Color Ramp", "COLORRAMP_ON");
GenericEffect("Hit Effect", "HITEFFECT_ON", 46, 48);
GenericEffect("Negative", "NEGATIVE_ON", 49, 49);
GenericEffect("Pixelate", "PIXELATE_ON", 50, 50, true, "Looks bad with distorition effects");
GreyScale("GreyScale", "GREYSCALE_ON");
Posterize("Posterize", "POSTERIZE_ON");
Blur("Blur", "BLUR_ON");
GenericEffect("Motion Blur", "MOTIONBLUR_ON", 62, 63);
GenericEffect("Ghost", "GHOST_ON", 64, 65, true, "This effect will not affect the outline", new int[] { 157 });
GenericEffect("Hologram", "HOLOGRAM_ON", 73, 77, true, null, new int[] { 140, 158 });
GenericEffect("Chromatic Aberration", "CHROMABERR_ON", 78, 79);
GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139 });
GenericEffect("Flicker", "FLICKER_ON", 81, 83);
GenericEffect("Shadow", "SHADOW_ON", 84, 87);
GenericEffect("Shine", "SHINE_ON", 133, 138);
GenericEffect("Contrast & Brightness", "CONTRAST_ON", 152, 153);
Overlay("Overlay Texture", "OVERLAY_ON");
GenericEffect("Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70);
GenericEffect("Alpha Round", "ALPHAROUND_ON", 144, 144);
}
DrawLine(Color.grey, 1, 3);
GUILayout.Label("UV Effects", bigLabelStyle);
currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show Alpha Effects"), toggleButtonStyle);
if(currEnabledDrawers[uvFxShapeDrawer])
{
GenericEffect("Hand Drawn", "DOODLE_ON", 88, 89);
Grass("Grass Movement / Wind", "WIND_ON");
GenericEffect("Wave", "WAVEUV_ON", 94, 98);
GenericEffect("Round Wave", "ROUNDWAVEUV_ON", 127, 128);
GenericEffect("Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99, true, "Only on single sprites spritesheets NOT supported");
GenericEffect("Offset", "OFFSETUV_ON", 100, 101);
GenericEffect("Clipping / Fill Amount", "CLIPPING_ON", 102, 105);
GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat");
GenericEffect("Zoom", "ZOOMUV_ON", 108, 108);
GenericEffect("Distortion", "DISTORT_ON", 109, 112);
GenericEffect("Twist", "TWISTUV_ON", 113, 116);
GenericEffect("Rotate", "ROTATEUV_ON", 117, 117, true, "_Tip_ Use Clipping effect to avoid possible undesired parts");
GenericEffect("Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1);
GenericEffect("Fish Eye", "FISHEYE_ON", 118, 118);
GenericEffect("Pinch", "PINCH_ON", 119, 119);
GenericEffect("Shake", "SHAKEUV_ON", 120, 122);
}
SetAndSaveEnabledDrawers(iniDrawers);
}
private void SetAndSaveEnabledDrawers(uint iniDrawers)
{
uint currDrawers = 0;
for(int i = 0; i < currEnabledDrawers.Length; i++)
{
if(currEnabledDrawers[i]) currDrawers |= materialDrawers[i];
}
if(iniDrawers != currDrawers) ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue = currDrawers;
}
private void Blending()
{
MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", matProperties);
MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", matProperties);
if(srcM.floatValue == 0 && dstM.floatValue == 0)
{
srcM.floatValue = 5;
dstM.floatValue = 10;
}
GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", smallLabelStyle);
if(GUILayout.Button("Back To Default Blending"))
{
srcM.floatValue = 5;
dstM.floatValue = 10;
targetMat.DisableKeyword("PREMULTIPLYALPHA_ON");
}
srcMode = (BlendMode)srcM.floatValue;
dstMode = (BlendMode)dstM.floatValue;
srcMode = (BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode);
dstMode = (BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode);
srcM.floatValue = (float)(srcMode);
dstM.floatValue = (float)(dstMode);
bool ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON");
bool toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini);
if(ini != toggle) Save();
if(toggle) targetMat.EnableKeyword("PREMULTIPLYALPHA_ON");
else targetMat.DisableKeyword("PREMULTIPLYALPHA_ON");
}
private void Billboard(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = inspector;
toggle = GUILayout.Toggle(toggle, effectNameLabel);
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
GUILayout.Label("Don't use this feature on UI elements!", smallLabelStyle);
DrawProperty(129, true);
MaterialProperty billboardY = matProperties[129];
if(billboardY.floatValue == 1) targetMat.EnableKeyword("BILBOARDY_ON");
else targetMat.DisableKeyword("BILBOARDY_ON");
}
else targetMat.DisableKeyword(keyword);
}
private void ZWrite()
{
MaterialProperty zWrite = ShaderGUI.FindProperty("_ZWrite", matProperties);
bool toggle = zWrite.floatValue > 0.9f ? true : false;
EditorGUILayout.BeginHorizontal();
{
float tempValue = zWrite.floatValue;
toggle = GUILayout.Toggle(toggle, new GUIContent("Enable Z Write"));
if(toggle) zWrite.floatValue = 1.0f;
else zWrite.floatValue = 0.0f;
if(tempValue != zWrite.floatValue && !Application.isPlaying) Save();
}
EditorGUILayout.EndHorizontal();
}
private void ZTest()
{
MaterialProperty zTestM = ShaderGUI.FindProperty("_ZTestMode", matProperties);
float tempValue = zTestM.floatValue;
zTestMode = (UnityEngine.Rendering.CompareFunction)zTestM.floatValue;
zTestMode = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("Z TestMode", zTestMode);
zTestM.floatValue = (float)(zTestMode);
if(tempValue != zTestM.floatValue && !Application.isPlaying) Save();
}
private void Culling()
{
MaterialProperty cullO = ShaderGUI.FindProperty("_CullingOption", matProperties);;
float tempValue = cullO.floatValue;
cullMode = (UnityEngine.Rendering.CullMode)cullO.floatValue;
cullMode = (UnityEngine.Rendering.CullMode)EditorGUILayout.EnumPopup("Culling Mode", cullMode);
cullO.floatValue = (float)(cullMode);
if(tempValue != cullO.floatValue && !Application.isPlaying) Save();
}
private void SpriteAtlas(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
toggle = GUILayout.Toggle(toggle, inspector);
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
GUILayout.Label("Make sure SpriteAtlasUV component is added \n " +
"*Check documentation if unsure what this does or how it works", smallLabelStyle);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword(keyword);
}
private void Outline(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + ".Outline";
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("OUTBASE_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(14);
DrawProperty(15);
DrawProperty(16);
DrawEffectSubKeywordToggle("Outline High Resolution?", "OUTBASE8DIR_ON");
DrawLine(Color.grey, 1, 3);
bool outlinePixelPerf = DrawEffectSubKeywordToggle("Outline is Pixel Perfect?", "OUTBASEPIXELPERF_ON");
if(outlinePixelPerf) DrawProperty(18);
else DrawProperty(17);
DrawLine(Color.grey, 1, 3);
bool outlineTexture = DrawEffectSubKeywordToggle("Outline uses texture?", "OUTTEX_ON");
if(outlineTexture)
{
DrawProperty(19);
DrawProperty(20);
DrawProperty(21);
}
DrawLine(Color.grey, 1, 3);
bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON");
if(outlineDistort)
{
DrawProperty(22);
DrawProperty(23);
DrawProperty(24);
DrawProperty(25);
}
DrawLine(Color.grey, 1, 3);
DrawEffectSubKeywordToggle("Only render outline?", "ONLYOUTLINE_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("OUTBASE_ON");
EditorGUILayout.EndToggleGroup();
}
private void GenericEffect(string inspector, string keyword, int first, int last, bool effectCounter = true, string preMessage = null, int[] extraProperties = null, bool boldToggleLetters = true)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
if(effectCounter)
{
effectNameLabel.text = effectCount + "." + inspector;
effectCount++;
}
else effectNameLabel.text = inspector;
if(boldToggleLetters) toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
else toggle = GUILayout.Toggle(toggle, effectNameLabel);
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
if(first > 0)
{
EditorGUILayout.BeginVertical(propertiesStyle);
{
if(preMessage != null) GUILayout.Label(preMessage, smallLabelStyle);
for(int i = first; i <= last; i++) DrawProperty(i);
if(extraProperties != null)
foreach(int i in extraProperties)
DrawProperty(i);
}
EditorGUILayout.EndVertical();
}
}
else targetMat.DisableKeyword(keyword);
if(boldToggleLetters) EditorGUILayout.EndToggleGroup();
}
private void Glow(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("GLOW_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
bool useGlowTex = DrawEffectSubKeywordToggle("Use Glow Texture?", "GLOWTEX_ON");
if(useGlowTex) DrawProperty(6);
DrawProperty(3);
DrawProperty(4);
DrawProperty(5, true);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("GLOW_ON");
EditorGUILayout.EndToggleGroup();
}
private void ColorRamp(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("COLORRAMP_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
bool useEditableGradient = false;
if(AssetDatabase.Contains(targetMat))
{
useEditableGradient = oldKeyWords.Contains("GRADIENTCOLORRAMP_ON");
bool gradientTex = useEditableGradient;
gradientTex = GUILayout.Toggle(gradientTex, new GUIContent("Use Editable Gradient?"));
if(useEditableGradient != gradientTex)
{
Save();
if(gradientTex)
{
useEditableGradient = true;
targetMat.EnableKeyword("GRADIENTCOLORRAMP_ON");
}
else targetMat.DisableKeyword("GRADIENTCOLORRAMP_ON");
}
if(useEditableGradient) matEditor.ShaderProperty(matProperties[159], matProperties[159].displayName);
}
else GUILayout.Label("*Save to folder to allow for dynamic Gradient property", smallLabelStyle);
if(!useEditableGradient) DrawProperty(51);
DrawProperty(52);
DrawProperty(53, true);
MaterialProperty colorRampOut = matProperties[53];
if(colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON");
else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON");
DrawProperty(155);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("COLORRAMP_ON");
EditorGUILayout.EndToggleGroup();
}
private void ColorChange(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("CHANGECOLOR_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
for(int i = 123; i < 127; i++) DrawProperty(i);
DrawLine(Color.grey, 1, 3);
ini = oldKeyWords.Contains("CHANGECOLOR2_ON");
bool toggle2 = ini;
toggle2 = EditorGUILayout.Toggle("Use Color 2", ini);
if(ini != toggle2) Save();
if(toggle2)
{
targetMat.EnableKeyword("CHANGECOLOR2_ON");
for(int i = 146; i < 149; i++) DrawProperty(i);
}
else targetMat.DisableKeyword("CHANGECOLOR2_ON");
DrawLine(Color.grey, 1, 3);
ini = oldKeyWords.Contains("CHANGECOLOR3_ON");
toggle2 = ini;
toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2);
if(ini != toggle2) Save();
if(toggle2)
{
targetMat.EnableKeyword("CHANGECOLOR3_ON");
for(int i = 149; i < 152; i++) DrawProperty(i);
}
else targetMat.DisableKeyword("CHANGECOLOR3_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("CHANGECOLOR_ON");
EditorGUILayout.EndToggleGroup();
}
private void GreyScale(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("GREYSCALE_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(54);
DrawProperty(56);
DrawProperty(55, true);
MaterialProperty greyScaleOut = matProperties[55];
if(greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON");
else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON");
DrawProperty(156);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("GREYSCALE_ON");
EditorGUILayout.EndToggleGroup();
}
private void Posterize(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("POSTERIZE_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(57);
DrawProperty(58);
DrawProperty(59, true);
MaterialProperty posterizeOut = matProperties[59];
if(posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON");
else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("POSTERIZE_ON");
EditorGUILayout.EndToggleGroup();
}
private void Blur(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("BLUR_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
GUILayout.Label("This effect will not affect the outline", smallLabelStyle);
DrawProperty(60);
DrawProperty(61, true);
MaterialProperty blurIsHd = matProperties[61];
if(blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON");
else targetMat.DisableKeyword("BLURISHD_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("BLUR_ON");
EditorGUILayout.EndToggleGroup();
}
private void Grass(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("WIND_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(90);
DrawProperty(91);
DrawProperty(145);
DrawProperty(92);
DrawProperty(93, true);
MaterialProperty grassManual = matProperties[92];
if(grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON");
else targetMat.DisableKeyword("MANUALWIND_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("WIND_ON");
EditorGUILayout.EndToggleGroup();
}
private void InnerOutline(string inspector, string keyword, int first, int last)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
if(first > 0)
{
EditorGUILayout.BeginVertical(propertiesStyle);
{
for(int i = first; i <= last; i++) DrawProperty(i);
EditorGUILayout.Separator();
DrawProperty(72, true);
MaterialProperty onlyInOutline = matProperties[72];
if(onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON");
else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON");
}
EditorGUILayout.EndVertical();
}
}
else targetMat.DisableKeyword(keyword);
EditorGUILayout.EndToggleGroup();
}
private void Gradient(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(143, true);
MaterialProperty gradIsRadial = matProperties[143];
if(gradIsRadial.floatValue == 1)
{
targetMat.EnableKeyword("RADIALGRADIENT_ON");
DrawProperty(31);
DrawProperty(32);
DrawProperty(34);
DrawProperty(141);
}
else
{
targetMat.DisableKeyword("RADIALGRADIENT_ON");
bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON");
bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient);
if(simpleGradient && !simpleGradToggle) targetMat.DisableKeyword("GRADIENT2COL_ON");
else if(!simpleGradient && simpleGradToggle) targetMat.EnableKeyword("GRADIENT2COL_ON");
DrawProperty(31);
DrawProperty(32);
if(!simpleGradToggle) DrawProperty(33);
DrawProperty(34);
if(!simpleGradToggle) DrawProperty(35);
if(!simpleGradToggle) DrawProperty(141);
DrawProperty(142);
}
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword(keyword);
EditorGUILayout.EndToggleGroup();
}
private void Overlay(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
bool multModeOn = oldKeyWords.Contains("OVERLAYMULT_ON");
bool isMultMode = multModeOn;
isMultMode = GUILayout.Toggle(isMultMode, new GUIContent("Is overlay multiplicative?"));
if(multModeOn != isMultMode)
{
Save();
if(isMultMode)
{
multModeOn = true;
targetMat.EnableKeyword("OVERLAYMULT_ON");
}
else targetMat.DisableKeyword("OVERLAYMULT_ON");
}
if(multModeOn) GUILayout.Label("Overlay is set to multiplicative mode", smallLabelStyle);
else GUILayout.Label("Overlay is set to additive mode", smallLabelStyle);
for(int i = 160; i <= 163; i++) DrawProperty(i);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword(keyword);
EditorGUILayout.EndToggleGroup();
}
private void DrawProperty(int index, bool noReset = false)
{
MaterialProperty targetProperty = matProperties[index];
EditorGUILayout.BeginHorizontal();
{
GUIContent propertyLabel = new GUIContent();
propertyLabel.text = targetProperty.displayName;
propertyLabel.tooltip = targetProperty.name + " (C#)";
matEditor.ShaderProperty(targetProperty, propertyLabel);
if(!noReset)
{
GUIContent resetButtonLabel = new GUIContent();
resetButtonLabel.text = "R";
resetButtonLabel.tooltip = "Resets to default value";
if(GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) ResetProperty(targetProperty);
}
}
EditorGUILayout.EndHorizontal();
}
private void ResetProperty(MaterialProperty targetProperty)
{
if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader);
if(targetProperty.type == MaterialProperty.PropType.Float || targetProperty.type == MaterialProperty.PropType.Range)
{
targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name);
}
else if(targetProperty.type == MaterialProperty.PropType.Vector)
{
targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name);
}
else if(targetProperty.type == MaterialProperty.PropType.Color)
{
targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name);
}
else if(targetProperty.type == MaterialProperty.PropType.Texture)
{
targetProperty.textureValue = originalMaterialCopy.GetTexture(targetProperty.name);
}
}
private bool DrawEffectSubKeywordToggle(string inspector, string keyword, bool setCustomConfigAfter = false)
{
GUIContent propertyLabel = new GUIContent();
propertyLabel.text = inspector;
propertyLabel.tooltip = keyword + " (C#)";
bool ini = oldKeyWords.Contains(keyword);
bool toggle = ini;
toggle = GUILayout.Toggle(toggle, propertyLabel);
if(ini != toggle)
{
if(toggle) targetMat.EnableKeyword(keyword);
else targetMat.DisableKeyword(keyword);
}
return toggle;
}
private void Save()
{
if(!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
EditorUtility.SetDirty(targetMat);
}
private void DrawLine(Color color, int thickness = 2, int padding = 10)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
r.height = thickness;
r.y += (padding / 2);
r.x -= 2;
r.width += 6;
EditorGUI.DrawRect(r, color);
}
}
#endif

View File

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

View File

@@ -0,0 +1,755 @@
#if UNITY_EDITOR
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;
[CanEditMultipleObjects]
public class AllIn1SpriteShaderUiMaskMaterialInspector : ShaderGUI
{
private Material targetMat;
private BlendMode srcMode, dstMode;
private GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle;
private const int bigFontSize = 16, smallFontSize = 11;
private string[] oldKeyWords;
private int effectCount = 1;
private Material originalMaterialCopy;
private MaterialEditor matEditor;
private MaterialProperty[] matProperties;
private uint[] materialDrawers = new uint[] { 1, 2, 4 };
bool[] currEnabledDrawers;
private const uint advancedConfigDrawer = 0;
private const uint colorFxShapeDrawer = 1;
private const uint uvFxShapeDrawer = 2;
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
matEditor = materialEditor;
matProperties = properties;
targetMat = materialEditor.target as Material;
effectCount = 1;
oldKeyWords = targetMat.shaderKeywords;
propertiesStyle = new GUIStyle(EditorStyles.helpBox);
propertiesStyle.margin = new RectOffset(0, 0, 0, 0);
bigLabelStyle = new GUIStyle(EditorStyles.boldLabel);
bigLabelStyle.fontSize = bigFontSize;
smallLabelStyle = new GUIStyle(EditorStyles.boldLabel);
smallLabelStyle.fontSize = smallFontSize;
toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true };
currEnabledDrawers = new bool[materialDrawers.Length];
uint iniDrawers = (uint)ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue;
for(int i = 0; i < materialDrawers.Length; i++) currEnabledDrawers[i] = (materialDrawers[i] & iniDrawers) > 0;
GUILayout.Label("General Properties", bigLabelStyle);
DrawProperty(0);
DrawProperty(1);
DrawProperty(2);
currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("<size=12>Show Advanced Configuration</size>"), toggleButtonStyle);
if(currEnabledDrawers[advancedConfigDrawer])
{
EditorGUILayout.BeginVertical(propertiesStyle);
Blending();
DrawLine(Color.grey, 1, 3);
SpriteAtlas("Sprite inside an atlas?", "ATLAS_ON");
DrawLine(Color.grey, 1, 3);
materialEditor.EnableInstancingField();
DrawLine(Color.grey, 1, 3);
materialEditor.RenderQueueField();
EditorGUILayout.EndVertical();
}
EditorGUILayout.Separator();
DrawLine(Color.grey, 1, 3);
GUILayout.Label("Color Effects", bigLabelStyle);
currEnabledDrawers[colorFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[colorFxShapeDrawer], new GUIContent("Show Color Effects"), toggleButtonStyle);
if(currEnabledDrawers[colorFxShapeDrawer])
{
Glow("Glow", "GLOW_ON");
GenericEffect("Fade", "FADE_ON", 7, 13);
Outline("Outline", "OUTBASE_ON");
GenericEffect("Alpha Outline", "ALPHAOUTLINE_ON", 26, 30, true, "A more performant but less flexible outline");
InnerOutline("Inner Outline", "INNEROUTLINE_ON", 66, 69);
Gradient("Gradient & Radial Gradient", "GRADIENT_ON");
GenericEffect("Color Swap", "COLORSWAP_ON", 36, 42, true, "You will need a mask texture (see Documentation)", new int[] { 154 });
GenericEffect("Hue Shift", "HSV_ON", 43, 45);
ColorChange("Change 1 Color", "CHANGECOLOR_ON");
ColorRamp("Color Ramp", "COLORRAMP_ON");
GenericEffect("Hit Effect", "HITEFFECT_ON", 46, 48);
GenericEffect("Negative", "NEGATIVE_ON", 49, 49);
GenericEffect("Pixelate", "PIXELATE_ON", 50, 50, true, "Looks bad with distorition effects");
GreyScale("GreyScale", "GREYSCALE_ON");
Posterize("Posterize", "POSTERIZE_ON");
Blur("Blur", "BLUR_ON");
GenericEffect("Motion Blur", "MOTIONBLUR_ON", 62, 63);
GenericEffect("Ghost", "GHOST_ON", 64, 65, true, "This effect will not affect the outline", new int[] { 157 });
GenericEffect("Hologram", "HOLOGRAM_ON", 73, 77, true, null, new int[] { 140, 158 });
GenericEffect("Chromatic Aberration", "CHROMABERR_ON", 78, 79);
GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139 });
GenericEffect("Flicker", "FLICKER_ON", 81, 83);
GenericEffect("Shadow", "SHADOW_ON", 84, 87);
GenericEffect("Shine", "SHINE_ON", 133, 138);
GenericEffect("Contrast & Brightness", "CONTRAST_ON", 152, 153);
Overlay("Overlay Texture", "OVERLAY_ON");
GenericEffect("Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70);
GenericEffect("Alpha Round", "ALPHAROUND_ON", 144, 144);
}
DrawLine(Color.grey, 1, 3);
GUILayout.Label("UV Effects", bigLabelStyle);
currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show Alpha Effects"), toggleButtonStyle);
if(currEnabledDrawers[uvFxShapeDrawer])
{
GenericEffect("Hand Drawn", "DOODLE_ON", 88, 89);
Grass("Grass Movement / Wind", "WIND_ON");
GenericEffect("Wave", "WAVEUV_ON", 94, 98);
GenericEffect("Round Wave", "ROUNDWAVEUV_ON", 127, 128);
GenericEffect("Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99, true, "Only on single sprites spritesheets NOT supported");
GenericEffect("Offset", "OFFSETUV_ON", 100, 101);
GenericEffect("Clipping / Fill Amount", "CLIPPING_ON", 102, 105);
GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat");
GenericEffect("Zoom", "ZOOMUV_ON", 108, 108);
GenericEffect("Distortion", "DISTORT_ON", 109, 112);
GenericEffect("Twist", "TWISTUV_ON", 113, 116);
GenericEffect("Rotate", "ROTATEUV_ON", 117, 117, true, "_Tip_ Use Clipping effect to avoid possible undesired parts");
GenericEffect("Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1);
GenericEffect("Fish Eye", "FISHEYE_ON", 118, 118);
GenericEffect("Pinch", "PINCH_ON", 119, 119);
GenericEffect("Shake", "SHAKEUV_ON", 120, 122);
}
SetAndSaveEnabledDrawers(iniDrawers);
}
private void SetAndSaveEnabledDrawers(uint iniDrawers)
{
uint currDrawers = 0;
for(int i = 0; i < currEnabledDrawers.Length; i++)
{
if(currEnabledDrawers[i]) currDrawers |= materialDrawers[i];
}
if(iniDrawers != currDrawers) ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue = currDrawers;
}
private void Blending()
{
MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", matProperties);
MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", matProperties);
if(srcM.floatValue == 0 && dstM.floatValue == 0)
{
srcM.floatValue = 5;
dstM.floatValue = 10;
}
GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", smallLabelStyle);
if(GUILayout.Button("Back To Default Blending"))
{
srcM.floatValue = 5;
dstM.floatValue = 10;
targetMat.DisableKeyword("PREMULTIPLYALPHA_ON");
}
srcMode = (BlendMode)srcM.floatValue;
dstMode = (BlendMode)dstM.floatValue;
srcMode = (BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode);
dstMode = (BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode);
srcM.floatValue = (float)(srcMode);
dstM.floatValue = (float)(dstMode);
bool ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON");
bool toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini);
if(ini != toggle) Save();
if(toggle) targetMat.EnableKeyword("PREMULTIPLYALPHA_ON");
else targetMat.DisableKeyword("PREMULTIPLYALPHA_ON");
}
private void SpriteAtlas(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
toggle = GUILayout.Toggle(toggle, inspector);
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
GUILayout.Label("Make sure SpriteAtlasUV component is added \n " +
"*Check documentation if unsure what this does or how it works", smallLabelStyle);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword(keyword);
}
private void Outline(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + ".Outline";
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("OUTBASE_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(14);
DrawProperty(15);
DrawProperty(16);
DrawEffectSubKeywordToggle("Outline High Resolution?", "OUTBASE8DIR_ON");
DrawLine(Color.grey, 1, 3);
bool outlinePixelPerf = DrawEffectSubKeywordToggle("Outline is Pixel Perfect?", "OUTBASEPIXELPERF_ON");
if(outlinePixelPerf) DrawProperty(18);
else DrawProperty(17);
DrawLine(Color.grey, 1, 3);
bool outlineTexture = DrawEffectSubKeywordToggle("Outline uses texture?", "OUTTEX_ON");
if(outlineTexture)
{
DrawProperty(19);
DrawProperty(20);
DrawProperty(21);
}
DrawLine(Color.grey, 1, 3);
bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON");
if(outlineDistort)
{
DrawProperty(22);
DrawProperty(23);
DrawProperty(24);
DrawProperty(25);
}
DrawLine(Color.grey, 1, 3);
DrawEffectSubKeywordToggle("Only render outline?", "ONLYOUTLINE_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("OUTBASE_ON");
EditorGUILayout.EndToggleGroup();
}
private void GenericEffect(string inspector, string keyword, int first, int last, bool effectCounter = true, string preMessage = null, int[] extraProperties = null, bool boldToggleLetters = true)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
if(effectCounter)
{
effectNameLabel.text = effectCount + "." + inspector;
effectCount++;
}
else effectNameLabel.text = inspector;
if(boldToggleLetters) toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
else toggle = GUILayout.Toggle(toggle, effectNameLabel);
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
if(first > 0)
{
EditorGUILayout.BeginVertical(propertiesStyle);
{
if(preMessage != null) GUILayout.Label(preMessage, smallLabelStyle);
for(int i = first; i <= last; i++) DrawProperty(i);
if(extraProperties != null)
foreach(int i in extraProperties)
DrawProperty(i);
}
EditorGUILayout.EndVertical();
}
}
else targetMat.DisableKeyword(keyword);
if(boldToggleLetters) EditorGUILayout.EndToggleGroup();
}
private void Glow(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("GLOW_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
bool useGlowTex = DrawEffectSubKeywordToggle("Use Glow Texture?", "GLOWTEX_ON");
if(useGlowTex) DrawProperty(6);
DrawProperty(3);
DrawProperty(4);
DrawProperty(5, true);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("GLOW_ON");
EditorGUILayout.EndToggleGroup();
}
private void ColorRamp(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("COLORRAMP_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
bool useEditableGradient = false;
if(AssetDatabase.Contains(targetMat))
{
useEditableGradient = oldKeyWords.Contains("GRADIENTCOLORRAMP_ON");
bool gradientTex = useEditableGradient;
gradientTex = GUILayout.Toggle(gradientTex, new GUIContent("Use Editable Gradient?"));
if(useEditableGradient != gradientTex)
{
Save();
if(gradientTex)
{
useEditableGradient = true;
targetMat.EnableKeyword("GRADIENTCOLORRAMP_ON");
}
else targetMat.DisableKeyword("GRADIENTCOLORRAMP_ON");
}
if(useEditableGradient) matEditor.ShaderProperty(matProperties[159], matProperties[159].displayName);
}
else GUILayout.Label("*Save to folder to allow for dynamic Gradient property", smallLabelStyle);
if(!useEditableGradient) DrawProperty(51);
DrawProperty(52);
DrawProperty(53, true);
MaterialProperty colorRampOut = matProperties[53];
if(colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON");
else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON");
DrawProperty(155);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("COLORRAMP_ON");
EditorGUILayout.EndToggleGroup();
}
private void ColorChange(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("CHANGECOLOR_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
for(int i = 123; i < 127; i++) DrawProperty(i);
DrawLine(Color.grey, 1, 3);
ini = oldKeyWords.Contains("CHANGECOLOR2_ON");
bool toggle2 = ini;
toggle2 = EditorGUILayout.Toggle("Use Color 2", ini);
if(ini != toggle2) Save();
if(toggle2)
{
targetMat.EnableKeyword("CHANGECOLOR2_ON");
for(int i = 146; i < 149; i++) DrawProperty(i);
}
else targetMat.DisableKeyword("CHANGECOLOR2_ON");
DrawLine(Color.grey, 1, 3);
ini = oldKeyWords.Contains("CHANGECOLOR3_ON");
toggle2 = ini;
toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2);
if(ini != toggle2) Save();
if(toggle2)
{
targetMat.EnableKeyword("CHANGECOLOR3_ON");
for(int i = 149; i < 152; i++) DrawProperty(i);
}
else targetMat.DisableKeyword("CHANGECOLOR3_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("CHANGECOLOR_ON");
EditorGUILayout.EndToggleGroup();
}
private void GreyScale(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("GREYSCALE_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(54);
DrawProperty(56);
DrawProperty(55, true);
MaterialProperty greyScaleOut = matProperties[55];
if(greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON");
else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON");
DrawProperty(156);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("GREYSCALE_ON");
EditorGUILayout.EndToggleGroup();
}
private void Posterize(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("POSTERIZE_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(57);
DrawProperty(58);
DrawProperty(59, true);
MaterialProperty posterizeOut = matProperties[59];
if(posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON");
else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("POSTERIZE_ON");
EditorGUILayout.EndToggleGroup();
}
private void Blur(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("BLUR_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
GUILayout.Label("This effect will not affect the outline", smallLabelStyle);
DrawProperty(60);
DrawProperty(61, true);
MaterialProperty blurIsHd = matProperties[61];
if(blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON");
else targetMat.DisableKeyword("BLURISHD_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("BLUR_ON");
EditorGUILayout.EndToggleGroup();
}
private void Grass(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword("WIND_ON");
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(90);
DrawProperty(91);
DrawProperty(145);
DrawProperty(92);
DrawProperty(93, true);
MaterialProperty grassManual = matProperties[92];
if(grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON");
else targetMat.DisableKeyword("MANUALWIND_ON");
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword("WIND_ON");
EditorGUILayout.EndToggleGroup();
}
private void InnerOutline(string inspector, string keyword, int first, int last)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
if(first > 0)
{
EditorGUILayout.BeginVertical(propertiesStyle);
{
for(int i = first; i <= last; i++) DrawProperty(i);
EditorGUILayout.Separator();
DrawProperty(72, true);
MaterialProperty onlyInOutline = matProperties[72];
if(onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON");
else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON");
}
EditorGUILayout.EndVertical();
}
}
else targetMat.DisableKeyword(keyword);
EditorGUILayout.EndToggleGroup();
}
private void Gradient(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(143, true);
MaterialProperty gradIsRadial = matProperties[143];
if(gradIsRadial.floatValue == 1)
{
targetMat.EnableKeyword("RADIALGRADIENT_ON");
DrawProperty(31);
DrawProperty(32);
DrawProperty(34);
DrawProperty(141);
}
else
{
targetMat.DisableKeyword("RADIALGRADIENT_ON");
bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON");
bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient);
if(simpleGradient && !simpleGradToggle) targetMat.DisableKeyword("GRADIENT2COL_ON");
else if(!simpleGradient && simpleGradToggle) targetMat.EnableKeyword("GRADIENT2COL_ON");
DrawProperty(31);
DrawProperty(32);
if(!simpleGradToggle) DrawProperty(33);
DrawProperty(34);
if(!simpleGradToggle) DrawProperty(35);
if(!simpleGradToggle) DrawProperty(141);
DrawProperty(142);
}
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword(keyword);
EditorGUILayout.EndToggleGroup();
}
private void Overlay(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + "." + inspector;
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if(ini != toggle) Save();
if(toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
bool multModeOn = oldKeyWords.Contains("OVERLAYMULT_ON");
bool isMultMode = multModeOn;
isMultMode = GUILayout.Toggle(isMultMode, new GUIContent("Is overlay multiplicative?"));
if(multModeOn != isMultMode)
{
Save();
if(isMultMode)
{
multModeOn = true;
targetMat.EnableKeyword("OVERLAYMULT_ON");
}
else targetMat.DisableKeyword("OVERLAYMULT_ON");
}
if(multModeOn) GUILayout.Label("Overlay is set to multiplicative mode", smallLabelStyle);
else GUILayout.Label("Overlay is set to additive mode", smallLabelStyle);
for(int i = 160; i <= 163; i++) DrawProperty(i);
}
EditorGUILayout.EndVertical();
}
else targetMat.DisableKeyword(keyword);
EditorGUILayout.EndToggleGroup();
}
private void DrawProperty(int index, bool noReset = false)
{
MaterialProperty targetProperty = matProperties[index];
EditorGUILayout.BeginHorizontal();
{
GUIContent propertyLabel = new GUIContent();
propertyLabel.text = targetProperty.displayName;
propertyLabel.tooltip = targetProperty.name + " (C#)";
matEditor.ShaderProperty(targetProperty, propertyLabel);
if(!noReset)
{
GUIContent resetButtonLabel = new GUIContent();
resetButtonLabel.text = "R";
resetButtonLabel.tooltip = "Resets to default value";
if(GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) ResetProperty(targetProperty);
}
}
EditorGUILayout.EndHorizontal();
}
private void ResetProperty(MaterialProperty targetProperty)
{
if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader);
if(targetProperty.type == MaterialProperty.PropType.Float || targetProperty.type == MaterialProperty.PropType.Range)
{
targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name);
}
else if(targetProperty.type == MaterialProperty.PropType.Vector)
{
targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name);
}
else if(targetProperty.type == MaterialProperty.PropType.Color)
{
targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name);
}
else if(targetProperty.type == MaterialProperty.PropType.Texture)
{
targetProperty.textureValue = originalMaterialCopy.GetTexture(targetProperty.name);
}
}
private bool DrawEffectSubKeywordToggle(string inspector, string keyword, bool setCustomConfigAfter = false)
{
GUIContent propertyLabel = new GUIContent();
propertyLabel.text = inspector;
propertyLabel.tooltip = keyword + " (C#)";
bool ini = oldKeyWords.Contains(keyword);
bool toggle = ini;
toggle = GUILayout.Toggle(toggle, propertyLabel);
if(ini != toggle)
{
if(toggle) targetMat.EnableKeyword(keyword);
else targetMat.DisableKeyword(keyword);
}
return toggle;
}
private void Save()
{
if(!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
EditorUtility.SetDirty(targetMat);
}
private void DrawLine(Color color, int thickness = 2, int padding = 10)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
r.height = thickness;
r.y += (padding / 2);
r.x -= 2;
r.width += 6;
EditorGUI.DrawRect(r, color);
}
}
#endif

View File

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