[Add] All in one shader

This commit is contained in:
2026-02-23 22:01:07 +07:00
parent ec0aa86ac2
commit 4f942cd7c0
806 changed files with 401510 additions and 33 deletions
@@ -0,0 +1,96 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AllIn1SpriteShader
{
[ExecuteInEditMode]
public class All1CreateUnifiedOutline : MonoBehaviour
{
[SerializeField] private Material outlineMaterial = null;
[SerializeField] private Transform outlineParentTransform = null;
[Space]
[Header("Only needed if Sprite (ignored if UI)")]
[SerializeField] private int duplicateOrderInLayer = -100;
[SerializeField] private string duplicateSortingLayer = "Default";
[Space]
[Header("This operation will delete the component")]
[SerializeField] private bool createUnifiedOutline;
void Update()
{
if (createUnifiedOutline)
{
if (outlineMaterial == null)
{
createUnifiedOutline = false;
MissingMaterial();
return;
}
List<Transform> children = new List<Transform>();
GetAllChildren(transform, ref children);
foreach (Transform t in children) CreateOutlineSpriteDuplicate(t.gameObject);
CreateOutlineSpriteDuplicate(gameObject);
DestroyImmediate(this);
}
}
private void CreateOutlineSpriteDuplicate(GameObject target)
{
bool objectIsUi = false;
SpriteRenderer ownSr = target.GetComponent<SpriteRenderer>();
Image ownImage = target.GetComponent<Image>();
if (ownSr != null) objectIsUi = false;
else if (ownImage != null) objectIsUi = true;
else if (ownSr == null && ownImage == null && !transform.Equals(outlineParentTransform)) return;
GameObject objDuplicate = new GameObject();
objDuplicate.name = target.name + "Outline";
objDuplicate.transform.position = target.transform.position;
objDuplicate.transform.rotation = target.transform.rotation;
objDuplicate.transform.localScale = target.transform.lossyScale;
if (outlineParentTransform == null) objDuplicate.transform.parent = target.transform;
else objDuplicate.transform.parent = outlineParentTransform;
if (!objectIsUi)
{
SpriteRenderer sr = objDuplicate.AddComponent<SpriteRenderer>();
sr.sprite = ownSr.sprite;
sr.sortingOrder = duplicateOrderInLayer;
sr.sortingLayerName = duplicateSortingLayer;
sr.material = outlineMaterial;
sr.flipX = ownSr.flipX;
sr.flipY = ownSr.flipY;
}
else
{
Image image = objDuplicate.AddComponent<Image>();
image.sprite = ownImage.sprite;
image.material = outlineMaterial;
}
}
private void MissingMaterial()
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("Missing Material", "Please assign a Material For New Duplicate and try again", "Ok");
#endif
}
private void GetAllChildren(Transform parent, ref List<Transform> transforms)
{
foreach (Transform child in parent)
{
transforms.Add(child);
GetAllChildren(child, ref transforms);
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 264cca4d0f5bbb54eb9de18ca54d1506
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs
uploadId: 857600
@@ -0,0 +1,829 @@
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor.SceneManagement;
#endif
namespace AllIn1SpriteShader
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
[AddComponentMenu("AllIn1SpriteShader/AddAllIn1Shader")]
public class AllIn1Shader : MonoBehaviour
{
public enum ShaderTypes
{
Default = 0,
ScaledTime = 1,
MaskedUI = 2,
Urp2dRenderer = 3,
Lit = 5,
SRPBatcher = 6,
Invalid = 4,
}
public ShaderTypes currentShaderType = ShaderTypes.Invalid;
private Material currMaterial, prevMaterial;
private bool destroyed = false;
#if UNITY_EDITOR
private bool matAssigned = false;
#endif
private enum AfterSetAction { Clear, CopyMaterial, Reset};
[Range(1f, 20f)] public float normalStrength = 5f;
[Range(0f, 3f)] public int normalSmoothing = 1;
[HideInInspector] public bool computingNormal = false;
#if UNITY_EDITOR
private static float timeLastReload = -1f;
private void Start()
{
if(timeLastReload < 0) timeLastReload = Time.time;
}
private void Update()
{
if (matAssigned || Application.isPlaying || !gameObject.activeSelf) return;
Renderer sr = GetComponent<Renderer>();
if (sr != null)
{
if (sr.sharedMaterial == null)
{
CleanMaterial();
MakeNewMaterial(true);
}
if (sr.sharedMaterial.name.Contains("Default")) MakeNewMaterial(true);
else matAssigned = true;
}
else
{
Graphic img = GetComponent<Graphic>();
if (img != null)
{
if (img.material.name.Contains("Default")) MakeNewMaterial(true);
else matAssigned = true;
}
}
}
#endif
private void MakeNewMaterial(bool getShaderTypeFromPrefs, string shaderName = "AllIn1SpriteShader")
{
bool operationSuccessful = SetMaterial(AfterSetAction.Clear, getShaderTypeFromPrefs, shaderName);
#if UNITY_EDITOR
if(operationSuccessful) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Created and Assigned");
#endif
}
public bool MakeCopy()
{
return SetMaterial(AfterSetAction.CopyMaterial, false, GetStringFromShaderType());
}
private void ResetAllProperties(bool getShaderTypeFromPrefs, string shaderName)
{
SetMaterial(AfterSetAction.Reset, getShaderTypeFromPrefs, shaderName);
}
private string GetStringFromShaderType()
{
currentShaderType = ShaderTypes.Default;
if (currentShaderType == ShaderTypes.Default) return "AllIn1SpriteShader";
else if (currentShaderType == ShaderTypes.ScaledTime) return "AllIn1SpriteShaderScaledTime";
else if (currentShaderType == ShaderTypes.MaskedUI) return "AllIn1SpriteShaderUiMask";
else if (currentShaderType == ShaderTypes.Urp2dRenderer) return "AllIn1Urp2dRenderer";
else if (currentShaderType == ShaderTypes.Lit) return "AllIn1SpriteShaderLit";
else if (currentShaderType == ShaderTypes.SRPBatcher) return "AllIn1SpriteShaderSRPBatch";
else return "AllIn1SpriteShader";
}
private bool SetMaterial(AfterSetAction action, bool getShaderTypeFromPrefs, string shaderName)
{
#if UNITY_EDITOR
Shader allIn1Shader = AllIn1ShaderWindow.FindShader(shaderName);
if (getShaderTypeFromPrefs)
{
int shaderVariant = PlayerPrefs.GetInt("allIn1DefaultShader");
currentShaderType = (ShaderTypes)shaderVariant;
if (shaderVariant == 1) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderScaledTime");
else if (shaderVariant == 2) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderUiMask");
else if (shaderVariant == 3) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer");
else if (shaderVariant == 5) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderLit");
else if (shaderVariant == 6) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderSRPBatch");
}
if (!Application.isPlaying && Application.isEditor && allIn1Shader != null)
{
bool rendererExists = false;
Renderer sr = GetComponent<Renderer>();
if (sr != null)
{
rendererExists = true;
int renderingQueue = 3000;
if(action == AfterSetAction.CopyMaterial) renderingQueue = GetComponent<Renderer>().sharedMaterial.renderQueue;
prevMaterial = new Material(GetComponent<Renderer>().sharedMaterial);
currMaterial = new Material(allIn1Shader);
currMaterial.renderQueue = renderingQueue;
GetComponent<Renderer>().sharedMaterial = currMaterial;
GetComponent<Renderer>().sharedMaterial.hideFlags = HideFlags.None;
matAssigned = true;
DoAfterSetAction(action);
}
else
{
Graphic img = GetComponent<Graphic>();
if (img != null)
{
rendererExists = true;
int renderingQueue = 3000;
if(action == AfterSetAction.CopyMaterial) renderingQueue = img.material.renderQueue;
prevMaterial = new Material(img.material);
currMaterial = new Material(allIn1Shader);
currMaterial.renderQueue = renderingQueue;
img.material = currMaterial;
img.material.hideFlags = HideFlags.None;
matAssigned = true;
DoAfterSetAction(action);
}
}
if (!rendererExists)
{
MissingRenderer();
return false;
}
else
{
SetSceneDirty();
return true;
}
}
else if (allIn1Shader == null)
{
#if UNITY_EDITOR
string logErrorMessage = "Make sure all AllIn1SpriteShader shader variants are present. Maybe delete the asset and download it again?";
Debug.LogError(logErrorMessage);
AllIn1ShaderWindow.ShowSceneViewNotification(logErrorMessage);
#endif
return false;
}
#endif
return false;
}
private void DoAfterSetAction(AfterSetAction action)
{
switch (action)
{
case AfterSetAction.Clear:
ClearAllKeywords();
break;
case AfterSetAction.CopyMaterial:
currMaterial.CopyPropertiesFromMaterial(prevMaterial);
break;
}
}
public bool TryCreateNew()
{
bool rendererExists = false;
Renderer sr = GetComponent<Renderer>();
if (sr != null)
{
rendererExists = true;
if (sr != null && sr.sharedMaterial != null && sr.sharedMaterial.name.Contains("AllIn1"))
{
ResetAllProperties(false, GetStringFromShaderType());
ClearAllKeywords();
}
else
{
CleanMaterial();
MakeNewMaterial(false, GetStringFromShaderType());
}
}
else
{
Graphic img = GetComponent<Graphic>();
if (img != null)
{
rendererExists = true;
if (img.material.name.Contains("AllIn1"))
{
ResetAllProperties(false, GetStringFromShaderType());
ClearAllKeywords();
}
else MakeNewMaterial(false, GetStringFromShaderType());
}
}
if (!rendererExists)
{
MissingRenderer();
}
SetSceneDirty();
return rendererExists;
}
public void ClearAllKeywords()
{
SetKeyword("RECTSIZE_ON");
SetKeyword("OFFSETUV_ON");
SetKeyword("CLIPPING_ON");
SetKeyword("POLARUV_ON");
SetKeyword("TWISTUV_ON");
SetKeyword("ROTATEUV_ON");
SetKeyword("FISHEYE_ON");
SetKeyword("PINCH_ON");
SetKeyword("SHAKEUV_ON");
SetKeyword("WAVEUV_ON");
SetKeyword("ROUNDWAVEUV_ON");
SetKeyword("DOODLE_ON");
SetKeyword("ZOOMUV_ON");
SetKeyword("FADE_ON");
SetKeyword("TEXTURESCROLL_ON");
SetKeyword("GLOW_ON");
SetKeyword("OUTBASE_ON");
SetKeyword("ONLYOUTLINE_ON");
SetKeyword("OUTTEX_ON");
SetKeyword("OUTDIST_ON");
SetKeyword("DISTORT_ON");
SetKeyword("WIND_ON");
SetKeyword("GRADIENT_ON");
SetKeyword("GRADIENT2COL_ON");
SetKeyword("RADIALGRADIENT_ON");
SetKeyword("COLORSWAP_ON");
SetKeyword("HSV_ON");
SetKeyword("HITEFFECT_ON");
SetKeyword("PIXELATE_ON");
SetKeyword("NEGATIVE_ON");
SetKeyword("GRADIENTCOLORRAMP_ON");
SetKeyword("COLORRAMP_ON");
SetKeyword("GREYSCALE_ON");
SetKeyword("POSTERIZE_ON");
SetKeyword("BLUR_ON");
SetKeyword("MOTIONBLUR_ON");
SetKeyword("GHOST_ON");
SetKeyword("ALPHAOUTLINE_ON");
SetKeyword("INNEROUTLINE_ON");
SetKeyword("ONLYINNEROUTLINE_ON");
SetKeyword("HOLOGRAM_ON");
SetKeyword("CHROMABERR_ON");
SetKeyword("GLITCH_ON");
SetKeyword("FLICKER_ON");
SetKeyword("SHADOW_ON");
SetKeyword("SHINE_ON");
SetKeyword("CONTRAST_ON");
SetKeyword("OVERLAY_ON");
SetKeyword("OVERLAYMULT_ON");
SetKeyword("ALPHACUTOFF_ON");
SetKeyword("ALPHAROUND_ON");
SetKeyword("CHANGECOLOR_ON");
SetKeyword("CHANGECOLOR2_ON");
SetKeyword("CHANGECOLOR3_ON");
SetKeyword("FOG_ON");
SetSceneDirty();
}
private void SetKeyword(string keyword, bool state = false)
{
if (destroyed) return;
if (currMaterial == null)
{
FindCurrMaterial();
if (currMaterial == null)
{
MissingRenderer();
return;
}
}
if (!state) currMaterial.DisableKeyword(keyword);
else currMaterial.EnableKeyword(keyword);
}
private void FindCurrMaterial()
{
Renderer sr = GetComponent<Renderer>();
if (sr != null)
{
currMaterial = GetComponent<Renderer>().sharedMaterial;
#if UNITY_EDITOR
matAssigned = true;
#endif
}
else
{
Graphic img = GetComponent<Graphic>();
if (img != null)
{
currMaterial = img.material;
#if UNITY_EDITOR
matAssigned = true;
#endif
}
}
}
public void CleanMaterial()
{
Renderer sr = GetComponent<Renderer>();
if (sr != null)
{
sr.sharedMaterial = new Material(Shader.Find("Sprites/Default"));
#if UNITY_EDITOR
matAssigned = false;
#endif
}
else
{
Graphic img = GetComponent<Graphic>();
if (img != null)
{
img.material = new Material(Shader.Find("Sprites/Default"));
#if UNITY_EDITOR
matAssigned = false;
#endif
}
}
SetSceneDirty();
}
public bool SaveMaterial()
{
#if UNITY_EDITOR
string sameMaterialPath = AllIn1ShaderWindow.GetMaterialSavePath();
sameMaterialPath += "/";
if (!System.IO.Directory.Exists(sameMaterialPath))
{
EditorUtility.DisplayDialog("The desired Material Save Path doesn't exist",
"Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok");
return false;
}
sameMaterialPath += gameObject.name;
string fullPath = sameMaterialPath + ".mat";
if (System.IO.File.Exists(fullPath))
{
SaveMaterialWithOtherName(sameMaterialPath);
}
else DoSaving(fullPath);
SetSceneDirty();
return true;
#else
return false;
#endif
}
private void SaveMaterialWithOtherName(string path, int i = 1)
{
int number = i;
string newPath = path + "_" + number.ToString();
string fullPath = newPath + ".mat";
if (System.IO.File.Exists(fullPath))
{
number++;
SaveMaterialWithOtherName(path, number);
}
else
{
DoSaving(fullPath);
}
}
private void DoSaving(string fileName)
{
#if UNITY_EDITOR
bool rendererExists = false;
Renderer sr = GetComponent<Renderer>();
Material matToSave = null;
Material createdMat = null;
if (sr != null)
{
rendererExists = true;
matToSave = sr.sharedMaterial;
}
else
{
Graphic img = GetComponent<Graphic>();
if (img != null)
{
rendererExists = true;
matToSave = img.material;
}
}
if (!rendererExists)
{
MissingRenderer();
return;
}
else
{
createdMat = new Material(matToSave);
currMaterial = createdMat;
AssetDatabase.CreateAsset(createdMat, fileName);
Debug.Log(fileName + " has been saved!");
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(fileName, typeof(Material)));
}
if (sr != null)
{
sr.material = createdMat;
}
else
{
Graphic img = GetComponent<Graphic>();
img.material = createdMat;
}
#endif
}
public void SetSceneDirty()
{
#if UNITY_EDITOR
if (!Application.isPlaying) EditorSceneManager.MarkAllScenesDirty();
//If you get an error here please delete the code block below
#if UNITY_2021_2_OR_NEWER
var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
#else
var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
#endif
if (prefabStage != null) EditorSceneManager.MarkSceneDirty(prefabStage.scene);
//Until here
#endif
}
private void MissingRenderer()
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("Missing Renderer", "This GameObject (" +
gameObject.name + ") has no Renderer or UI Image component. This AllIn1Shader component will be removed.", "Ok");
destroyed = true;
DestroyImmediate(this);
#endif
}
public bool ToggleSetAtlasUvs(bool activate)
{
bool success = false;
SetAtlasUvs atlasUvs = GetComponent<SetAtlasUvs>();
if (activate)
{
if (atlasUvs == null) atlasUvs = gameObject.AddComponent<SetAtlasUvs>();
if (atlasUvs != null) success = atlasUvs.GetAndSetUVs();
if(success) SetKeyword("ATLAS_ON", true);
}
else
{
if (atlasUvs != null)
{
atlasUvs.ResetAtlasUvs();
DestroyImmediate(atlasUvs);
success = true;
}
else
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("Missing Atlas Uv Setup", "This GameObject (" + gameObject.name + ") has no Atlas Uv Setup.", "Ok");
#endif
return false;
}
SetKeyword("ATLAS_ON", false);
}
SetSceneDirty();
return success;
}
public bool ApplyMaterialToHierarchy()
{
Renderer sr = GetComponent<Renderer>();
Graphic image = GetComponent<Graphic>();
Material matToApply = null;
if (sr != null) matToApply = sr.sharedMaterial;
else if (image != null)
{
matToApply = image.material;
}
else
{
MissingRenderer();
return false;
}
List<Transform> children = new List<Transform>();
GetAllChildren(transform, ref children);
bool hasPerformedOperation = false;
foreach (Transform t in children)
{
sr = t.gameObject.GetComponent<Renderer>();
if (sr != null) sr.material = matToApply;
else
{
image = t.gameObject.GetComponent<Graphic>();
if (image != null) image.material = matToApply;
}
hasPerformedOperation = true;
}
return hasPerformedOperation;
}
public void CheckIfValidTarget()
{
Renderer sr = GetComponent<Renderer>();
Graphic image = GetComponent<Graphic>();
if (sr == null && image == null) MissingRenderer();
}
private void GetAllChildren(Transform parent, ref List<Transform> transforms)
{
foreach (Transform child in parent)
{
transforms.Add(child);
GetAllChildren(child, ref transforms);
}
}
public bool RenderToImage()
{
#if UNITY_EDITOR
if (currMaterial == null)
{
FindCurrMaterial();
if (currMaterial == null)
{
MissingRenderer();
return false;
}
}
Texture tex = currMaterial.GetTexture("_MainTex");
if(tex != null)
{
bool success = RenderAndSaveTexture(currMaterial, tex);
if(!success) return false;
}
else
{
SpriteRenderer sr = GetComponent<SpriteRenderer>();
Graphic i = GetComponent<Graphic>();
if (sr != null && sr.sprite != null && sr.sprite.texture != null) tex = sr.sprite.texture;
else if (i != null && i.mainTexture != null) tex = i.mainTexture;
if(tex != null)
{
bool success = RenderAndSaveTexture(currMaterial, tex);
if(!success) return false;
}
else{
EditorUtility.DisplayDialog("No valid target texture found", "All In 1 Shader component couldn't find a valid Main Texture in this GameObject (" +
gameObject.name + "). This means that the material you are using has no Main Texture or that the texture couldn't be reached through the Renderer component you are using." +
" Please make sure to have a valid Main Texture in the Material or Renderer/Graphic component", "Ok");
return false;
}
}
return true;
#else
return false;
#endif
}
private bool RenderAndSaveTexture(Material targetMaterial, Texture targetTexture)
{
#if UNITY_EDITOR
float scaleSlider = 1;
if (PlayerPrefs.HasKey("All1ShaderRenderImagesScale")) scaleSlider = PlayerPrefs.GetFloat("All1ShaderRenderImagesScale");
RenderTexture renderTarget = new RenderTexture((int)(targetTexture.width * scaleSlider), (int)(targetTexture.height * scaleSlider), 0, RenderTextureFormat.ARGB32);
Graphics.Blit(targetTexture, renderTarget, targetMaterial);
Texture2D reaultTex = new Texture2D(renderTarget.width, renderTarget.height, TextureFormat.ARGB32, false);
reaultTex.ReadPixels(new Rect(0, 0, renderTarget.width, renderTarget.height), 0, 0);
reaultTex.Apply();
string path = AllIn1ShaderWindow.GetRenderImageSavePath();
path += "/";
if (!System.IO.Directory.Exists(path))
{
EditorUtility.DisplayDialog("The desired Material to Image Save Path doesn't exist",
"Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok");
return false;
}
string fullPath = path + gameObject.name + ".png";
if (System.IO.File.Exists(fullPath)) fullPath = GetNewValidPath(path + gameObject.name);
string pingPath = fullPath;
string fileName = fullPath.Replace(path, "");
fileName = fileName.Replace(".png", "");
fullPath = EditorUtility.SaveFilePanel("Save Render Image", path, fileName, "png");
if(string.IsNullOrEmpty(fullPath))
{
Debug.Log("Save operation was cancelled or no valid path was selected.");
return false;
}
byte[] bytes = reaultTex.EncodeToPNG();
File.WriteAllBytes(fullPath, bytes);
AssetDatabase.ImportAsset(subPath);
AssetDatabase.Refresh();
DestroyImmediate(reaultTex);
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(pingPath, typeof(Texture)));
Debug.Log("Render Image saved to: " + fullPath + " with scale: " + scaleSlider + " (it can be changed in Window -> AllIn1ShaderWindow)");
return true;
#else
return false;
#endif
}
private string GetNewValidPath(string path, int i = 1)
{
int number = i;
string newPath = path + "_" + number.ToString();
string fullPath = newPath + ".png";
if (System.IO.File.Exists(fullPath))
{
number++;
fullPath = GetNewValidPath(path, number);
}
return fullPath;
}
#region normalMapCreator
protected virtual void OnEnable()
{
#if UNITY_EDITOR
EditorApplication.update += OnEditorUpdate;
#endif
}
protected virtual void OnDisable()
{
#if UNITY_EDITOR
EditorApplication.update -= OnEditorUpdate;
#endif
}
bool needToWait;
int waitingCycles;
int timesWeWaited;
protected virtual void OnEditorUpdate()
{
if (computingNormal)
{
if (needToWait)
{
waitingCycles++;
if (waitingCycles > 5)
{
needToWait = false;
timesWeWaited++;
}
}
else
{
if (timesWeWaited == 1) SetNewNormalTexture2();
if (timesWeWaited == 2) SetNewNormalTexture3();
if (timesWeWaited == 3) SetNewNormalTexture4();
needToWait = true;
}
}
}
SpriteRenderer normalMapSr;
Renderer normalMapRenderer;
bool isSpriteRenderer;
public void CreateAndAssignNormalMap()
{
#if UNITY_EDITOR
if (GetComponent<TilemapRenderer>() != null)
{
EditorUtility.DisplayDialog("This is a tilemap", "This feature isn't supported on Tilemap Renderers." +
" Add a secondary normal map texture instead (you can create a Normal Map in the asset Window)", "Ok");
return;
}
normalMapSr = GetComponent<SpriteRenderer>();
normalMapRenderer = GetComponent<Renderer>();
//Debug.LogError($"NORMALMAP_ON: {normalMapRenderer.sharedMaterial.IsKeywordEnabled("NORMALMAP_ON")} -t:{Time.time}");
if (normalMapSr != null)
{
isSpriteRenderer = true;
SetNewNormalTexture();
if(!normalMapSr.sharedMaterial.IsKeywordEnabled("NORMALMAP_ON")) normalMapSr.sharedMaterial.EnableKeyword("NORMALMAP_ON");
}
else if (normalMapRenderer != null)
{
isSpriteRenderer = false;
SetNewNormalTexture();
if(!normalMapRenderer.sharedMaterial.IsKeywordEnabled("NORMALMAP_ON")) normalMapRenderer.sharedMaterial.EnableKeyword("NORMALMAP_ON");
}
else
{
if (GetComponent<Graphic>() != null)
{
EditorUtility.DisplayDialog("This is a UI element", "This GameObject (" +
gameObject.name + ") is a UI element. UI elements probably shouldn't have a normal map. Why are you using the light shader variant?", "Ok");
}
else
{
MissingRenderer();
}
return;
}
#endif
}
string path;
private void SetNewNormalTexture()
{
#if UNITY_EDITOR
path = AllIn1ShaderWindow.GetNormalMapSavePath();
path += "/";
if (!System.IO.Directory.Exists(path))
{
EditorUtility.DisplayDialog("The desired folder doesn't exist",
"Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok");
return;
}
computingNormal = true;
needToWait = true;
waitingCycles = 0;
timesWeWaited = 0;
#else
computingNormal = false;
return;
#endif
}
#if UNITY_EDITOR
TextureImporter importer;
Texture2D mainTex2D;
#endif
private void SetNewNormalTexture2()
{
#if UNITY_EDITOR
if (!isSpriteRenderer)
{
mainTex2D = (Texture2D)normalMapRenderer.sharedMaterial.GetTexture("_MainTex");
importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(mainTex2D)) as TextureImporter;
}
else importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(normalMapSr.sprite)) as TextureImporter;
importer.isReadable = true;
importer.SaveAndReimport();
#endif
}
string subPath;
private void SetNewNormalTexture3()
{
#if UNITY_EDITOR
Texture2D normalM = null;
if(isSpriteRenderer) normalM = AllIn1ShaderWindow.CreateNormalMap(normalMapSr.sprite.texture, normalStrength, normalSmoothing);
else normalM = AllIn1ShaderWindow.CreateNormalMap(mainTex2D, normalStrength, normalSmoothing);
byte[] bytes = normalM.EncodeToPNG();
path += gameObject.name;
subPath = path + ".png";
string dataPath = Application.dataPath;
dataPath = dataPath.Replace("/Assets", "/");
string fullPath = dataPath + subPath;
File.WriteAllBytes(fullPath, bytes);
AssetDatabase.ImportAsset(subPath);
AssetDatabase.Refresh();
DestroyImmediate(normalM);
#endif
}
private void SetNewNormalTexture4()
{
#if UNITY_EDITOR
importer = AssetImporter.GetAtPath(subPath) as TextureImporter;
importer.filterMode = FilterMode.Bilinear;
importer.textureType = TextureImporterType.NormalMap;
importer.wrapMode = TextureWrapMode.Repeat;
importer.SaveAndReimport();
if (currMaterial == null)
{
FindCurrMaterial();
if (currMaterial == null)
{
MissingRenderer();
return;
}
}
Texture2D normalTex = (Texture2D)AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture2D));
currMaterial.SetTexture("_NormalMap", normalTex);
Debug.Log("Normal texture saved to: " + subPath);
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture)));
computingNormal = false;
#endif
}
#endregion
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ee158225ee1e59f4791627785501d950
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs
uploadId: 857600
@@ -0,0 +1,695 @@
#if UNITY_EDITOR
using System.IO;
using UnityEditor;
using UnityEngine;
namespace AllIn1SpriteShader
{
public class AllIn1ShaderWindow : EditorWindow
{
private const string versionString = "4.661";
[MenuItem("Tools/AllIn1/SpriteShaderWindow")]
public static void ShowAllIn1ShaderWindowWindow()
{
GetWindow<AllIn1ShaderWindow>("All In 1 Shader Window");
}
public static readonly string CUSTOM_EDITOR_HEADER = "AllIn1SpriteShaderEditorImage";
private static string basePath = "Assets/Plugins/AllIn1SpriteShader";
public static readonly string materialsSavesRelativePath = "/Materials";
public static readonly string renderImagesSavesRelativePath = "/Textures";
public static readonly string normalMapSavesRelativePath = "/Textures/NormalMaps";
public static readonly string gradientSavesRelativePath = "/Textures/GradientTextures";
public Vector2 scrollPosition = Vector2.zero;
private Texture2D imageInspector;
private DefaultAsset materialTargetFolder = null;
private GUIStyle style, bigLabel = new GUIStyle(), titleStyle = new GUIStyle();
private const int bigFontSize = 16;
AllIn1Shader.ShaderTypes shaderTypes = AllIn1Shader.ShaderTypes.Default;
bool showUrpWarning = false;
double warningTime = 0f;
private Texture2D targetNormalImage;
private float normalStrength = 5f;
private int normalSmoothing = 1;
private int isComputingNormals = 0;
private enum TextureSizes
{
_2 = 2,
_4 = 4,
_8 = 8,
_16 = 16,
_32 = 32,
_64 = 64,
_128 = 128,
_256 = 256,
_512 = 512,
_1024 = 1024,
_2048 = 2048
}
private TextureSizes textureSizes = TextureSizes._128;
[SerializeField] private Gradient gradient = new Gradient();
private FilterMode gradientFiltering = FilterMode.Bilinear;
private enum ImageType
{
ShowImage,
HideInComponent,
HideEverywhere
}
private ImageType imageType;
private void OnGUI()
{
style = new GUIStyle(EditorStyles.helpBox);
style.margin = new RectOffset(0, 0, 0, 0);
bigLabel = new GUIStyle(EditorStyles.boldLabel);
bigLabel.fontSize = bigFontSize;
titleStyle.alignment = TextAnchor.MiddleLeft;
using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height)))
{
scrollPosition = scrollView.scrollPosition;
ShowImageAndSetImageEditorPref();
ShowAssetImageOptionsToggle();
DefaultAssetShader();
DrawLine(Color.grey, 1, 3);
GUILayout.Label("Material Save Path", bigLabel);
GUILayout.Space(20);
GUILayout.Label("Select the folder where new Materials will be saved when the Save Material To Folder button of the asset component is pressed", EditorStyles.boldLabel);
HandleSaveFolderEditorPref("All1ShaderMaterials", basePath + materialsSavesRelativePath, "Material");
DrawLine(Color.grey, 1, 3);
GUILayout.Label("Render Material to Image Save Path", bigLabel);
GUILayout.Space(20);
EditorGUILayout.BeginHorizontal();
{
float scaleSlider = 1;
if (PlayerPrefs.HasKey("All1ShaderRenderImagesScale")) scaleSlider = PlayerPrefs.GetFloat("All1ShaderRenderImagesScale");
GUILayout.Label("Rendered Image Texture Scale", GUILayout.MaxWidth(190));
scaleSlider = EditorGUILayout.Slider(scaleSlider, 0.2f, 5f, GUILayout.MaxWidth(200));
if (GUILayout.Button("Default Value", GUILayout.MaxWidth(100))) PlayerPrefs.SetFloat("All1ShaderRenderImagesScale", 1f);
else PlayerPrefs.SetFloat("All1ShaderRenderImagesScale", scaleSlider);
}
EditorGUILayout.EndVertical();
GUILayout.Label("Select the folder where new Images will be saved when the Render Material To Image button of the asset component is pressed", EditorStyles.boldLabel);
HandleSaveFolderEditorPref("All1ShaderRenderImages", basePath + renderImagesSavesRelativePath, "Images");
DrawLine(Color.grey, 1, 3);
NormalMapCreator();
DrawLine(Color.grey, 1, 3);
GradientCreator();
DrawLine(Color.grey, 1, 3);
GUILayout.Space(10);
SceneNotificationsToggle();
DrawLine(Color.grey, 1, 3);
GUILayout.Space(10);
RefreshLitShader();
GUILayout.Space(10);
DrawLine(Color.grey, 1, 3);
GUILayout.Label("Current asset version is " + versionString, EditorStyles.boldLabel);
}
}
private void ShowImageAndSetImageEditorPref()
{
if(!EditorPrefs.HasKey("allIn1ImageConfig"))
{
EditorPrefs.SetInt("allIn1ImageConfig", (int) ImageType.ShowImage);
}
imageType = (ImageType) EditorPrefs.GetInt("allIn1ImageConfig");
if(imageType == ImageType.HideEverywhere) return;
switch(imageType)
{
case ImageType.ShowImage:
case ImageType.HideInComponent:
if(imageInspector == null) imageInspector = GetInspectorImage();
break;
}
if(imageInspector)
{
Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(50));
GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true);
}
DrawLine(Color.grey, 1, 3);
}
public static Texture2D GetInspectorImage() => GetImage(CUSTOM_EDITOR_HEADER);
private static Texture2D GetImage(string textureName)
{
string[] guids = AssetDatabase.FindAssets($"{textureName} t:texture");
if(guids.Length > 0)
{
string path = AssetDatabase.GUIDToAssetPath(guids[0]);
return AssetDatabase.LoadAssetAtPath<Texture2D>(path);
}
return null;
}
private void ShowAssetImageOptionsToggle()
{
GUILayout.Label("Asset Image Display Options", bigLabel);
GUILayout.Space(20);
int previousImageType = (int) imageType;
imageType = (ImageType) EditorGUILayout.EnumPopup(imageType, GUILayout.MaxWidth(200));
if((int) imageType != previousImageType) EditorPrefs.SetInt("allIn1ImageConfig", (int) imageType);
DrawLine(Color.grey, 1, 3);
}
private void DefaultAssetShader()
{
GUILayout.Label("Default Asset Shader", bigLabel);
GUILayout.Space(20);
GUILayout.Label("This is the shader variant that will be assigned by default to Sprites and UI Images when the asset component is added", EditorStyles.boldLabel);
bool isUrp = false;
Shader temp = FindShader("AllIn1Urp2dRenderer");
if (temp != null) isUrp = true;
shaderTypes = (AllIn1Shader.ShaderTypes)PlayerPrefs.GetInt("allIn1DefaultShader");
int previousShaderType = (int)shaderTypes;
shaderTypes = (AllIn1Shader.ShaderTypes)EditorGUILayout.EnumPopup(shaderTypes, GUILayout.MaxWidth(200));
if (previousShaderType != (int)shaderTypes)
{
if (!isUrp && shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
showUrpWarning = true;
warningTime = EditorApplication.timeSinceStartup + 5;
}
else
{
PlayerPrefs.SetInt("allIn1DefaultShader", (int)shaderTypes);
showUrpWarning = false;
}
}
if (warningTime < EditorApplication.timeSinceStartup) showUrpWarning = false;
if (isUrp) showUrpWarning = false;
if (!isUrp && !showUrpWarning && shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
showUrpWarning = true;
warningTime = EditorApplication.timeSinceStartup + 5;
shaderTypes = AllIn1Shader.ShaderTypes.Default;
PlayerPrefs.SetInt("allIn1DefaultShader", (int)shaderTypes);
}
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);
}
private void NormalMapCreator()
{
GUILayout.Label("Normal Map Creator", bigLabel);
GUILayout.Space(20);
GUILayout.Label("Select the folder where new Normal Maps will be saved when the Create Normal Map button of the asset component is pressed (URP only)", EditorStyles.boldLabel);
HandleSaveFolderEditorPref("All1ShaderNormals", basePath + normalMapSavesRelativePath, "Normal Maps");
GUILayout.Space(20);
GUILayout.Label("Assign a sprite you want to create a normal map from. Choose the normal map settings and press the 'Create And Save Normal Map' button", EditorStyles.boldLabel);
targetNormalImage = (Texture2D)EditorGUILayout.ObjectField("Target Image", targetNormalImage, typeof(Texture2D), false, GUILayout.MaxWidth(225));
EditorGUILayout.BeginHorizontal();
{
GUILayout.Label("Normal Strength:", GUILayout.MaxWidth(150));
normalStrength = EditorGUILayout.Slider(normalStrength, 1f, 20f, GUILayout.MaxWidth(400));
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
GUILayout.Label("Normal Smoothing:", GUILayout.MaxWidth(150));
normalSmoothing = EditorGUILayout.IntSlider(normalSmoothing, 0, 3, GUILayout.MaxWidth(400));
}
EditorGUILayout.EndHorizontal();
if (isComputingNormals == 0)
{
if (targetNormalImage != null)
{
if (GUILayout.Button("Create And Save Normal Map"))
{
isComputingNormals = 1;
return;
}
}
else
{
GUILayout.Label("Add a Target Image to use this feature", EditorStyles.boldLabel);
}
}
else
{
GUILayout.Label("Normal Map is currently being created, be patient", EditorStyles.boldLabel, GUILayout.Height(40));
Repaint();
isComputingNormals++;
if (isComputingNormals > 5)
{
string assetPath = AssetDatabase.GetAssetPath(targetNormalImage);
var tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (tImporter != null)
{
tImporter.isReadable = true;
tImporter.SaveAndReimport();
}
Texture2D normalToSave = CreateNormalMap(targetNormalImage, normalStrength, normalSmoothing);
string prefSavedPath = PlayerPrefs.GetString("All1ShaderNormals") + "/";
string path = prefSavedPath + "NormalMap.png";
if(System.IO.File.Exists(path)) path = GetNewValidPath(path);
string texName = path.Replace(prefSavedPath, "");
path = EditorUtility.SaveFilePanel("Save texture as PNG", prefSavedPath, texName, "png");
//If you are reading this you might have encountered an error in Unity 2022 Mac builds, if that's the case comment the line above and uncomment the line below
//path = prefSavedPath + texName + ".png";
if (path.Length != 0)
{
byte[] pngData = normalToSave.EncodeToPNG();
if (pngData != null) File.WriteAllBytes(path, pngData);
AssetDatabase.Refresh();
if (path.IndexOf("Assets/") >= 0)
{
string subPath = path.Substring(path.IndexOf("Assets/"));
TextureImporter importer = AssetImporter.GetAtPath(subPath) as TextureImporter;
if (importer != null)
{
Debug.Log("Normal Map saved inside the project: " + subPath);
importer.filterMode = FilterMode.Bilinear;
importer.textureType = TextureImporterType.NormalMap;
importer.wrapMode = TextureWrapMode.Repeat;
importer.SaveAndReimport();
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture)));
}
}
else Debug.Log("Normal Map saved outside the project: " + path);
}
isComputingNormals = 0;
}
}
GUILayout.Label("*This process will freeze the editor for some seconds, larger images will take longer", EditorStyles.boldLabel);
}
private void HandleSaveFolderEditorPref(string keyName, string defaultPath, string logsFeatureName)
{
if (!PlayerPrefs.HasKey(keyName)) PlayerPrefs.SetString(keyName, defaultPath);
materialTargetFolder = (DefaultAsset)AssetDatabase.LoadAssetAtPath(PlayerPrefs.GetString(keyName), typeof(DefaultAsset));
if (materialTargetFolder == null)
{
PlayerPrefs.SetString(keyName, defaultPath);
materialTargetFolder = (DefaultAsset)AssetDatabase.LoadAssetAtPath(PlayerPrefs.GetString(keyName), typeof(DefaultAsset));
if (materialTargetFolder == null)
{
materialTargetFolder = (DefaultAsset)AssetDatabase.LoadAssetAtPath("Assets/", typeof(DefaultAsset));
if(materialTargetFolder == null)
{
EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(600));
EditorGUILayout.HelpBox("Folder is invalid, please select a valid one", MessageType.Error, true);
EditorGUILayout.EndHorizontal();
}
else PlayerPrefs.SetString("Assets/", defaultPath);
}
}
materialTargetFolder = (DefaultAsset)EditorGUILayout.ObjectField("New " + logsFeatureName + " Folder",
materialTargetFolder, typeof(DefaultAsset), false, GUILayout.MaxWidth(500));
if (materialTargetFolder != null && IsAssetAFolder(materialTargetFolder))
{
string path = AssetDatabase.GetAssetPath(materialTargetFolder);
PlayerPrefs.SetString(keyName, path);
EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(600));
EditorGUILayout.HelpBox("Valid folder! " + logsFeatureName + " save path: " + path, MessageType.Info);
EditorGUILayout.EndHorizontal();
}
else
{
EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(600));
EditorGUILayout.HelpBox("Select the new " + logsFeatureName + " Folder", MessageType.Warning, true);
EditorGUILayout.EndHorizontal();
}
}
private void GradientCreator()
{
GUILayout.Label("Gradient Creator", bigLabel);
GUILayout.Space(20);
GUILayout.Label("This feature can be used to create textures for the Color Ramp Effect", EditorStyles.boldLabel);
EditorGUILayout.GradientField("Gradient", gradient, GUILayout.Height(25), GUILayout.MaxWidth(500));
EditorGUILayout.BeginHorizontal();
{
GUILayout.Label("Texture Size:", GUILayout.MaxWidth(145));
textureSizes = (TextureSizes)EditorGUILayout.EnumPopup(textureSizes, GUILayout.MaxWidth(200));
}
EditorGUILayout.EndHorizontal();
int textureSize = (int)textureSizes;
Texture2D gradTex = new Texture2D(textureSize, 1, TextureFormat.RGBA32, false);
for (int i = 0; i < textureSize; i++) gradTex.SetPixel(i, 0, gradient.Evaluate((float)i / (float)textureSize));
gradTex.Apply();
GUILayout.Space(20);
GUILayout.Label("Select the folder where new Gradient Textures will be saved", EditorStyles.boldLabel);
HandleSaveFolderEditorPref("All1ShaderGradients", basePath + gradientSavesRelativePath, "Gradient");
string prefSavedPath = PlayerPrefs.GetString("All1ShaderGradients") + "/";
if (Directory.Exists(prefSavedPath))
{
EditorGUILayout.BeginHorizontal();
{
GUILayout.Label("Gradient Texture Filtering: ", GUILayout.MaxWidth(170));
gradientFiltering = (FilterMode)EditorGUILayout.EnumPopup(gradientFiltering, GUILayout.MaxWidth(200));
}
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("Save Gradient Texture", GUILayout.MaxWidth(500)))
{
string path = prefSavedPath + "ColorGradient.png";
if(System.IO.File.Exists(path)) path = GetNewValidPath(path);
string texName = path.Replace(prefSavedPath, "");
path = EditorUtility.SaveFilePanel("Save texture as PNG", prefSavedPath, texName, "png");
if (path.Length != 0)
{
byte[] pngData = gradTex.EncodeToPNG();
if (pngData != null) File.WriteAllBytes(path, pngData);
AssetDatabase.Refresh();
if (path.IndexOf("Assets/") >= 0)
{
string subPath = path.Substring(path.IndexOf("Assets/"));
TextureImporter importer = AssetImporter.GetAtPath(subPath) as TextureImporter;
if (importer != null)
{
Debug.Log("Gradient saved inside the project: " + subPath);
importer.filterMode = gradientFiltering;
importer.SaveAndReimport();
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture)));
}
}
else Debug.Log("Gradient saved outside the project: " + path);
}
}
}
}
private static bool IsAssetAFolder(Object obj)
{
string path = "";
if (obj == null) return false;
#if UNITY_6000_3_OR_NEWER
path = AssetDatabase.GetAssetPath(obj.GetEntityId());
#else
path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
#endif
if (path.Length > 0)
{
if (Directory.Exists(path)) return true;
else return false;
}
return false;
}
private static string GetNewValidPath(string path, string extension = ".png", int i = 1)
{
int number = i;
path = path.Replace(extension, "");
string newPath = path + "_" + number.ToString();
string fullPath = newPath + extension;
if(File.Exists(fullPath))
{
number++;
fullPath = GetNewValidPath(path, extension, number);
}
return fullPath;
}
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);
}
public static Texture2D CreateNormalMap(Texture2D t, float normalMult = 5f, int normalSmooth = 0)
{
int width = t.width;
int height = t.height;
Color[] sourcePixels = t.GetPixels();
Color[] resultPixels = new Color[width * height];
Vector3 vScale = new Vector3(0.3333f, 0.3333f, 0.3333f);
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
int index = x + y * width;
Vector3 cSampleNegXNegY = GetPixelClamped(sourcePixels, x - 1, y - 1, width, height);
Vector3 cSampleZerXNegY = GetPixelClamped(sourcePixels, x, y - 1, width, height);
Vector3 cSamplePosXNegY = GetPixelClamped(sourcePixels, x + 1, y - 1, width, height);
Vector3 cSampleNegXZerY = GetPixelClamped(sourcePixels, x - 1, y, width, height);
Vector3 cSamplePosXZerY = GetPixelClamped(sourcePixels, x + 1, y, width, height);
Vector3 cSampleNegXPosY = GetPixelClamped(sourcePixels, x - 1, y + 1, width, height);
Vector3 cSampleZerXPosY = GetPixelClamped(sourcePixels, x, y + 1, width, height);
Vector3 cSamplePosXPosY = GetPixelClamped(sourcePixels, x + 1, y + 1, width, height);
float fSampleNegXNegY = Vector3.Dot(cSampleNegXNegY, vScale);
float fSampleZerXNegY = Vector3.Dot(cSampleZerXNegY, vScale);
float fSamplePosXNegY = Vector3.Dot(cSamplePosXNegY, vScale);
float fSampleNegXZerY = Vector3.Dot(cSampleNegXZerY, vScale);
float fSamplePosXZerY = Vector3.Dot(cSamplePosXZerY, vScale);
float fSampleNegXPosY = Vector3.Dot(cSampleNegXPosY, vScale);
float fSampleZerXPosY = Vector3.Dot(cSampleZerXPosY, vScale);
float fSamplePosXPosY = Vector3.Dot(cSamplePosXPosY, vScale);
float edgeX = (fSampleNegXNegY - fSamplePosXNegY) * 0.25f + (fSampleNegXZerY - fSamplePosXZerY) * 0.5f + (fSampleNegXPosY - fSamplePosXPosY) * 0.25f;
float edgeY = (fSampleNegXNegY - fSampleNegXPosY) * 0.25f + (fSampleZerXNegY - fSampleZerXPosY) * 0.5f + (fSamplePosXNegY - fSamplePosXPosY) * 0.25f;
Vector2 vEdge = new Vector2(edgeX, edgeY) * normalMult;
Vector3 norm = new Vector3(vEdge.x, vEdge.y, 1.0f).normalized;
resultPixels[index] = new Color(norm.x * 0.5f + 0.5f, norm.y * 0.5f + 0.5f, norm.z * 0.5f + 0.5f, 1);
}
}
if(normalSmooth > 0)
{
resultPixels = SmoothNormals(resultPixels, width, height, normalSmooth);
}
Texture2D texNormal = new Texture2D(width, height, TextureFormat.RGB24, false, false);
texNormal.SetPixels(resultPixels);
texNormal.Apply();
return texNormal;
}
private static Vector3 GetPixelClamped(Color[] pixels, int x, int y, int width, int height)
{
x = Mathf.Clamp(x, 0, width - 1);
y = Mathf.Clamp(y, 0, height - 1);
Color c = pixels[x + y * width];
return new Vector3(c.r, c.g, c.b);
}
private static Color[] SmoothNormals(Color[] pixels, int width, int height, int normalSmooth)
{
Color[] smoothedPixels = new Color[pixels.Length];
float step = 0.00390625f * normalSmooth;
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
float pixelsToAverage = 0.0f;
Color c = pixels[x + y * width];
pixelsToAverage++;
for(int offsetY = -normalSmooth; offsetY <= normalSmooth; offsetY++)
{
for(int offsetX = -normalSmooth; offsetX <= normalSmooth; offsetX++)
{
if(offsetX == 0 && offsetY == 0) continue;
int sampleX = Mathf.Clamp(x + offsetX, 0, width - 1);
int sampleY = Mathf.Clamp(y + offsetY, 0, height - 1);
c += pixels[sampleX + sampleY * width];
pixelsToAverage++;
}
}
smoothedPixels[x + y * width] = c / pixelsToAverage;
}
}
return smoothedPixels;
}
[MenuItem("Assets/Create/AllIn1Shader Materials/CreateDefaultMaterial")]
public static void CreateDefaultMaterial()
{
CreateMaterial("AllIn1SpriteShader");
}
[MenuItem("Assets/Create/AllIn1Shader Materials/CreateScaledTimeMaterial")]
public static void CreateScaledTimeMaterial()
{
CreateMaterial("AllIn1SpriteShaderScaledTime");
}
[MenuItem("Assets/Create/AllIn1Shader Materials/CreateUiMaskMaterial")]
public static void CreateUiMaskMaterial()
{
CreateMaterial("AllIn1SpriteShaderUiMask");
}
private static void CreateMaterial(string shaderName)
{
string selectedPath = AssetDatabase.GetAssetPath(Selection.activeObject);
if(!string.IsNullOrEmpty(selectedPath) && Directory.Exists(selectedPath))
{
Material material = new Material(FindShader(shaderName));
string fullPath = selectedPath + "/Mat-" + shaderName + ".mat";
if(File.Exists(fullPath)) fullPath = GetNewValidPath(fullPath, ".mat");
AssetDatabase.CreateAsset(material, fullPath);
AssetDatabase.Refresh();
}
else
{
Debug.LogWarning("Please select a valid folder in the Project Window.");
}
}
private void OnEnable() => GetBasePath();
private static void GetBasePath()
{
string[] guids = AssetDatabase.FindAssets("t:folder AllIn1SpriteShader");
if(guids.Length > 0)
{
basePath = AssetDatabase.GUIDToAssetPath(guids[0]);
}
else
{
Debug.LogError("AllIn1SpriteShader folder not found in the project.");
basePath = "Assets/Plugins/AllIn1SpriteShader";
}
}
public static string GetMaterialSavePath()
{
if(!PlayerPrefs.HasKey("All1ShaderMaterials"))
{
GetBasePath();
return basePath + materialsSavesRelativePath;
}
return PlayerPrefs.GetString("All1ShaderMaterials");
}
public static string GetRenderImageSavePath()
{
if(!PlayerPrefs.HasKey("All1ShaderRenderImages"))
{
GetBasePath();
return basePath + renderImagesSavesRelativePath;
}
return PlayerPrefs.GetString("All1ShaderRenderImages");
}
public static string GetNormalMapSavePath()
{
if(!PlayerPrefs.HasKey("All1ShaderNormals"))
{
GetBasePath();
return basePath + normalMapSavesRelativePath;
}
return PlayerPrefs.GetString("All1ShaderNormals");
}
private void SceneNotificationsToggle()
{
float previousLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 200f;
bool areNotificationsEnabled = EditorPrefs.GetInt("DisplaySceneViewNotifications", 1) == 1;
areNotificationsEnabled = EditorGUILayout.Toggle("Display Scene View Notifications", areNotificationsEnabled);
EditorPrefs.SetInt("DisplaySceneViewNotifications", areNotificationsEnabled ? 1 : 0);
EditorGUIUtility.labelWidth = previousLabelWidth;
}
private static void RefreshLitShader()
{
GUILayout.Label("Force the Lit Shader to be reconfigured");
GUILayout.Label("If you are getting some error or have changed the render pipeline press the button below");
if (GUILayout.Button("Refresh Lit Shader", GUILayout.MaxWidth(500f)))
{
AllIn1ShaderImporter.ForceReimport();
}
}
public static void SceneViewNotificationAndLog(string message)
{
Debug.Log(message);
ShowSceneViewNotification(message);
}
public static void ShowSceneViewNotification(string message)
{
bool showNotification = EditorPrefs.GetInt("DisplaySceneViewNotifications", 1) == 1;
if(!showNotification) return;
GUIContent content = new GUIContent(message);
#if UNITY_2019_1_OR_NEWER
SceneView.lastActiveSceneView.ShowNotification(content, 1.5f);
#else
SceneView.lastActiveSceneView.ShowNotification(content);
#endif
}
public static Shader FindShader(string shaderName)
{
string[] guids = AssetDatabase.FindAssets($"{shaderName} t:shader");
foreach(string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
if(shader != null)
{
string fullShaderName = shader.name;
string actualShaderName = fullShaderName.Substring(fullShaderName.LastIndexOf('/') + 1);
if(actualShaderName.Equals(shaderName)) return shader;
}
}
return null;
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b642652081667ab4fad9f2579fec0e51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs
uploadId: 857600
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 88005189a0eaefe4aa34961fe0208e26
folderAsset: yes
timeCreated: 1464994693
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,894 @@
#if UNITY_EDITOR
using System.Linq;
using AllIn1SpriteShader;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;
namespace AllIn1SpriteShader
{
[CanEditMultipleObjects]
public class AllIn12DRendererMaterialInspector : 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, 8 };
bool[] currEnabledDrawers;
private const uint advancedConfigDrawer = 0;
private const uint colorFxShapeDrawer = 1;
private const uint uvFxShapeDrawer = 2;
private const uint lightingDrawer = 3;
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(177);
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);
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();
}
DrawLine(Color.grey, 1, 3);
GUILayout.Label("Lighting Properties", bigLabelStyle);
currEnabledDrawers[lightingDrawer] = GUILayout.Toggle(currEnabledDrawers[lightingDrawer], new GUIContent("Show Lighting Properties"), toggleButtonStyle);
if(currEnabledDrawers[lightingDrawer])
{
for (int i = 172; i <= 175; i++) DrawProperty(i);
DrawProperty(176, true);
MaterialProperty glowLight = properties[176];
if (glowLight.floatValue == 1) targetMat.EnableKeyword("GLOWLIGHT_ON");
else targetMat.DisableKeyword("GLOWLIGHT_ON");
}
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");
Fade("Fade", "FADE_ON");
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, 184 });
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("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166);
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, true, null, new int[] { 182 });
GenericEffect("Warp Distortion", "WARP_ON", 167, 169);
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 Fade(string inspector, string keyword)
{
bool toggle = oldKeyWords.Contains(keyword);
bool ini = toggle;
GUIContent effectNameLabel = new GUIContent();
effectNameLabel.tooltip = keyword + " (C#)";
effectNameLabel.text = effectCount + ".Fade";
toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle);
effectCount++;
if (ini != toggle) Save();
if (toggle)
{
targetMat.EnableKeyword(keyword);
EditorGUILayout.BeginVertical(propertiesStyle);
{
DrawProperty(7);
DrawProperty(178);
DrawProperty(8);
DrawProperty(9);
DrawProperty(10);
DrawProperty(11);
DrawProperty(12);
DrawProperty(179);
DrawProperty(13);
}
EditorGUILayout.EndVertical();
}
else
{
targetMat.DisableKeyword(keyword);
}
EditorGUILayout.EndToggleGroup();
}
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);
DrawProperty(180);
}
DrawLine(Color.grey, 1, 3);
bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON");
if(outlineDistort)
{
DrawProperty(22);
DrawProperty(23);
DrawProperty(24);
DrawProperty(25);
DrawProperty(181);
}
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);
DrawProperty(160);
DrawProperty(183);
DrawProperty(161);
DrawProperty(162);
DrawProperty(163);
for(int i = 170; i <= 171; 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)
{
AllIn1ShaderPropertyType propertyType = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty);
if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader);
if(propertyType == AllIn1ShaderPropertyType.Float || propertyType == AllIn1ShaderPropertyType.Range)
{
targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name);
}
else if(propertyType == AllIn1ShaderPropertyType.Vector)
{
targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name);
}
else if(propertyType == AllIn1ShaderPropertyType.Color)
{
targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name);
}
else if(propertyType == AllIn1ShaderPropertyType.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
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: e063793833d64b7439fd1f34dc70b052
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs
uploadId: 857600
@@ -0,0 +1,26 @@
#if UNITY_EDITOR
using UnityEditor;
namespace AllIn1SpriteShader
{
public class AllIn1ShaderAssetPostProcessor : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
{
bool needToRefreshConfig = false;
for (int i = 0; i < importedAssets.Length; i++)
{
if (importedAssets[i].EndsWith(Constants.MAIN_ASSEMBLY_NAME))
{
needToRefreshConfig = needToRefreshConfig || true;
}
}
if (needToRefreshConfig)
{
AllIn1ShaderImporter.ForceReimport();
}
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9ab4f76bf224f2b4d8735f59db902c37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs
uploadId: 857600
@@ -0,0 +1,283 @@
#if UNITY_EDITOR
using System;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace AllIn1SpriteShader
{
public class AllIn1ShaderGradientDrawer : MaterialPropertyDrawer
{
private int resolution;
private Texture2D textureAsset;
private static MethodInfo reinitializeMethod;
private static MethodInfo resizeMethod;
public AllIn1ShaderGradientDrawer()
{
resolution = 64;
}
public AllIn1ShaderGradientDrawer(float res)
{
resolution = (int)res;
}
private static bool IsPropertyTypeSuitable(MaterialProperty prop)
{
AllIn1ShaderPropertyType propertyType = EditorUtils.GetShaderTypeByMaterialProperty(prop);
return propertyType == AllIn1ShaderPropertyType.Texture;
}
private string TextureName(MaterialProperty prop) => $"z{prop.name}Tex";
private string OldName(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);
string oldTextureName = OldName(prop);
Gradient currentGradient = null;
if (prop.targets.Length == 1)
{
Material target = (Material)prop.targets[0];
string path = AssetDatabase.GetAssetPath(target);
textureAsset = GetTexture(path, textureName, oldTextureName);
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, oldTextureName);
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, string possibleOldName)
{
textureAsset = GetTextureAsset(path, name);
if(textureAsset == null)
{
textureAsset = GetTextureAsset(path, possibleOldName);
if(textureAsset != null)
{
textureAsset.name = textureAsset.name.Replace(possibleOldName, name);
EditorUtility.SetDirty(textureAsset);
}
}
if (textureAsset == null) CreateTexture(path, name);
if(textureAsset.width != resolution)
{
ResizeTexture(textureAsset, resolution, 1);
EditorUtility.SetDirty(textureAsset);
AssetDatabase.SaveAssets();
}
return textureAsset;
}
private void ResizeTexture(Texture2D texture, int width, int height)
{
if(reinitializeMethod == null && resizeMethod == null)
{
reinitializeMethod = typeof(Texture2D).GetMethod("Reinitialize", new[] { typeof(int), typeof(int) });
if(reinitializeMethod == null) resizeMethod = typeof(Texture2D).GetMethod("Resize", new[] { typeof(int), typeof(int) });
}
if(reinitializeMethod != null) reinitializeMethod.Invoke(texture, new object[] { width, height });
else if(resizeMethod != null) resizeMethod.Invoke(texture, new object[] { width, height });
}
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 Gradients/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);
}
private 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();
}
private 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
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c51263ea47edd3641a26e5f242925bcf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs
uploadId: 857600
@@ -0,0 +1,221 @@
#if UNITY_EDITOR
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace AllIn1SpriteShader
{
[InitializeOnLoad]
public static class AllIn1ShaderImporter
{
public enum UnityVersion
{
NONE = 0,
UNITY_2019 = 1,
UNITY_2020 = 2,
UNITY_2021 = 3,
UNITY_2022 = 4,
UNITY_6 = 5,
}
public enum RenderPipeline
{
NONE = -1,
BIRP = 0,
URP = 1,
HDRP = 2,
}
private const string SHADER_FOLDER_PATH = "../../Shaders/LitShaders";
private const string FINAL_SHADERS_FOLDER_PATH = "../../Shaders";
private const string SHADER_TEMPLATE_NAME = @"{0}_{1}.txt";
private const string SPRITE_LIT_SHADER_NAME = "AllIn1SpriteShaderLit";
private const string SPRITE_LIT_TRANSPARENT_SHADER_NAME = "AllIn1SpriteShaderLitTransparent";
private const string PIPELINE_SUFFIX_URP_2019 = "BetterShader_URP2019";
private const string PIPELINE_SUFFIX_HDRP_2019 = "BetterShader_HDRP2019";
private const string PIPELINE_SUFFIX_URP_2020 = "BetterShader_URP2020";
private const string PIPELINE_SUFFIX_HDRP_2020 = "BetterShader_HDRP2020";
private const string PIPELINE_SUFFIX_URP_2021 = "BetterShader_URP2021";
private const string PIPELINE_SUFFIX_HDRP_2021 = "BetterShader_HDRP2021";
private const string PIPELINE_SUFFIX_URP_2022 = "BetterShader_URP2022";
private const string PIPELINE_SUFFIX_HDRP_2022 = "BetterShader_HDRP2022";
private const string PIPELINE_SUFFIX_URP_2023 = "BetterShader_URP2023";
private const string PIPELINE_SUFFIX_HDRP_2023 = "BetterShader_HDRP2023";
private const string PIPELINE_SUFFIX_STANDARD = "BetterShader_Standard";
private const string LIT_SHADER_PIPELINE_KEY = "AllIn1SpriteShader_LitShader_RenderPipeline";
private const string LIT_SHADER_UNITY_VERSION_KEY = "AllIn1SpriteShader_LitShader_UnityVersion";
private const string LIT_SHADER_FIRST_TIME_PROJECT = "AllIn1SpriteShader_LitShader_FirstTimeProject";
static AllIn1ShaderImporter()
{
ConfigureShaders();
}
private static void ConfigureShaders()
{
RenderPipelineChecker.RefreshData();
UnityVersion unityVersion = GetUnityVersion();
RenderPipeline renderPipeline = GetRenderPipeline();
RenderPipeline lastRenderPipeline = (RenderPipeline)SessionState.GetInt(LIT_SHADER_PIPELINE_KEY, -1);
UnityVersion lastUnityVersion = (UnityVersion)SessionState.GetInt(LIT_SHADER_UNITY_VERSION_KEY, 0);
int firstTimeProject = SessionState.GetInt(LIT_SHADER_FIRST_TIME_PROJECT, -1);
if (lastRenderPipeline != renderPipeline || lastUnityVersion != unityVersion || firstTimeProject != 1)
{
SessionState.SetInt(LIT_SHADER_PIPELINE_KEY, (int)renderPipeline);
SessionState.SetInt(LIT_SHADER_UNITY_VERSION_KEY, (int)unityVersion);
SessionState.SetInt(LIT_SHADER_FIRST_TIME_PROJECT, 1);
ConfigureShader(SPRITE_LIT_SHADER_NAME);
ConfigureShader(SPRITE_LIT_TRANSPARENT_SHADER_NAME);
}
}
private static void ConfigureShader(string shaderName)
{
string pipelineSufix = string.Empty;
UnityVersion unityVersion = GetUnityVersion();
RenderPipeline renderPipeline = GetRenderPipeline();
if (renderPipeline == RenderPipeline.HDRP)
{
switch (unityVersion)
{
case UnityVersion.UNITY_2019:
pipelineSufix = PIPELINE_SUFFIX_HDRP_2019;
break;
case UnityVersion.UNITY_2020:
pipelineSufix = PIPELINE_SUFFIX_HDRP_2020;
break;
case UnityVersion.UNITY_2021:
pipelineSufix = PIPELINE_SUFFIX_HDRP_2021;
break;
case UnityVersion.UNITY_2022:
pipelineSufix = PIPELINE_SUFFIX_HDRP_2022;
break;
case UnityVersion.UNITY_6:
pipelineSufix = PIPELINE_SUFFIX_HDRP_2023;
break;
}
}
else if (renderPipeline == RenderPipeline.URP)
{
switch (unityVersion)
{
case UnityVersion.UNITY_2019:
pipelineSufix = PIPELINE_SUFFIX_URP_2019;
break;
case UnityVersion.UNITY_2020:
pipelineSufix = PIPELINE_SUFFIX_URP_2020;
break;
case UnityVersion.UNITY_2021:
pipelineSufix = PIPELINE_SUFFIX_URP_2021;
break;
case UnityVersion.UNITY_2022:
pipelineSufix = PIPELINE_SUFFIX_URP_2022;
break;
case UnityVersion.UNITY_6:
pipelineSufix = PIPELINE_SUFFIX_URP_2023;
break;
}
}
else
{
pipelineSufix = PIPELINE_SUFFIX_STANDARD;
}
string templateFileName = string.Format(SHADER_TEMPLATE_NAME, shaderName, pipelineSufix);
string shaderTemplatePath = SHADER_FOLDER_PATH + "/" + templateFileName;
string finalShaderPath = FINAL_SHADERS_FOLDER_PATH + "/" + $"{shaderName}.shader";
try
{
var currentFileGUID = AssetDatabase.FindAssets($"t:Script {nameof(AllIn1ShaderImporter)}")[0];
string currentFolder = Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(currentFileGUID));
string newShaderStr = File.ReadAllText(Path.Combine(currentFolder, shaderTemplatePath));
newShaderStr = newShaderStr.Replace($"Shader \"AllIn1SpriteShader/{shaderName}_BetterShader\"", $"Shader \"AllIn1SpriteShader/{shaderName}\"");
File.WriteAllText(Path.Combine(currentFolder, finalShaderPath), EditorUtils.UnifyEOL(newShaderStr));
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
catch (Exception e)
{
Debug.LogError("Shader not found: " + e);
}
}
private static UnityVersion GetUnityVersion()
{
UnityVersion res = UnityVersion.NONE;
string unityVersion = Application.unityVersion;
if (unityVersion.Contains("2019"))
{
res = UnityVersion.UNITY_2019;
}
else if (unityVersion.Contains("2020"))
{
res = UnityVersion.UNITY_2020;
}
else if (unityVersion.Contains("2021"))
{
res = UnityVersion.UNITY_2021;
}
else if (unityVersion.Contains("2022"))
{
res = UnityVersion.UNITY_2022;
}
else if (unityVersion.Contains("6000"))
{
res = UnityVersion.UNITY_6;
}
return res;
}
private static RenderPipeline GetRenderPipeline()
{
RenderPipeline res = RenderPipeline.BIRP;
if (RenderPipelineChecker.IsURP)
{
res = RenderPipeline.URP;
}
else if (RenderPipelineChecker.IsHDRP)
{
res = RenderPipeline.HDRP;
}
return res;
}
public static void ForceReimport()
{
SessionState.EraseInt(LIT_SHADER_PIPELINE_KEY);
SessionState.EraseInt(LIT_SHADER_UNITY_VERSION_KEY);
SessionState.EraseInt(LIT_SHADER_FIRST_TIME_PROJECT);
ConfigureShaders();
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: aa9d501412652444c8b5b573248c31be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs
uploadId: 857600
@@ -0,0 +1,12 @@
namespace AllIn1SpriteShader
{
public enum AllIn1ShaderPropertyType
{
Color,
Vector,
Float,
Range,
Texture,
Int,
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 292320b1088d1734184f5459f884be05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs
uploadId: 857600
@@ -0,0 +1,327 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using ShaderType = AllIn1SpriteShader.AllIn1Shader.ShaderTypes;
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 Texture2D imageInspector;
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()
{
ChooseAndDisplayAssetImage();
AllIn1Shader myScript = (AllIn1Shader)target;
SetCurrentShaderType(myScript);
if (GUILayout.Button("Deactivate All Effects"))
{
for (int i = 0; i < targets.Length; i++) ((AllIn1Shader)targets[i]).ClearAllKeywords();
AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Deactivated All Effects");
}
if (GUILayout.Button("New Clean Material"))
{
bool successOperation = true;
for (int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader)targets[i]).TryCreateNew();
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Clean Material");
}
if (GUILayout.Button("Create New Material With Same Properties (SEE DOC)"))
{
bool successOperation = true;
for (int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader)targets[i]).MakeCopy();
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Copy Created");
}
if (GUILayout.Button("Save Material To Folder (SEE DOC)"))
{
bool successOperation = true;
for(int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader) targets[i]).SaveMaterial();
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Saved");
}
if (GUILayout.Button("Apply Material To All Children"))
{
bool successOperation = true;
for(int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader) targets[i]).ApplyMaterialToHierarchy();
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Applied To Children");
else EditorUtility.DisplayDialog("No children found", "All In 1 Shader component couldn't find any children to this GameObject (" + targets[0].name + ")", "Ok");
}
if (myScript.currentShaderType != AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
if (GUILayout.Button("Render Material To Image"))
{
bool successOperation = true;
for(int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader) targets[i]).RenderToImage();
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Rendered To Image");
}
}
bool isUrp = false;
Shader temp = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer");
if (temp != null) isUrp = true;
EditorGUILayout.BeginHorizontal();
{
GUILayout.Label("Change Shader Variant:", GUILayout.MaxWidth(140));
int previousShaderType = (int)myScript.currentShaderType;
myScript.currentShaderType = (AllIn1Shader.ShaderTypes)EditorGUILayout.EnumPopup(myScript.currentShaderType);
if (previousShaderType != (int)myScript.currentShaderType)
{
for (int i = 0; i < targets.Length; i++) ((AllIn1Shader)targets[i]).CheckIfValidTarget();
if (myScript == null) return;
if (isUrp || myScript.currentShaderType != AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
AllIn1ShaderWindow.SceneViewNotificationAndLog(myScript.gameObject.name + " shader variant has been changed to: " + myScript.currentShaderType);
myScript.SetSceneDirty();
Renderer sr = myScript.GetComponent<Renderer>();
if (sr != null)
{
if (sr.sharedMaterial != null)
{
int renderingQueue = sr.sharedMaterial.renderQueue;
if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Default) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShader");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.ScaledTime) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderScaledTime");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.MaskedUI) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderUiMask");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderLit");
else if(myScript.currentShaderType == AllIn1Shader.ShaderTypes.SRPBatcher) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderSRPBatch");
else SetCurrentShaderType(myScript);
sr.sharedMaterial.renderQueue = renderingQueue;
if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit)
{
sr.sharedMaterial.SetFloat("_ZWrite", 1.0f);
sr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
sr.receiveShadows = true;
sr.sharedMaterial.renderQueue = 2000;
}
else
{
sr.sharedMaterial.SetFloat("_ZWrite", 0f);
sr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
sr.receiveShadows = false;
sr.sharedMaterial.renderQueue = 3000;
}
}
}
else
{
Graphic img = myScript.GetComponent<Graphic>();
if (img != null && img.material != null)
{
int renderingQueue = img.material.renderQueue;
if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Default) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShader");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.ScaledTime) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderScaledTime");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.MaskedUI) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderUiMask");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer");
else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderLit");
else if(myScript.currentShaderType == AllIn1Shader.ShaderTypes.SRPBatcher) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderSRPBatch");
else SetCurrentShaderType(myScript);
img.material.renderQueue = renderingQueue;
}
}
}
else if(!isUrp && myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer)
{
myScript.currentShaderType = (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.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) || myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit)
{
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++) ((AllIn1Shader)targets[i]).CreateAndAssignNormalMap();
AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Creating Normal Map");
}
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"))
{
bool successOperation = true;
for(int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader) targets[i]).ToggleSetAtlasUvs(true);
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Sprite Atlas Auto Setup");
}
if (GUILayout.Button("Remove Sprite Atlas Configuration"))
{
bool successOperation = true;
for(int i = 0; i < targets.Length; i++)
{
successOperation &= ((AllIn1Shader) targets[i]).ToggleSetAtlasUvs(false);
}
if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Remove Sprite Atlas Configuration");
}
#if LETAI_TRUESHADOW
if (myScript.GetComponent<LeTai.TrueShadow.TrueShadow>() && !myScript.GetComponent<TrueShadowCompatibility>())
{
EditorGUILayout.Space();
DrawLine(Color.grey, 1, 3);
if (GUILayout.Button("Add True Shadow Compatibility"))
{
myScript.gameObject.AddComponent<TrueShadowCompatibility>();
myScript.SetSceneDirty();
}
}
#endif
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);
((AllIn1Shader)targets[i]).SetSceneDirty();
}
AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Component Removed");
}
if (GUILayout.Button("REMOVE COMPONENT AND MATERIAL"))
{
for (int i = 0; i < targets.Length; i++)
{
((AllIn1Shader)targets[i]).CleanMaterial();
}
for (int i = targets.Length - 1; i >= 0; i--)
{
DestroyImmediate(targets[i] as AllIn1Shader);
}
AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Component And Material Removed");
}
}
private void ChooseAndDisplayAssetImage()
{
if(!EditorPrefs.HasKey("allIn1ImageConfig"))
{
EditorPrefs.SetInt("allIn1ImageConfig", (int) ImageType.ShowImage);
}
imageType = (ImageType) EditorPrefs.GetInt("allIn1ImageConfig");
switch(imageType)
{
case ImageType.ShowImage:
case ImageType.HideInComponent:
if(imageInspector == null) imageInspector = AllIn1ShaderWindow.GetInspectorImage();
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)
{
if(sr.sharedMaterial == null) return;
shaderName = sr.sharedMaterial.shader.name;
}
else
{
Graphic img = myScript.GetComponent<Graphic>();
if(img.material == null) return;
if (img != null) shaderName = img.material.shader.name;
}
shaderName = shaderName.Replace("AllIn1SpriteShader/", "");
if (shaderName.Equals("AllIn1SpriteShader")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.Default;
else if (shaderName.Equals("AllIn1SpriteShaderScaledTime")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.ScaledTime;
else if (shaderName.Equals("AllIn1SpriteShaderUiMask")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.MaskedUI;
else if (shaderName.Equals("AllIn1Urp2dRenderer")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.Urp2dRenderer;
else if(shaderName.Equals("AllIn1SpriteShaderLit")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.Lit;
else if(shaderName.Equals("AllIn1SpriteShaderSRPBatch")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.SRPBatcher;
}
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
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 78232fc1cf0e9c445a36b7bf7fc49fdb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs
uploadId: 857600
@@ -0,0 +1,850 @@
#if UNITY_EDITOR
using AllIn1SpriteShader;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;
namespace AllIn1SpriteShader
{
[CanEditMultipleObjects]
public class AllIn1SpriteShaderLitMaterialInspector : 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(172);
DrawProperty(1);
//DrawProperty(2);
DrawProperty(70);
currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("<size=12>Show Advanced Configuration</size>"), toggleButtonStyle);
if(currEnabledDrawers[advancedConfigDrawer])
{
EditorGUILayout.BeginVertical(propertiesStyle);
Culling();
DrawLine(Color.grey, 1, 3);
ZTest();
DrawLine(Color.grey, 1, 3);
ZWrite();
DrawLine(Color.grey, 1, 3);
Billboard("Billboard 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("Light Effect", bigLabelStyle);
GenericEffect("Normal Map", "NORMALMAP_ON", 189, 190);
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, extraProperties: new int[] { 173, 174 } );
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, 180 });
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");
}
DrawLine(Color.grey, 1, 3);
GUILayout.Label("UV Effects", bigLabelStyle);
currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show UV 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("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166);
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, extraProperties: new int[] { 177 } );
GenericEffect("Warp Distortion", "WARP_ON", 167, 169);
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("This doesn't make much sense in a lit shader", 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(175);
DrawProperty(20);
DrawProperty(21);
}
DrawLine(Color.grey, 1, 3);
bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON");
if(outlineDistort)
{
DrawProperty(22);
DrawProperty(176);
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);
DrawProperty(160);
DrawProperty(178);
DrawProperty(161);
DrawProperty(162);
DrawProperty(163);
for (int i = 170; i <= 171; 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)
{
AllIn1ShaderPropertyType shaderProperty = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty);
if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader);
if(shaderProperty == AllIn1ShaderPropertyType.Float || shaderProperty == AllIn1ShaderPropertyType.Range)
{
targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name);
}
else if(shaderProperty == AllIn1ShaderPropertyType.Vector)
{
targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name);
}
else if(shaderProperty == AllIn1ShaderPropertyType.Color)
{
targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name);
}
else if(shaderProperty == AllIn1ShaderPropertyType.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
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 58a451704eab27348bd5177152dc656f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs
uploadId: 857600
@@ -0,0 +1,884 @@
#if UNITY_EDITOR
using System.Linq;
using AllIn1SpriteShader;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;
namespace AllIn1SpriteShader
{
[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 bool IsSRPShader()
{
bool res = false;
if(targetMat != null)
{
res = targetMat.shader.name == "AllIn1SpriteShader/AllIn1SpriteShaderSRPBatch";
}
return res;
}
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];
bool isShaderSRP = IsSRPShader();
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);
if (isShaderSRP)
{
DrawProperty(172);
}
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("Billboard 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");
if (isShaderSRP)
{
GenericEffect("Fade", "FADE_ON", 7, 13, true, null, new int[] { 173, 174 });
}
else
{
GenericEffect("Fade", "FADE_ON", 7, 13, true);
}
Outline("Outline", "OUTBASE_ON", isShaderSRP);
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);
if(!isShaderSRP) GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 172 });
else GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 179 });
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", isShaderSRP);
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 UV 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("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166);
GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat");
GenericEffect("Zoom", "ZOOMUV_ON", 108, 108);
if (isShaderSRP)
{
GenericEffect("Distortion", "DISTORT_ON", 109, 112, true, null, new int[] { 177 });
}
else
{
GenericEffect("Distortion", "DISTORT_ON", 109, 112);
}
GenericEffect("Warp Distortion", "WARP_ON", 167, 169);
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 isSRPShader)
{
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);
if (isSRPShader)
{
DrawProperty(175);
}
}
DrawLine(Color.grey, 1, 3);
bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON");
if(outlineDistort)
{
DrawProperty(22);
DrawProperty(23);
DrawProperty(24);
DrawProperty(25);
if (isSRPShader)
{
DrawProperty(176);
}
}
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 isShaderSRP)
{
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);
for(int i = 170; i <= 171; i++) DrawProperty(i);
if (isShaderSRP)
{
DrawProperty(178);
}
}
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)
{
AllIn1ShaderPropertyType shaderProperty = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty);
if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader);
if(shaderProperty == AllIn1ShaderPropertyType.Float || shaderProperty == AllIn1ShaderPropertyType.Range)
{
targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name);
}
else if(shaderProperty == AllIn1ShaderPropertyType.Vector)
{
targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name);
}
else if(shaderProperty == AllIn1ShaderPropertyType.Color)
{
targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name);
}
else if(shaderProperty == AllIn1ShaderPropertyType.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
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f42211545c188ae41b1e35cc1ce38187
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs
uploadId: 857600
@@ -0,0 +1,764 @@
#if UNITY_EDITOR
using System.Linq;
using AllIn1SpriteShader;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;
namespace AllIn1SpriteShader
{
[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, 172 });
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("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166);
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("Warp Distortion", "WARP_ON", 167, 169);
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);
for(int i = 170; i <= 171; 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)
{
AllIn1ShaderPropertyType propertyType = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty);
if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader);
if(propertyType == AllIn1ShaderPropertyType.Float || propertyType == AllIn1ShaderPropertyType.Range)
{
targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name);
}
else if(propertyType == AllIn1ShaderPropertyType.Vector)
{
targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name);
}
else if(propertyType == AllIn1ShaderPropertyType.Color)
{
targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name);
}
else if(propertyType == AllIn1ShaderPropertyType.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
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: bcdb12210426bb34cb44a19ffb54132d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs
uploadId: 857600
@@ -0,0 +1,7 @@
namespace AllIn1SpriteShader
{
public static class Constants
{
public const string MAIN_ASSEMBLY_NAME = "AllIn1SpriteShaderAssembly.asmdef";
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: dd7850185e6f57c4596c42efd4dccc33
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs
uploadId: 857600
@@ -0,0 +1,77 @@
#if UNITY_EDITOR
using UnityEditor;
namespace AllIn1SpriteShader
{
public static class EditorUtils
{
public static string UnifyEOL(string text)
{
if(string.IsNullOrEmpty(text)) return text;
text = text.Replace("\r\n", "\n");
text = text.Replace("\r", "\n");
return text;
}
public static AllIn1ShaderPropertyType GetShaderTypeByMaterialProperty(MaterialProperty matProperty)
{
AllIn1ShaderPropertyType res;
#if UNITY_6000_2_OR_NEWER
switch (matProperty.propertyType)
{
case UnityEngine.Rendering.ShaderPropertyType.Color:
res = AllIn1ShaderPropertyType.Color;
break;
case UnityEngine.Rendering.ShaderPropertyType.Float:
res = AllIn1ShaderPropertyType.Float;
break;
case UnityEngine.Rendering.ShaderPropertyType.Int:
res = AllIn1ShaderPropertyType.Int;
break;
case UnityEngine.Rendering.ShaderPropertyType.Range:
res = AllIn1ShaderPropertyType.Range;
break;
case UnityEngine.Rendering.ShaderPropertyType.Texture:
res = AllIn1ShaderPropertyType.Texture;
break;
case UnityEngine.Rendering.ShaderPropertyType.Vector:
res = AllIn1ShaderPropertyType.Vector;
break;
default:
res = AllIn1ShaderPropertyType.Vector;
break;
}
#else
switch (matProperty.type)
{
case MaterialProperty.PropType.Color:
res = AllIn1ShaderPropertyType.Color;
break;
case MaterialProperty.PropType.Float:
res = AllIn1ShaderPropertyType.Float;
break;
case MaterialProperty.PropType.Int:
res = AllIn1ShaderPropertyType.Int;
break;
case MaterialProperty.PropType.Range:
res = AllIn1ShaderPropertyType.Range;
break;
case MaterialProperty.PropType.Texture:
res = AllIn1ShaderPropertyType.Texture;
break;
case MaterialProperty.PropType.Vector:
res = AllIn1ShaderPropertyType.Vector;
break;
default:
res = AllIn1ShaderPropertyType.Vector;
break;
}
#endif
return res;
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 44cca39610f3ac740aaa53036cfef5d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs
uploadId: 857600
@@ -0,0 +1,75 @@
//////////////////////////////////////////////////////
// Shader Packager
// Copyright (c) Jason Booth
//////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
#if UNITY_2019_3_OR_NEWER
// Installs custom defines for render pipelines (e.g., USING_HDRP) to enable conditional compilation
// across different pipelines. Unity doesn't provide these defines out of the box, so this helper
// simplifies cross-pipeline compatibility.
namespace AllIn1SpriteShader
{
public static class RenderPipelineChecker
{
private const string HDRP_PACKAGE = "HDRenderPipelineAsset";
private const string URP_PACKAGE = "UniversalRenderPipelineAsset";
public static bool IsHDRP
{
get; private set;
}
public static bool IsURP
{
get; private set;
}
public static bool IsStandardRP
{
get; private set;
}
public static void RefreshData()
{
IsHDRP = DoesTypeExist(HDRP_PACKAGE);
IsURP = DoesTypeExist(URP_PACKAGE);
if (!(IsHDRP || IsURP))
{
IsStandardRP = true;
}
}
public static bool DoesTypeExist(string className)
{
var foundType = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in GetTypesSafe(assembly)
where type.Name == className
select type).FirstOrDefault();
return foundType != null;
}
public static IEnumerable<Type> GetTypesSafe(System.Reflection.Assembly assembly)
{
Type[] types;
try
{
types = assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
types = e.Types;
}
return types.Where(x => x != null);
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 83ac30b66f3fe444189a98a9bb648c51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs
uploadId: 857600
@@ -0,0 +1,37 @@
using UnityEngine;
using UnityEngine.UI;
namespace AllIn1SpriteShader
{
public class RandomSeed : MonoBehaviour
{
private readonly int randomSeedProperty = Shader.PropertyToID("_RandomSeed");
private MaterialPropertyBlock propertyBlock;
//If you want to randomize UI Images, you'll need to create different materials since materials are always shared
//This can be done at runtime with scripting or manually in the editor
private void Start()
{
Renderer renderer = GetComponent<Renderer>();
if(renderer != null)
{
propertyBlock = new MaterialPropertyBlock();
propertyBlock.SetFloat(randomSeedProperty, Random.Range(0f, 100f));
renderer.SetPropertyBlock(propertyBlock);
}
else
{
Image image = GetComponent<Image>();
if (image != null)
{
if (image.material != null)
{
image.material.SetFloat(randomSeedProperty, Random.Range(0, 1000f));
}
else Debug.LogError("Missing Material on UI Image: " + gameObject.name);
}
else Debug.LogError("Missing Renderer or UI Image on: " + gameObject.name);
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6078fd4d3c5bd6f4087f8869458662dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs
uploadId: 857600
@@ -0,0 +1,179 @@
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AllIn1SpriteShader
{
[ExecuteInEditMode]
public class SetAtlasUvs : MonoBehaviour
{
[SerializeField] private bool updateEveryFrame = false;
[Tooltip("If using a Sprite Renderer it will use the material property instead of sharedMaterial"), SerializeField] private bool useMaterialInstanceIfPossible = false;
private Renderer render;
private SpriteRenderer spriteRender;
private Image uiImage;
private bool isUI = false;
private readonly int minXuv = Shader.PropertyToID("_MinXUV");
private readonly int maxXuv = Shader.PropertyToID("_MaxXUV");
private readonly int minYuv = Shader.PropertyToID("_MinYUV");
private readonly int maxYuv = Shader.PropertyToID("_MaxYUV");
private void Start()
{
Setup();
}
private void Reset()
{
Setup();
}
private void Setup()
{
if (GetRendererReferencesIfNeeded()) GetAndSetUVs();
if (!updateEveryFrame && Application.isPlaying && this != null) this.enabled = false;
}
private void LateUpdate()
{
if (updateEveryFrame)
{
GetAndSetUVs();
}
}
public bool GetAndSetUVs()
{
if (!GetRendererReferencesIfNeeded()) return false;
if (!isUI)
{
Sprite sprite = spriteRender.sprite;
Rect r = sprite.textureRect;
r.x /= sprite.texture.width;
r.width /= sprite.texture.width;
r.y /= sprite.texture.height;
r.height /= sprite.texture.height;
if(useMaterialInstanceIfPossible && Application.isPlaying)
{
render.material.SetFloat(minXuv, r.xMin);
render.material.SetFloat(maxXuv, r.xMax);
render.material.SetFloat(minYuv, r.yMin);
render.material.SetFloat(maxYuv, r.yMax);
}
else
{
render.sharedMaterial.SetFloat(minXuv, r.xMin);
render.sharedMaterial.SetFloat(maxXuv, r.xMax);
render.sharedMaterial.SetFloat(minYuv, r.yMin);
render.sharedMaterial.SetFloat(maxYuv, r.yMax);
}
}
else
{
Rect r = uiImage.sprite.textureRect;
r.x /= uiImage.sprite.texture.width;
r.width /= uiImage.sprite.texture.width;
r.y /= uiImage.sprite.texture.height;
r.height /= uiImage.sprite.texture.height;
uiImage.material.SetFloat(minXuv, r.xMin);
uiImage.material.SetFloat(maxXuv, r.xMax);
uiImage.material.SetFloat(minYuv, r.yMin);
uiImage.material.SetFloat(maxYuv, r.yMax);
}
return true;
}
public void ResetAtlasUvs()
{
if (!GetRendererReferencesIfNeeded()) return;
if (!isUI)
{
if(useMaterialInstanceIfPossible && Application.isPlaying)
{
render.material.SetFloat(minXuv, 0f);
render.material.SetFloat(maxXuv, 1f);
render.material.SetFloat(minYuv, 0f);
render.material.SetFloat(maxYuv, 1f);
}
else
{
render.sharedMaterial.SetFloat(minXuv, 0f);
render.sharedMaterial.SetFloat(maxXuv, 1f);
render.sharedMaterial.SetFloat(minYuv, 0f);
render.sharedMaterial.SetFloat(maxYuv, 1f);
}
}
else
{
uiImage.material.SetFloat(minXuv, 0f);
uiImage.material.SetFloat(maxXuv, 1f);
uiImage.material.SetFloat(minYuv, 0f);
uiImage.material.SetFloat(maxYuv, 1f);
}
}
public void UpdateEveryFrame(bool everyFrame)
{
updateEveryFrame = everyFrame;
}
private bool GetRendererReferencesIfNeeded()
{
if (spriteRender == null) spriteRender = GetComponent<SpriteRenderer>();
if (spriteRender != null)
{
if (spriteRender.sprite == null)
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("No sprite found", "The object: " + gameObject.name + ", has Sprite Renderer but no sprite", "Ok");
#endif
DestroyImmediate(this);
return false;
}
if (render == null) render = GetComponent<Renderer>();
isUI = false;
}
else
{
if (uiImage == null)
{
uiImage = GetComponent<Image>();
if (uiImage != null)
{
#if UNITY_EDITOR
Debug.Log("You added the SetAtlasUv component to: " + gameObject.name + " that has a UI Image\n " +
"This SetAtlasUV component will only work properly on UI Images if each Image has a DIFFERENT material instance (See Documentation Sprite Atlases section for more info)");
#endif
}
else
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("No Renderer or UI Graphic found", "This SetAtlasUV component will now get destroyed", "Ok");
#endif
DestroyImmediate(this);
return false;
}
}
if (render == null) render = GetComponent<Renderer>();
isUI = true;
}
if (spriteRender == null && uiImage == null)
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("No Renderer or UI Graphic found", "This SetAtlasUV component will now get destroyed", "Ok");
#endif
DestroyImmediate(this);
return false;
}
return true;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1625263d85e5d554284989eb9052e863
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs
uploadId: 857600
@@ -0,0 +1,24 @@
using UnityEngine;
namespace AllIn1SpriteShader
{
//This script is made with Unity version 2019 and onward in mind
//This script will pass in the Unscaled Time to the shader to animate the effects even when the game is paused
//Set shaders to Scaled Time variant and add this script to an active GameObject to see the results
//Video tutorial about it: https://youtu.be/7_BggIufV-w
[ExecuteInEditMode]
public class SetGlobalTime : MonoBehaviour
{
int globalTime;
private void Start()
{
globalTime = Shader.PropertyToID("globalUnscaledTime");
}
private void Update()
{
Shader.SetGlobalFloat(globalTime, Time.unscaledTime / 20f);
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c6c0770c7b77d3f45ab8c8d42b794c51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs
uploadId: 857600
@@ -0,0 +1,92 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace AllIn1SpriteShader
{
[ExecuteInEditMode]
[RequireComponent(typeof(SpriteRenderer))]
public class SpritePropertiesSync : MonoBehaviour
{
public enum CastShadowMode
{
[InspectorName("Off")] OFF,
[InspectorName("One Sided")] ONE_SIDED,
[InspectorName("Two Sided")] TWO_SIDED
}
private static int PROPID_SPRITE_FLIP = Shader.PropertyToID("_SpriteFlip");
public SpriteRenderer spr;
public bool isMaterialDrivenByAnimator;
[SerializeField] private CastShadowMode shadowCastingMode = CastShadowMode.TWO_SIDED;
private MaterialPropertyBlock matPropBlock;
public void Start()
{
if(spr == null) spr = GetComponent<SpriteRenderer>();
if(spr == null)
{
Debug.LogWarning($"Sprite Renderer is null in SpritePropertiesSync-{gameObject.name}", gameObject);
enabled = false;
return;
}
matPropBlock = new MaterialPropertyBlock();
UpdateRendererShadowCastingMode();
}
private void LateUpdate()
{
if(spr == null || spr.sharedMaterial == null)
{
Debug.LogError($"Incorrect setup in SpritePropertiesSync-{gameObject.name}", gameObject);
enabled = false;
return;
}
#if UNITY_EDITOR
if (matPropBlock == null) matPropBlock = new MaterialPropertyBlock();
UpdateRendererShadowCastingMode();
#endif
UpdateMaterial();
}
private void UpdateRendererShadowCastingMode()
{
switch (shadowCastingMode)
{
case CastShadowMode.OFF:
spr.shadowCastingMode = ShadowCastingMode.Off;
break;
case CastShadowMode.ONE_SIDED:
spr.shadowCastingMode = ShadowCastingMode.On;
break;
case CastShadowMode.TWO_SIDED:
spr.shadowCastingMode = ShadowCastingMode.TwoSided;
break;
}
}
private void UpdateMaterial()
{
spr.GetPropertyBlock(matPropBlock);
float flipX = spr.flipX ? -1f : 1f;
float flipY = spr.flipY ? -1f : 1f;
Vector3 localScale = spr.transform.localScale;
float scaleSign = Mathf.Sign(localScale.x * localScale.y * localScale.z * flipX * flipY);
Vector4 vecFlip = new Vector4(flipX, flipY, flipX, flipY);
if (Application.isPlaying && isMaterialDrivenByAnimator)
{
vecFlip.x = 1.0f;
vecFlip.y = 1.0f;
}
vecFlip.z = scaleSign;
matPropBlock.SetVector(PROPID_SPRITE_FLIP, vecFlip);
spr.SetPropertyBlock(matPropBlock);
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 38fbd5bf8eb2ab740896fa4bd7b94843
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs
uploadId: 857600
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30ea7cd4d865fef46b7a1ea7e98943a1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

@@ -0,0 +1,99 @@
fileFormatVersion: 2
guid: 917b41800d6604d4e99bef50da598d65
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 692da10dc1b5aa741a39ec794b64c334
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png
uploadId: 857600
@@ -0,0 +1,39 @@
#if LETAI_TRUESHADOW
using LeTai.TrueShadow;
using LeTai.TrueShadow.PluginInterfaces;
using UnityEngine;
namespace AllIn1SpriteShader
{
[ExecuteAlways]
public class TrueShadowCompatibility : MonoBehaviour, ITrueShadowCustomHashProvider
{
[Tooltip("Use with animated effects")]
public bool updateTrueShadowEveryFrame = false;
private TrueShadow shadow;
public void UpdateTrueShadow()
{
if (!shadow) shadow = GetComponent<TrueShadow>();
if (!shadow) return;
UpdateTrueShadow(shadow);
}
public static void UpdateTrueShadow(TrueShadow shadow)
{
shadow.CustomHash = Random.Range(int.MinValue, int.MaxValue);
}
public void Update()
{
bool shouldDirty = updateTrueShadowEveryFrame;
#if UNITY_EDITOR
shouldDirty |= !Application.isPlaying;
#endif
if (shouldDirty)
UpdateTrueShadow();
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 279c59909b723da49b1f2cf62d25b06a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 156513
packageName: All In 1 Sprite Shader
packageVersion: 4.661
assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs
uploadId: 857600