更新
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5278f5c70dd7cd840bf783501444121f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class DrawHelper
|
||||
{
|
||||
static readonly Color k_LineColorLight = new Color(0.8f, 0.8f, 0.8f, 1);
|
||||
static readonly Color k_LineColorDark = new Color(0.8f, 0.8f, 0.8f, 1) * 2.7f;
|
||||
|
||||
public static void DrawLine()
|
||||
{
|
||||
var previousColor = GUI.color;
|
||||
GUI.color = EditorGUIUtility.isProSkin ? k_LineColorDark : k_LineColorLight;
|
||||
GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true));
|
||||
GUI.color = previousColor;
|
||||
}
|
||||
|
||||
public static void DrawSeparator()
|
||||
{
|
||||
const int SpacePixelds = 3;
|
||||
GUILayout.Space(SpacePixelds);
|
||||
DrawHelper.DrawLine();
|
||||
GUILayout.Space(SpacePixelds);
|
||||
}
|
||||
|
||||
public static float DrawFloatRange(string displayName, float val, float min, float max)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var guiConent = GUIUtils.TempContent(displayName);
|
||||
GUILayout.Label(guiConent, GUILayout.ExpandWidth(false));
|
||||
val = GUILayout.HorizontalSlider(val, min, max, GUILayout.ExpandWidth(true));
|
||||
val = EditorGUILayout.FloatField(val, GUILayout.Width(40));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
return val;
|
||||
}
|
||||
|
||||
public static void DrawLeftRight(string label, ref float left, ref float right, float min = 0, float max = 1, float strict = 1)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
var guiConent = GUIUtils.TempContent(label);
|
||||
GUILayout.Label(guiConent, GUILayout.MinWidth(103.0f));
|
||||
|
||||
left = EditorGUILayout.FloatField(left);
|
||||
left = Mathf.Clamp(left, min, max);
|
||||
if (strict == 1)
|
||||
{
|
||||
if (left > right)
|
||||
left = right;
|
||||
}
|
||||
|
||||
right = EditorGUILayout.FloatField(right);
|
||||
right = Mathf.Clamp(right, min, max);
|
||||
if (strict == 1)
|
||||
{
|
||||
if (right < left)
|
||||
right = left;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.MinMaxSlider(ref left, ref right, min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc1323e2d8a88848ab9d9afe860380c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/Helpers/DrawHelper.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: debadf9c297ebce4f932e8f3bf874954
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class DrawerBase : MaterialPropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44bdec5ea5fc66045bba90e4b0ac2487
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/MaterialPropertyDrawers/DrawerBase.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 500e4264ac254614db0b04ab2f902f95
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal.Experimental
|
||||
{
|
||||
internal class IntEnum : MaterialPropertyDrawer
|
||||
{
|
||||
private readonly string[] m_Names;
|
||||
|
||||
public IntEnum(params string[] names)
|
||||
{
|
||||
m_Names = names;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
if (prop.propertyType != UnityEngine.Rendering.ShaderPropertyType.Float && prop.propertyType != UnityEngine.Rendering.ShaderPropertyType.Int)
|
||||
{
|
||||
EditorGUI.LabelField(position, label, "Use with Float or Int only.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Preserve previous mixed value state
|
||||
EditorGUI.showMixedValue = prop.hasMixedValue;
|
||||
|
||||
int currentValue = PropertyUtils.GetAsInt(prop);
|
||||
if (currentValue < 0 || currentValue >= m_Names.Length)
|
||||
currentValue = 0;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
int newValue = EditorGUI.Popup(position, label, currentValue, m_Names);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
// Apply to all selected materials
|
||||
PropertyUtils.SetAsInt(prop, newValue);
|
||||
}
|
||||
|
||||
// Reset mixed value state
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7680902a49d7ab74f89149a6ea7764c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/MaterialPropertyDrawers/Experimental/IntEnum.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,51 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class FloatRange : DrawerBase
|
||||
{
|
||||
float m_Min;
|
||||
float m_Max;
|
||||
|
||||
public FloatRange(float min, float max)
|
||||
{
|
||||
m_Min = min;
|
||||
m_Max = max;
|
||||
}
|
||||
|
||||
public FloatRange(string min, string max)
|
||||
{
|
||||
m_Min = AttributeUtils.ParseNumber(min);
|
||||
m_Max = AttributeUtils.ParseNumber(max);
|
||||
}
|
||||
|
||||
public FloatRange(float min, string max)
|
||||
{
|
||||
m_Min = min;
|
||||
m_Max = AttributeUtils.ParseNumber(max);
|
||||
}
|
||||
|
||||
public FloatRange(string min, float max)
|
||||
{
|
||||
m_Min = AttributeUtils.ParseNumber(min);
|
||||
m_Max = max;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
EditorGUI.showMixedValue = prop.hasMixedValue;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var value = DrawHelper.DrawFloatRange(prop.displayName, prop.floatValue, m_Min, m_Max);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
prop.floatValue = value;
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d95e281c1b08dc4cb19bccbebd4ebad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/MaterialPropertyDrawers/FloatRange.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,34 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class HelpBox : DrawerBase
|
||||
{
|
||||
private MessageType m_MessageType = MessageType.None;
|
||||
|
||||
public HelpBox()
|
||||
{
|
||||
}
|
||||
|
||||
public HelpBox(string messageType)
|
||||
{
|
||||
switch (messageType)
|
||||
{
|
||||
case "Info": m_MessageType = MessageType.Info; break;
|
||||
case "Warning": m_MessageType = MessageType.Warning; break;
|
||||
case "Error": m_MessageType = MessageType.Error; break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
var message = prop.displayName;
|
||||
EditorGUILayout.HelpBox(message, m_MessageType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc4496d4ab0501c4f8426d8900371a3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/MaterialPropertyDrawers/HelpBox.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,34 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class MiniTexture : DrawerBase
|
||||
{
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
var rect = EditorGUILayout.GetControlRect(true, 20f, EditorStyles.layerMaskField);
|
||||
editor.TexturePropertyMiniThumbnail(rect, prop, "", label);
|
||||
|
||||
rect.x += 31;
|
||||
var guiContent = GUIUtils.TempContent(prop.displayName);
|
||||
EditorGUI.LabelField(rect, guiContent);
|
||||
|
||||
var material = editor.target as Material;
|
||||
var shader = material.shader;
|
||||
var texturePropIndex = shader.FindPropertyIndex(prop.name);
|
||||
ShaderPropertyFlags shaderPropFlags = shader.GetPropertyFlags(texturePropIndex);
|
||||
if ((shaderPropFlags & ShaderPropertyFlags.NoScaleOffset) == 0)
|
||||
{
|
||||
// GUI.enabled = prop.textureValue != null;
|
||||
editor.TextureScaleOffsetProperty(prop);
|
||||
// GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bd506808f8f0924b8c38e6dbbde9176
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/MaterialPropertyDrawers/MiniTexture.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,162 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class MultiLineVector : DrawerBase
|
||||
{
|
||||
readonly string[] k_DefaultNames = new string[] { "- X", "- Y", "- Z", "- W" };
|
||||
|
||||
float m_Len;
|
||||
string[] m_Names = new string[] { "- X", "- Y", "- Z", "- W" };
|
||||
float[] m_Min = new float[] { short.MinValue, short.MinValue, short.MinValue, short.MinValue };
|
||||
float[] m_Max = new float[] { short.MaxValue, short.MaxValue, short.MaxValue, short.MaxValue };
|
||||
|
||||
public MultiLineVector(float len)
|
||||
{
|
||||
m_Len = (int)len;
|
||||
}
|
||||
|
||||
public MultiLineVector(float len, float min, float max)
|
||||
{
|
||||
m_Len = (int)len;
|
||||
m_Min = new float[4] { min, min, min, min };
|
||||
m_Max = new float[4] { max, max, max, max };
|
||||
}
|
||||
|
||||
public MultiLineVector(float len, string minStr, string maxStr)
|
||||
{
|
||||
var min = AttributeUtils.ParseNumber(minStr);
|
||||
var max = AttributeUtils.ParseNumber(maxStr);
|
||||
|
||||
m_Len = (int)len;
|
||||
m_Min = new float[4] { min, min, min, min };
|
||||
m_Max = new float[4] { max, max, max, max };
|
||||
}
|
||||
|
||||
public MultiLineVector(float len, params object[] args)
|
||||
{
|
||||
m_Len = (int)len;
|
||||
|
||||
for (int i = 0; i < args.Length && i < 4 * 3; i++)
|
||||
{
|
||||
var str = args[i].ToString();
|
||||
|
||||
int channel = i / 3;
|
||||
int slot = i % 3;
|
||||
|
||||
if (slot == 0)
|
||||
{
|
||||
m_Names[channel] = "- " + str;
|
||||
}
|
||||
else if (slot == 1)
|
||||
{
|
||||
str = str.Replace("n", "-").Replace("f", "");
|
||||
m_Min[channel] = Convert.ToSingle(str);
|
||||
}
|
||||
else if (slot == 2)
|
||||
{
|
||||
str = str.Replace("n", "-").Replace("f", "");
|
||||
m_Max[channel] = Convert.ToSingle(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
EditorGUI.LabelField(position, label);
|
||||
|
||||
var hasMixedValueX = false;
|
||||
var hasMixedValueY = false;
|
||||
var hasMixedValueZ = false;
|
||||
var hasMixedValueW = false;
|
||||
for (int i = 0, len = editor.targets.Length; i < len - 1; i++)
|
||||
{
|
||||
var mat1 = editor.targets[i] as Material;
|
||||
var mat2 = editor.targets[i + 1] as Material;
|
||||
|
||||
var value1 = mat1.GetVector(prop.name);
|
||||
var value2 = mat2.GetVector(prop.name);
|
||||
|
||||
if (value1.x != value2.x)
|
||||
hasMixedValueX = true;
|
||||
if (value1.y != value2.y)
|
||||
hasMixedValueY = true;
|
||||
if (value1.z != value2.z)
|
||||
hasMixedValueZ = true;
|
||||
if (value1.w != value2.w)
|
||||
hasMixedValueW = true;
|
||||
}
|
||||
|
||||
var propValue = prop.vectorValue;
|
||||
|
||||
var xChanged = false;
|
||||
if (m_Len >= 1)
|
||||
{
|
||||
EditorGUI.showMixedValue = hasMixedValueX;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
propValue.x = DrawHelper.DrawFloatRange(m_Names[0], propValue.x, m_Min[0], m_Max[0]);
|
||||
xChanged = EditorGUI.EndChangeCheck();
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
var yChanged = false;
|
||||
if (m_Len >= 2)
|
||||
{
|
||||
EditorGUI.showMixedValue = hasMixedValueY;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
propValue.y = DrawHelper.DrawFloatRange(m_Names[1], propValue.y, m_Min[1], m_Max[1]);
|
||||
yChanged = EditorGUI.EndChangeCheck();
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
var zChanged = false;
|
||||
if (m_Len >= 3)
|
||||
{
|
||||
EditorGUI.showMixedValue = hasMixedValueZ;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
propValue.z = DrawHelper.DrawFloatRange(m_Names[2], propValue.z, m_Min[2], m_Max[2]);
|
||||
zChanged = EditorGUI.EndChangeCheck();
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
var wChanged = false;
|
||||
if (m_Len >= 4)
|
||||
{
|
||||
EditorGUI.showMixedValue = hasMixedValueW;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
propValue.w = DrawHelper.DrawFloatRange(m_Names[3], propValue.w, m_Min[3], m_Max[3]);
|
||||
wChanged = EditorGUI.EndChangeCheck();
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
foreach (var target in prop.targets)
|
||||
{
|
||||
var mat = target as Material;
|
||||
|
||||
var newValue = mat.GetVector(prop.name);
|
||||
|
||||
if (xChanged)
|
||||
newValue.x = propValue.x;
|
||||
if (yChanged)
|
||||
newValue.y = propValue.y;
|
||||
if (zChanged)
|
||||
newValue.z = propValue.z;
|
||||
if (wChanged)
|
||||
newValue.w = propValue.w;
|
||||
|
||||
mat.SetVector(prop.name, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
return 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3880f234611f2f24ea6d64cde1f05156
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/MaterialPropertyDrawers/MultiLineVector.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9bc14476b237904788281408b74a23a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,137 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using GraphicsCat.MarkupShaderGUIInternal;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace GraphicsCat
|
||||
{
|
||||
public class MarkupShaderGUI : ShaderGUI
|
||||
{
|
||||
public class Context
|
||||
{
|
||||
public Shader shader;
|
||||
public MaterialEditor materialEditor;
|
||||
public Material[] materials;
|
||||
public MaterialProperty[] materialProperties;
|
||||
public MaterialProperty materialProperty;
|
||||
public string[] attributes;
|
||||
public string attribute;
|
||||
}
|
||||
|
||||
private Context m_Context = new();
|
||||
|
||||
private MarkupShaderGUIInternal.RenderSettings m_RenderSettingsTag = new();
|
||||
private Foldout m_FoldoutTag = new();
|
||||
private ShowIf m_ShowIfTag = new();
|
||||
private EnableIf m_EnableIfTag = new();
|
||||
private Separator m_SeparatorTag = new();
|
||||
private Label m_LabelTag = new();
|
||||
private MiniTextureWithColor m_MiniTextureWithColorTag = new();
|
||||
private LightmapEmissionFlags m_LightmapEmissionFlags = new();
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] materialProperties)
|
||||
{
|
||||
Material material = materialEditor.target as Material;
|
||||
if (material == null)
|
||||
return;
|
||||
|
||||
Shader shader = material.shader;
|
||||
if (shader == null)
|
||||
return;
|
||||
|
||||
m_Context.shader = shader;
|
||||
m_Context.materialEditor = materialEditor;
|
||||
m_Context.materials = materialEditor.targets.Cast<Material>().ToArray();
|
||||
m_Context.materialProperties = materialProperties;
|
||||
|
||||
GUILayout.Space(2f);
|
||||
|
||||
bool hasRenderSettings = false;
|
||||
for (int propIndex = 0; propIndex < materialProperties.Length; propIndex++)
|
||||
{
|
||||
m_Context.materialProperty = materialProperties[propIndex];
|
||||
m_Context.attributes = shader.GetPropertyAttributes(propIndex);
|
||||
foreach (var attribute in m_Context.attributes)
|
||||
{
|
||||
m_Context.attribute = attribute;
|
||||
|
||||
if (attribute.IndexOf("RenderSettings") != -1)
|
||||
{
|
||||
hasRenderSettings = true;
|
||||
m_RenderSettingsTag.InitNewMaterials(m_Context);
|
||||
}
|
||||
|
||||
m_FoldoutTag.Process(m_Context);
|
||||
m_ShowIfTag.Process(m_Context);
|
||||
m_EnableIfTag.Process(m_Context);
|
||||
m_MiniTextureWithColorTag.Process(m_Context);
|
||||
|
||||
var hideInFoldout = m_FoldoutTag.inScope && !m_FoldoutTag.state;
|
||||
var hideInShowIf = m_ShowIfTag.inScope && !m_ShowIfTag.state;
|
||||
if (hideInFoldout || hideInShowIf)
|
||||
continue;
|
||||
|
||||
if (m_EnableIfTag.inScope)
|
||||
GUI.enabled = m_EnableIfTag.state;
|
||||
|
||||
m_RenderSettingsTag.Process(m_Context);
|
||||
m_SeparatorTag.Process(m_Context);
|
||||
m_LabelTag.Process(m_Context);
|
||||
m_LightmapEmissionFlags.Process(m_Context);
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
if (m_RenderSettingsTag.inScope)
|
||||
continue;
|
||||
|
||||
if (m_FoldoutTag.inScope && !m_FoldoutTag.state)
|
||||
continue;
|
||||
|
||||
if (m_ShowIfTag.inScope && !m_ShowIfTag.state)
|
||||
continue;
|
||||
|
||||
ShaderPropertyFlags propFlags = shader.GetPropertyFlags(propIndex);
|
||||
if ((propFlags & ShaderPropertyFlags.HideInInspector) != 0)
|
||||
continue;
|
||||
|
||||
if (m_EnableIfTag.inScope)
|
||||
GUI.enabled = m_EnableIfTag.state;
|
||||
|
||||
if (m_MiniTextureWithColorTag.inScope && m_MiniTextureWithColorTag.state)
|
||||
{
|
||||
var isTextureType = (m_Context.materialProperty.propertyType == ShaderPropertyType.Texture);
|
||||
if (isTextureType)
|
||||
{
|
||||
if (propIndex < materialProperties.Length - 1)
|
||||
{
|
||||
var nextPropIndex = propIndex + 1;
|
||||
var nextProp = materialProperties[nextPropIndex];
|
||||
var nextPropIsColorType = (nextProp.propertyType == ShaderPropertyType.Color);
|
||||
if (nextPropIsColorType)
|
||||
m_MiniTextureWithColorTag.Draw(m_Context.materialProperty, materialEditor);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var guiContent = GUIUtils.TempContent(m_Context.materialProperty.displayName);
|
||||
materialEditor.ShaderProperty(m_Context.materialProperty, guiContent);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasRenderSettings == false)
|
||||
{
|
||||
materialEditor.RenderQueueField();
|
||||
materialEditor.DoubleSidedGIField();
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71217df46f6890e4e9d9bacc9db95f61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/MarkupShaderGUI.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c467d0d8f67c7c641af26f6a733d5cf7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76f71b519f97f9448b6fc9f2713feea6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class Tag
|
||||
{
|
||||
public bool inScope = false;
|
||||
public bool state = false;
|
||||
|
||||
protected virtual string m_beginTag => "BeginTag";
|
||||
protected virtual string m_EndTag => "EndTag";
|
||||
|
||||
public void Process(MarkupShaderGUI.Context context)
|
||||
{
|
||||
if (context.attribute.StartsWith(m_beginTag))
|
||||
{
|
||||
inScope = true;
|
||||
OnBegin(context);
|
||||
}
|
||||
|
||||
if (context.attribute.StartsWith(m_EndTag))
|
||||
{
|
||||
OnEnd();
|
||||
inScope = false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnBegin(MarkupShaderGUI.Context context) { }
|
||||
public virtual void OnEnd() { }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10c2a44e2e696714aac0ae41c83b30fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Common/Tag.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1269331ec4ce571438145f8f277b57e4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class ConditionalTag : Tag
|
||||
{
|
||||
override public void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
var args = AttributeUtils.ExtractArgs(context.attribute);
|
||||
if (args.Count < 3)
|
||||
return;
|
||||
|
||||
var comparePropName = args[0];
|
||||
var compareMode = args[1];
|
||||
var compareValue = Convert.ToSingle(args[2]);
|
||||
|
||||
var compareProp = context.materialProperties.FirstOrDefault(p => p.name == comparePropName);
|
||||
if (compareProp.hasMixedValue)
|
||||
{
|
||||
state = false;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (compareMode)
|
||||
{
|
||||
case "Less":
|
||||
if (compareProp.floatValue >= compareValue)
|
||||
state = false;
|
||||
break;
|
||||
case "Equal":
|
||||
if (compareProp.floatValue != compareValue)
|
||||
state = false;
|
||||
break;
|
||||
case "LessEqual":
|
||||
if (compareProp.floatValue > compareValue)
|
||||
state = false;
|
||||
break;
|
||||
case "Greater":
|
||||
if (compareProp.floatValue <= compareValue)
|
||||
state = false;
|
||||
break;
|
||||
case "NotEqual":
|
||||
if (compareProp.floatValue == compareValue)
|
||||
state = false;
|
||||
break;
|
||||
case "GreaterEqual":
|
||||
if (compareProp.floatValue < compareValue)
|
||||
state = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
override public void OnEnd()
|
||||
{
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ea8285fb70ac2b4fa2c9ee791e39aa9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Conditional/ConditionalTag.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,12 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class EnableIf : ConditionalTag
|
||||
{
|
||||
protected override string m_beginTag => "BeginEnableIf";
|
||||
protected override string m_EndTag => "EndEnableIf";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c871a475490c264fb301ca8d1d318bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Conditional/EnableIf.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,12 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class ShowIf : ConditionalTag
|
||||
{
|
||||
protected override string m_beginTag => "BeginShowIf";
|
||||
protected override string m_EndTag => "EndShowIf";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6443c4cdd419d446a2f9559b8786799
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Conditional/ShowIf.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78ed3e7b2186ff24c80859a0d0834e73
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class LightmapEmissionFlags : Tag
|
||||
{
|
||||
protected override string m_beginTag => "LightmapEmissionFlags";
|
||||
|
||||
public override void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
// Change the GI emission flag and fix it up with emissive as black if necessary.
|
||||
context.materialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel - 2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 628dc929ce4f0b24fb7626af865a7520
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Experimental/LightmapEmissionFlags.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,531 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class RenderSettings : Tag
|
||||
{
|
||||
protected override string m_beginTag => "BeginRenderSettings";
|
||||
protected override string m_EndTag => "EndRenderSettings";
|
||||
|
||||
enum SurfaceType { Opaque, Transparent }
|
||||
readonly string _SURFACE_TYPE_OPAQUE = "_SURFACE_TYPE_OPAQUE";
|
||||
readonly string _SURFACE_TYPE_TRANSPARENT = "_SURFACE_TYPE_TRANSPARENT";
|
||||
readonly string k_SurfaceTypeName = "_SURFACE_TYPE";
|
||||
readonly string[] k_SurfaceTypeOptions = System.Enum.GetNames(typeof(SurfaceType));
|
||||
readonly int[] k_SurfaceTypeValues = (int[])System.Enum.GetValues(typeof(SurfaceType));
|
||||
SurfaceType? m_SurfaceType;
|
||||
bool m_SurfaceTypeChanged;
|
||||
|
||||
readonly string _ALPHATEST_ON = "_ALPHATEST_ON";
|
||||
readonly string k_AlphaClippingName = "_AlphaClipping";
|
||||
bool? m_AlphaClipping;
|
||||
readonly string k_CutoffName = "_Cutoff";
|
||||
float? m_Cutoff;
|
||||
|
||||
readonly string k_PreserveSpecular = "_PreserveSpecular";
|
||||
bool? m_PreserveSpecular;
|
||||
|
||||
readonly string k_CullModeName = "_Cull";
|
||||
readonly string[] k_CullModeOptions = System.Enum.GetNames(typeof(CullMode));
|
||||
readonly int[] k_CullModeValues = (int[])System.Enum.GetValues(typeof(CullMode));
|
||||
CullMode? m_CullMode;
|
||||
|
||||
readonly string k_ZTestName = "_ZTest";
|
||||
readonly string[] k_ZTestOptions = System.Enum.GetNames(typeof(CompareFunction));
|
||||
int[] k_ZTestValues = (int[])System.Enum.GetValues(typeof(CompareFunction));
|
||||
CompareFunction? m_ZTest;
|
||||
|
||||
enum ZWriteControl { Auto, Off, On }
|
||||
readonly string k_ZWriteControlName = "_ZWriteControl";
|
||||
readonly string[] k_ZWriteControlOptions = System.Enum.GetNames(typeof(ZWriteControl));
|
||||
readonly int[] k_ZWriteControlValues = (int[])System.Enum.GetValues(typeof(ZWriteControl));
|
||||
readonly string k_ZWriteName = "_ZWrite";
|
||||
ZWriteControl? m_ZWriteControl;
|
||||
|
||||
enum BlendControl { Auto, Custom, Alpha, Premultiply, Additive, Multiply }
|
||||
readonly string k_BlendControlName = "_BlendControl";
|
||||
readonly string[] k_BlendControlOptions = System.Enum.GetNames(typeof(BlendControl));
|
||||
readonly int[] k_BlendControlValues = (int[])System.Enum.GetValues(typeof(BlendControl));
|
||||
BlendControl? m_BlendControl;
|
||||
|
||||
readonly string k_SrcBlendName = "_SrcBlend";
|
||||
readonly string k_DstBlendName = "_DstBlend";
|
||||
readonly string k_AlphaSrcBlendName = "_AlphaSrcBlend";
|
||||
readonly string k_AlphaDstBlendName = "_AlphaDstBlend";
|
||||
readonly string[] k_BlendFactorOptions = System.Enum.GetNames(typeof(BlendMode));
|
||||
readonly int[] k_BlendFactorValues = (int[])System.Enum.GetValues(typeof(BlendMode));
|
||||
BlendMode? m_SrcBlend, m_DstBlend, m_AlphaSrcBlend, m_AlphaDstBlend;
|
||||
|
||||
readonly string _RECEIVE_SHADOWS_OFF = "_RECEIVE_SHADOWS_OFF";
|
||||
readonly string k_CastShadowsName = "_CastShadows";
|
||||
readonly string k_ReceiveShadowsName = "_ReceiveShadows";
|
||||
bool? m_CastShadows;
|
||||
bool? m_ReceiveShadows;
|
||||
|
||||
enum QueueControl { Auto, Custom }
|
||||
readonly string k_QueueControlName = "_QueueControl";
|
||||
QueueControl? m_QueueControl;
|
||||
readonly string k_QueueOffsetName = "_QueueOffset";
|
||||
int? m_QueueOffset;
|
||||
|
||||
MarkupShaderGUI.Context m_Context;
|
||||
UnityEngine.Object[] m_Targets;
|
||||
bool m_PropChanged = false;
|
||||
|
||||
public void InitNewMaterials(MarkupShaderGUI.Context context)
|
||||
{
|
||||
m_Context = context;
|
||||
if (m_Context.materialEditor.targets != m_Targets)
|
||||
{
|
||||
m_Targets = m_Context.materialEditor.targets;
|
||||
CollectPropertyValues();
|
||||
UpdateMaterials();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
m_PropChanged = false;
|
||||
|
||||
DrawSurfaceType();
|
||||
DrawAlphaClipping();
|
||||
DrawPreserveSpecular();
|
||||
|
||||
DrawHelper.DrawSeparator();
|
||||
DrawCullMode();
|
||||
DrawZTest();
|
||||
DrawZWrite();
|
||||
DrawBlendMode();
|
||||
|
||||
DrawHelper.DrawSeparator();
|
||||
DrawShadows();
|
||||
|
||||
DrawHelper.DrawSeparator();
|
||||
DrawRenderQueue();
|
||||
|
||||
if (m_PropChanged)
|
||||
UpdateMaterials();
|
||||
|
||||
DrawHelper.DrawSeparator();
|
||||
context.materialEditor.EnableInstancingField();
|
||||
context.materialEditor.DoubleSidedGIField();
|
||||
}
|
||||
|
||||
void CollectPropertyValues()
|
||||
{
|
||||
m_SurfaceType = GetMixedEnum<SurfaceType>(k_SurfaceTypeName);
|
||||
m_AlphaClipping = GetMixedBool(k_AlphaClippingName);
|
||||
m_PreserveSpecular = GetMixedBool(k_PreserveSpecular);
|
||||
|
||||
m_Cutoff = GetMixedFloat(k_CutoffName);
|
||||
m_CullMode = GetMixedEnum<CullMode>(k_CullModeName);
|
||||
m_ZTest = GetMixedEnum<CompareFunction>(k_ZTestName);
|
||||
m_ZWriteControl = GetMixedEnum<ZWriteControl>(k_ZWriteControlName);
|
||||
m_BlendControl = GetMixedEnum<BlendControl>(k_BlendControlName);
|
||||
m_SrcBlend = GetMixedEnum<BlendMode>(k_SrcBlendName);
|
||||
m_DstBlend = GetMixedEnum<BlendMode>(k_DstBlendName);
|
||||
m_AlphaSrcBlend = GetMixedEnum<BlendMode>(k_AlphaSrcBlendName);
|
||||
m_AlphaDstBlend = GetMixedEnum<BlendMode>(k_AlphaDstBlendName);
|
||||
|
||||
m_CastShadows = GetMixedBool(k_CastShadowsName);
|
||||
m_ReceiveShadows = GetMixedBool(k_ReceiveShadowsName);
|
||||
|
||||
m_QueueControl = GetMixedEnum<QueueControl>(k_QueueControlName);
|
||||
m_QueueOffset = GetMixedInt(k_QueueOffsetName);
|
||||
}
|
||||
|
||||
void DrawSurfaceType()
|
||||
{
|
||||
DrawEnum("Surface Type", k_SurfaceTypeName, ref m_SurfaceType, SurfaceType.Opaque);
|
||||
}
|
||||
|
||||
void DrawAlphaClipping()
|
||||
{
|
||||
DrawToggle("Alpha Clipping", k_AlphaClippingName, ref m_AlphaClipping, false);
|
||||
|
||||
if (m_AlphaClipping.HasValue && m_AlphaClipping.Value)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
DrawFloatRange("Threshold", k_CutoffName, ref m_Cutoff, 0.5f, 0.0f, 1.0f);
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawPreserveSpecular()
|
||||
{
|
||||
DrawToggle("Preserve Specular", k_PreserveSpecular, ref m_PreserveSpecular, true);
|
||||
}
|
||||
|
||||
void DrawCullMode()
|
||||
{
|
||||
DrawEnum("Cull Mode", k_CullModeName, ref m_CullMode, CullMode.Back);
|
||||
}
|
||||
|
||||
void DrawZTest()
|
||||
{
|
||||
DrawEnum("Depth Test", k_ZTestName, ref m_ZTest, CompareFunction.LessEqual);
|
||||
}
|
||||
|
||||
void DrawZWrite()
|
||||
{
|
||||
DrawEnum("Depth Write", k_ZWriteControlName, ref m_ZWriteControl, ZWriteControl.Auto);
|
||||
}
|
||||
|
||||
void DrawBlendMode()
|
||||
{
|
||||
DrawEnum("Blend Control", k_BlendControlName, ref m_BlendControl, BlendControl.Auto);
|
||||
|
||||
EditorGUI.indentLevel += 1;
|
||||
|
||||
if (m_BlendControl.HasValue)
|
||||
{
|
||||
GUI.enabled = (m_BlendControl == BlendControl.Custom);
|
||||
DrawEnum("Src Blend", k_SrcBlendName, ref m_SrcBlend, BlendMode.One);
|
||||
DrawEnum("Dst Blend", k_DstBlendName, ref m_DstBlend, BlendMode.Zero);
|
||||
DrawEnum("Alpha Src Blend", k_AlphaSrcBlendName, ref m_AlphaSrcBlend, BlendMode.One);
|
||||
DrawEnum("Alpha Dst Blend", k_AlphaDstBlendName, ref m_AlphaDstBlend, BlendMode.Zero);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
void DrawShadows()
|
||||
{
|
||||
DrawToggle("Cast Shadows", k_CastShadowsName, ref m_CastShadows, true);
|
||||
DrawToggle("Receive Shadows", k_ReceiveShadowsName, ref m_ReceiveShadows, true);
|
||||
}
|
||||
|
||||
void DrawRenderQueue()
|
||||
{
|
||||
DrawEnum("Queue Control", k_QueueControlName, ref m_QueueControl, QueueControl.Auto);
|
||||
|
||||
if (m_QueueControl.HasValue)
|
||||
{
|
||||
GUI.enabled = (m_QueueControl.Value == QueueControl.Auto);
|
||||
DrawIntRange("Offset", k_QueueOffsetName, ref m_QueueOffset, 0, -50, 50);
|
||||
|
||||
GUI.enabled = (m_QueueControl.Value == QueueControl.Custom);
|
||||
m_Context.materialEditor.RenderQueueField();
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawIntRange(string displayName, string propName, ref int? propValue, int defaultValue, int min, int max)
|
||||
{
|
||||
EditorGUI.showMixedValue = !propValue.HasValue;
|
||||
|
||||
try
|
||||
{
|
||||
using (var _ = new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// EditorGUILayout.LabelField(displayName, GUILayout.ExpandWidth(false));
|
||||
// var newValue = EditorGUILayout.IntSlider(propValue ?? defaultValue, min, max, GUILayout.ExpandWidth(true));
|
||||
|
||||
GUILayout.Label(displayName, GUILayout.ExpandWidth(false));
|
||||
var newValue = (int)GUILayout.HorizontalSlider(propValue ?? defaultValue, min, max, GUILayout.ExpandWidth(true));
|
||||
newValue = IMGUIUtils.IntField(newValue);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_PropChanged = true;
|
||||
|
||||
propValue = newValue;
|
||||
foreach (var material in m_Context.materials)
|
||||
material.SetInt(propName, propValue.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawFloatRange(string displayName, string propName, ref float? propValue, float defaultValue, float min, float max)
|
||||
{
|
||||
EditorGUI.showMixedValue = !propValue.HasValue;
|
||||
|
||||
try
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newValue = EditorGUILayout.Slider(displayName, propValue ?? defaultValue, min, max);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_PropChanged = true;
|
||||
|
||||
propValue = newValue;
|
||||
foreach (var material in m_Context.materials)
|
||||
material.SetFloat(propName, propValue.Value);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawEnum<T>(string displayName, string propName, ref T? propValue, T defaultValue) where T : struct, System.Enum
|
||||
{
|
||||
EditorGUI.showMixedValue = !propValue.HasValue;
|
||||
|
||||
try
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newValue = (T)EditorGUILayout.EnumPopup(displayName, propValue ?? defaultValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_PropChanged = true;
|
||||
|
||||
propValue = newValue;
|
||||
var intValue = Convert.ToInt32(propValue.Value);
|
||||
foreach (var material in m_Context.materials)
|
||||
material.SetInt(propName, intValue);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawToggle(string displayName, string propName, ref bool? propValue, bool defaultValue)
|
||||
{
|
||||
EditorGUI.showMixedValue = !propValue.HasValue;
|
||||
|
||||
try
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newValue = EditorGUILayout.Toggle(displayName, propValue ?? defaultValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_PropChanged = true;
|
||||
|
||||
propValue = newValue;
|
||||
var intValue = propValue.Value ? 1 : 0;
|
||||
foreach (var material in m_Context.materials)
|
||||
material.SetInt(propName, intValue);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateMaterials()
|
||||
{
|
||||
UpdateRenderType();
|
||||
UpdateZWrite();
|
||||
UpdateBlendFactors();
|
||||
UpdateRenderQueue();
|
||||
UpdateShadows();
|
||||
}
|
||||
|
||||
void UpdateRenderType()
|
||||
{
|
||||
foreach (var material in m_Context.materials)
|
||||
{
|
||||
var surfaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
|
||||
var isOpaque = (surfaceType == SurfaceType.Opaque);
|
||||
var isTransparent = (surfaceType == SurfaceType.Transparent);
|
||||
|
||||
var isAlphaClipping = (material.GetInt(k_AlphaClippingName) == 1);
|
||||
|
||||
material.SetKeyword(_SURFACE_TYPE_OPAQUE, isOpaque);
|
||||
material.SetKeyword(_SURFACE_TYPE_TRANSPARENT, isTransparent);
|
||||
material.SetKeyword(_ALPHATEST_ON, isAlphaClipping);
|
||||
|
||||
if (isAlphaClipping) // alpha clipping first
|
||||
material.SetOverrideTag("RenderType", "TransparentCutout");
|
||||
else if (isTransparent)
|
||||
material.SetOverrideTag("RenderType", "Transparent");
|
||||
else
|
||||
material.SetOverrideTag("RenderType", ""); // Empty string resets the value
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateZWrite()
|
||||
{
|
||||
foreach (var material in m_Context.materials)
|
||||
{
|
||||
var zWriteMode = (ZWriteControl)material.GetInt(k_ZWriteControlName);
|
||||
|
||||
var oldZWrite = material.GetInt(k_ZWriteName);
|
||||
var newZWrite = 0;
|
||||
|
||||
switch (zWriteMode)
|
||||
{
|
||||
case ZWriteControl.Auto:
|
||||
var srufaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
|
||||
newZWrite = (srufaceType == SurfaceType.Transparent) ? 0 : 1;
|
||||
break;
|
||||
case ZWriteControl.Off: newZWrite = 0; break;
|
||||
case ZWriteControl.On: newZWrite = 1; break;
|
||||
}
|
||||
|
||||
if (oldZWrite != newZWrite)
|
||||
material.SetInt(k_ZWriteName, newZWrite);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateBlendFactors()
|
||||
{
|
||||
foreach (var material in m_Context.materials)
|
||||
{
|
||||
var blendingMode = (BlendControl)material.GetInt(k_BlendControlName);
|
||||
|
||||
var srcBlend = (BlendMode)material.GetInt(k_SrcBlendName);
|
||||
var dstBlend = (BlendMode)material.GetInt(k_DstBlendName);
|
||||
var alphaSrcBlend = (BlendMode)material.GetInt(k_AlphaSrcBlendName);
|
||||
var alphaDstBlend = (BlendMode)material.GetInt(k_AlphaDstBlendName);
|
||||
|
||||
var isAuto = (blendingMode == BlendControl.Auto);
|
||||
if (isAuto)
|
||||
{
|
||||
var surfaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
|
||||
if (surfaceType == SurfaceType.Opaque)
|
||||
{
|
||||
srcBlend = BlendMode.One;
|
||||
dstBlend = BlendMode.Zero;
|
||||
alphaSrcBlend = BlendMode.One;
|
||||
alphaDstBlend = BlendMode.Zero;
|
||||
}
|
||||
else if (surfaceType == SurfaceType.Transparent)
|
||||
{
|
||||
srcBlend = BlendMode.SrcAlpha;
|
||||
dstBlend = BlendMode.OneMinusSrcAlpha;
|
||||
alphaSrcBlend = BlendMode.One;
|
||||
alphaDstBlend = dstBlend;
|
||||
}
|
||||
}
|
||||
|
||||
var isAlpha = (blendingMode == BlendControl.Alpha);
|
||||
if (isAlpha)
|
||||
{
|
||||
srcBlend = BlendMode.SrcAlpha;
|
||||
dstBlend = BlendMode.OneMinusSrcAlpha;
|
||||
alphaSrcBlend = BlendMode.One;
|
||||
alphaDstBlend = dstBlend;
|
||||
}
|
||||
|
||||
var isPremultiply = (blendingMode == BlendControl.Premultiply);
|
||||
if (isPremultiply)
|
||||
{
|
||||
srcBlend = BlendMode.One;
|
||||
dstBlend = BlendMode.OneMinusSrcAlpha;
|
||||
alphaSrcBlend = srcBlend;
|
||||
alphaDstBlend = dstBlend;
|
||||
}
|
||||
|
||||
var isAdditive = (blendingMode == BlendControl.Additive);
|
||||
if (isAdditive)
|
||||
{
|
||||
srcBlend = BlendMode.SrcAlpha;
|
||||
dstBlend = BlendMode.One;
|
||||
alphaSrcBlend = BlendMode.One;
|
||||
alphaDstBlend = dstBlend;
|
||||
}
|
||||
|
||||
var isMultiply = (blendingMode == BlendControl.Multiply);
|
||||
if (isMultiply)
|
||||
{
|
||||
srcBlend = BlendMode.DstColor;
|
||||
dstBlend = BlendMode.Zero;
|
||||
alphaSrcBlend = BlendMode.Zero;
|
||||
alphaDstBlend = BlendMode.One;
|
||||
}
|
||||
|
||||
SetBlendingFactors(material, srcBlend, dstBlend, alphaSrcBlend, alphaDstBlend);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateShadows()
|
||||
{
|
||||
foreach (var material in m_Context.materials)
|
||||
{
|
||||
var castShadows = material.GetInt(k_CastShadowsName);
|
||||
material.SetShaderPassEnabled("ShadowCaster", (castShadows == 1));
|
||||
|
||||
var receiveShadows = material.GetInt(k_ReceiveShadowsName);
|
||||
material.SetKeyword(_RECEIVE_SHADOWS_OFF, (receiveShadows != 1));
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateRenderQueue()
|
||||
{
|
||||
foreach (var material in m_Context.materials)
|
||||
{
|
||||
var queueControl = (QueueControl)material.GetInt(k_QueueControlName);
|
||||
if (queueControl == QueueControl.Auto)
|
||||
{
|
||||
var surfaceType = (SurfaceType)material.GetInt(k_SurfaceTypeName);
|
||||
if (surfaceType == SurfaceType.Transparent)
|
||||
material.renderQueue = (int)RenderQueue.Transparent;
|
||||
else
|
||||
{
|
||||
var isAlphaClipping = (material.GetInt(k_AlphaClippingName) == 1);
|
||||
if (isAlphaClipping)
|
||||
material.renderQueue = (int)RenderQueue.AlphaTest;
|
||||
else
|
||||
material.renderQueue = (int)RenderQueue.Geometry;
|
||||
}
|
||||
|
||||
var queueOffset = material.GetInt(k_QueueOffsetName);
|
||||
material.renderQueue += queueOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetBlendingFactors(Material material, BlendMode colorSrc, BlendMode colorDst, BlendMode alphaSrc, BlendMode alphaDst)
|
||||
{
|
||||
material.SetInt("_SrcBlend", (int)colorSrc);
|
||||
material.SetInt("_DstBlend", (int)colorDst);
|
||||
material.SetInt("_AlphaSrcBlend", (int)alphaSrc);
|
||||
material.SetInt("_AlphaDstBlend", (int)alphaDst);
|
||||
}
|
||||
|
||||
T? GetMixedEnum<T>(string prop) where T : struct
|
||||
{
|
||||
var first = m_Context.materials[0].GetInt(prop);
|
||||
if (m_Context.materials.All(m => m.GetInt(prop) == first))
|
||||
return (T)(object)first;
|
||||
return null;
|
||||
}
|
||||
|
||||
bool? GetMixedBool(string prop)
|
||||
{
|
||||
var first = m_Context.materials[0].GetInt(prop);
|
||||
if (m_Context.materials.All(m => m.GetInt(prop) == first))
|
||||
return first == 1;
|
||||
return null;
|
||||
}
|
||||
|
||||
int? GetMixedInt(string prop)
|
||||
{
|
||||
var first = m_Context.materials[0].GetInt(prop);
|
||||
if (m_Context.materials.All(m => m.GetInt(prop) == first))
|
||||
return first;
|
||||
return null;
|
||||
}
|
||||
|
||||
float? GetMixedFloat(string prop)
|
||||
{
|
||||
var first = m_Context.materials[0].GetFloat(prop);
|
||||
if (m_Context.materials.All(m => m.GetFloat(prop) == first))
|
||||
return first;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2764b74759e7c81419d5a1913fad1ffd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Experimental/RenderSettings.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,112 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class Foldout : Tag
|
||||
{
|
||||
protected override string m_beginTag => "BeginFoldout";
|
||||
protected override string m_EndTag => "EndFoldout";
|
||||
|
||||
string m_FoldoutName = "";
|
||||
string m_FoldoutKey = "";
|
||||
|
||||
public override void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
m_FoldoutName = ExtractFoldoutName(context.attribute);
|
||||
|
||||
m_FoldoutKey = context.shader.name + m_FoldoutName;
|
||||
state = GetFoldoutState(m_FoldoutKey);
|
||||
|
||||
DrawFoldout(m_FoldoutKey, context);
|
||||
|
||||
if (state == true) // begin foldout space
|
||||
GUILayout.Space(4);
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (state == true) // end foldout space
|
||||
GUILayout.Space(6);
|
||||
else
|
||||
GUILayout.Space(2);
|
||||
|
||||
m_FoldoutName = "";
|
||||
m_FoldoutKey = "";
|
||||
state = true;
|
||||
}
|
||||
|
||||
void DrawFoldout(string foldoutKey, MarkupShaderGUI.Context context)
|
||||
{
|
||||
const float height = 21f;
|
||||
|
||||
Rect foldoutRect = GUILayoutUtility.GetRect(0, height, GUILayout.ExpandWidth(true));
|
||||
foldoutRect.xMin -= 29;
|
||||
|
||||
var style = new GUIStyle("ShurikenModuleTitle")
|
||||
{
|
||||
border = new RectOffset(15, 7, 4, 4),
|
||||
fixedHeight = height,
|
||||
contentOffset = new Vector2(19, -1), // text offset
|
||||
fontSize = 12 // Default is 10
|
||||
};
|
||||
|
||||
var foldoutTitle = m_FoldoutName;
|
||||
var prop = context.materialProperty;
|
||||
var enumName = AttributeUtils.GetKeywordEnumName(context.attributes, prop);
|
||||
if (string.IsNullOrEmpty(enumName) == false)
|
||||
{
|
||||
if (prop.hasMixedValue)
|
||||
foldoutTitle += " - *";
|
||||
else
|
||||
foldoutTitle += " - " + enumName;
|
||||
}
|
||||
|
||||
// Draw title
|
||||
GUI.Label(foldoutRect, foldoutTitle, style);
|
||||
|
||||
// Draw arrow
|
||||
var arrowRect = new Rect(foldoutRect.x + 4, foldoutRect.y + foldoutRect.height / 2 - 7, 14f, 14f);
|
||||
Event e = Event.current;
|
||||
if (e.type == EventType.Repaint)
|
||||
EditorStyles.foldout.Draw(arrowRect, false, false, GetFoldoutState(foldoutKey), false);
|
||||
|
||||
// Handle click to toggle foldout
|
||||
if (Event.current.type == EventType.MouseDown && foldoutRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
var previousState = GetFoldoutState(foldoutKey);
|
||||
SetFoldoutState(foldoutKey, !previousState);
|
||||
Event.current.Use();
|
||||
}
|
||||
}
|
||||
|
||||
string ExtractFoldoutName(string attribute)
|
||||
{
|
||||
var args = AttributeUtils.ExtractArgs(attribute);
|
||||
if (args.Count > 0)
|
||||
return args[0];
|
||||
return "";
|
||||
}
|
||||
|
||||
void SetFoldoutState(string foldoutKey, bool state)
|
||||
{
|
||||
var prefKey = GetPrefKey(foldoutKey);
|
||||
EditorPrefs.SetBool(prefKey, state);
|
||||
}
|
||||
|
||||
bool GetFoldoutState(string foldoutKey)
|
||||
{
|
||||
var prefKey = GetPrefKey(foldoutKey);
|
||||
return EditorPrefs.GetBool(prefKey, false);
|
||||
}
|
||||
|
||||
string GetPrefKey(string foldoutKey)
|
||||
{
|
||||
return $"{nameof(MarkupShaderGUIInternal)}.{foldoutKey}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afcebc20e9235a0418735b9896aa1981
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Foldout.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,69 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class Label : Tag
|
||||
{
|
||||
protected override string m_beginTag => "Label";
|
||||
|
||||
GUIStyle m_LabelStyle;
|
||||
|
||||
GUIStyle labelStyle => m_LabelStyle ??= new GUIStyle(EditorStyles.label);
|
||||
|
||||
public override void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
var args = AttributeUtils.ExtractArgs(context.attribute);
|
||||
var argsCount = args.Count;
|
||||
|
||||
var label = "";
|
||||
if (argsCount >= 1)
|
||||
label = args[0];
|
||||
var size = 10;
|
||||
if (args.Count >= 2)
|
||||
size = (int)AttributeUtils.ParseNumber(args[1]);
|
||||
|
||||
if (argsCount == 1)
|
||||
DrawLabel(label);
|
||||
else if (argsCount == 2)
|
||||
DrawLabel(label, size);
|
||||
else if (argsCount == 3)
|
||||
{
|
||||
var fontStyle = args[2];
|
||||
DrawLabel(label, size, fontStyle);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawLabel(string label)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label))
|
||||
return;
|
||||
|
||||
GUILayout.Label(label);
|
||||
}
|
||||
|
||||
void DrawLabel(string label, int size)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label))
|
||||
return;
|
||||
|
||||
labelStyle.fontSize = size;
|
||||
labelStyle.fontStyle = FontStyle.Normal;
|
||||
GUILayout.Label(label, labelStyle);
|
||||
}
|
||||
|
||||
void DrawLabel(string label, int size, string fontStyleStr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label))
|
||||
return;
|
||||
|
||||
labelStyle.fontSize = size;
|
||||
labelStyle.fontStyle = (FontStyle)System.Enum.Parse(typeof(FontStyle), fontStyleStr);
|
||||
GUILayout.Label(label, labelStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06a9c3b0f10cace4c815d6476783f718
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Label.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,73 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class MiniTextureWithColor : Tag
|
||||
{
|
||||
protected override string m_beginTag => "BeginMiniTextureWithColor";
|
||||
protected override string m_EndTag => "EndMiniTextureWithColor";
|
||||
|
||||
public override void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
state = true;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
state = false;
|
||||
}
|
||||
|
||||
public void Draw(MaterialProperty prop, MaterialEditor editor)
|
||||
{
|
||||
var material = editor.target as Material;
|
||||
var shader = material.shader;
|
||||
|
||||
var texPropIndex = shader.FindPropertyIndex(prop.name);
|
||||
var texPropDisplayName = prop.displayName;
|
||||
|
||||
// single line texture and color
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
var controlRect = EditorGUILayout.GetControlRect(true, 20f, EditorStyles.layerMaskField);
|
||||
editor.TexturePropertyMiniThumbnail(controlRect, prop, "", texPropDisplayName);
|
||||
|
||||
var displayNameRect = controlRect;
|
||||
displayNameRect.x += 31;
|
||||
var labelGUIConent = GUIUtils.TempContent(prop.displayName);
|
||||
EditorGUI.LabelField(displayNameRect, labelGUIConent);
|
||||
|
||||
var colorPropIndex = texPropIndex + 1;
|
||||
if (colorPropIndex < shader.GetPropertyCount())
|
||||
{
|
||||
if (shader.GetPropertyType(colorPropIndex) == ShaderPropertyType.Color)
|
||||
{
|
||||
var offset = Mathf.Max(controlRect.width * 0.425f, 122f);
|
||||
var colorRect = controlRect;
|
||||
colorRect.x += offset;
|
||||
colorRect.width -= offset;
|
||||
|
||||
string colorPropName = shader.GetPropertyName(colorPropIndex);
|
||||
var colorProp = MaterialEditor.GetMaterialProperty(editor.targets, colorPropName);
|
||||
editor.ColorProperty(colorRect, colorProp, GUIContent.none.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
// texture uv scale offset
|
||||
ShaderPropertyFlags shaderPropFlags = shader.GetPropertyFlags(texPropIndex);
|
||||
if ((shaderPropFlags & ShaderPropertyFlags.NoScaleOffset) == 0)
|
||||
{
|
||||
// GUI.enabled = prop.textureValue != null;
|
||||
editor.TextureScaleOffsetProperty(prop);
|
||||
// GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88a627b463d99794d8b0124021edaeab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/MiniTextureWithColor.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,16 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class Separator : Tag
|
||||
{
|
||||
protected override string m_beginTag => "Separator";
|
||||
|
||||
public override void OnBegin(MarkupShaderGUI.Context context)
|
||||
{
|
||||
DrawHelper.DrawSeparator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c1206d37c95cfe47afd03bff13e345d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/ShaderGUI/Tags/Separator.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7974fb3fe6b71fa4db5790eb9962010f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,120 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public static class AttributeUtils
|
||||
{
|
||||
public static List<string> ExtractArgs(string input)
|
||||
{
|
||||
int start = input.IndexOf('(');
|
||||
int end = input.LastIndexOf(')');
|
||||
|
||||
if (start < 0 || end < 0 || end <= start)
|
||||
return new List<string>();
|
||||
|
||||
string inside = input.Substring(start + 1, end - start - 1);
|
||||
var parts = inside.Split(',');
|
||||
var result = new List<string>();
|
||||
foreach (var part in parts)
|
||||
{
|
||||
string trimmed = part.Trim();
|
||||
if (!string.IsNullOrEmpty(trimmed))
|
||||
result.Add(trimmed);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float ParseNumber(string val)
|
||||
{
|
||||
val = val.Replace("n", "-").Replace("f", "");
|
||||
return Convert.ToSingle(val);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse Enum attribute strings and return the current enum name.
|
||||
/// Supports MaterialProperty of type Float and Int.
|
||||
/// </summary>
|
||||
public static string GetEnumName(string[] attributes, MaterialProperty prop)
|
||||
{
|
||||
if (attributes == null || attributes.Length == 0 || prop == null)
|
||||
return string.Empty;
|
||||
|
||||
int propValue = PropertyUtils.GetAsInt(prop);
|
||||
|
||||
foreach (var attr in attributes)
|
||||
{
|
||||
if (attr.StartsWith("Enum(", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string content = attr.Substring(5, attr.Length - 6).Trim();
|
||||
|
||||
// Case 1: real enum type
|
||||
Type enumType = Type.GetType(content);
|
||||
if (enumType != null && enumType.IsEnum)
|
||||
{
|
||||
string[] names = System.Enum.GetNames(enumType);
|
||||
if (propValue >= 0 && propValue < names.Length)
|
||||
return names[propValue];
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// Case 2: manual pairs (Name,Value,...)
|
||||
string[] tokens = content.Split(',');
|
||||
if (tokens.Length % 2 == 0)
|
||||
{
|
||||
Dictionary<int, string> map = new Dictionary<int, string>();
|
||||
for (int i = 0; i < tokens.Length; i += 2)
|
||||
{
|
||||
string name = tokens[i].Trim();
|
||||
if (int.TryParse(tokens[i + 1], out int val))
|
||||
{
|
||||
map[val] = name;
|
||||
}
|
||||
}
|
||||
|
||||
if (map.TryGetValue(propValue, out string found))
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse KeywordEnum attribute strings and return the current enum name.
|
||||
/// Supports MaterialProperty of type Float and Int.
|
||||
/// </summary>
|
||||
public static string GetKeywordEnumName(string[] attributes, MaterialProperty prop)
|
||||
{
|
||||
if (attributes == null || attributes.Length == 0 || prop == null)
|
||||
return string.Empty;
|
||||
|
||||
int propValue = PropertyUtils.GetAsInt(prop);
|
||||
|
||||
foreach (var attr in attributes)
|
||||
{
|
||||
if (attr.StartsWith("KeywordEnum(", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string content = attr.Substring(12, attr.Length - 13).Trim();
|
||||
string[] tokens = content.Split(',');
|
||||
|
||||
List<string> names = new List<string>();
|
||||
for (int i = 0; i < tokens.Length; i++)
|
||||
names.Add(tokens[i].Trim());
|
||||
|
||||
if (propValue >= 0 && propValue < names.Count)
|
||||
return names[propValue];
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb577be7aa42fd74cb6a24303cad46f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/Utils/AttributeUtils.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,42 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public class GUIUtils
|
||||
{
|
||||
static GUIContent s_TempContent = new GUIContent();
|
||||
|
||||
public static GUIContent TempContent(string displayName)
|
||||
{
|
||||
var guiContent = s_TempContent;
|
||||
if (string.IsNullOrEmpty(displayName))
|
||||
{
|
||||
guiContent.text = "";
|
||||
guiContent.tooltip = "";
|
||||
return guiContent;
|
||||
}
|
||||
|
||||
int start = displayName.IndexOf('[');
|
||||
int end = displayName.IndexOf(']');
|
||||
|
||||
if (start >= 0 && end > start)
|
||||
{
|
||||
// Text is everything before '['
|
||||
guiContent.text = displayName.Substring(0, start).Trim();
|
||||
// Tooltip is inside [ ... ]
|
||||
guiContent.tooltip = displayName.Substring(start + 1, end - start - 1).Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
// No brackets found ¡ú whole string is just text
|
||||
guiContent.text = displayName.Trim();
|
||||
}
|
||||
|
||||
return guiContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7885dc239873aa748b34af0269f80cf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/Utils/GUIUtils.cs
|
||||
uploadId: 820558
|
||||
@@ -0,0 +1,38 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GraphicsCat.MarkupShaderGUIInternal
|
||||
{
|
||||
public static class PropertyUtils
|
||||
{
|
||||
public static int GetAsInt(MaterialProperty prop)
|
||||
{
|
||||
return prop.propertyType switch
|
||||
{
|
||||
UnityEngine.Rendering.ShaderPropertyType.Int => prop.intValue,
|
||||
UnityEngine.Rendering.ShaderPropertyType.Float => Mathf.RoundToInt(prop.floatValue),
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
public static void SetAsInt(MaterialProperty prop, int value)
|
||||
{
|
||||
switch (prop.propertyType)
|
||||
{
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Int:
|
||||
prop.intValue = value;
|
||||
break;
|
||||
case UnityEngine.Rendering.ShaderPropertyType.Float:
|
||||
prop.floatValue = value;
|
||||
break;
|
||||
default:
|
||||
// Unsupported type, do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba7e97c155e45f2479fcd7faf8b6266c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 328765
|
||||
packageName: LitPlus - URP Enhanced Lit Shader
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/GraphicsCat/Modules/MarkupShaderGUI/Editor/Utils/PropertyUtils.cs
|
||||
uploadId: 820558
|
||||
Reference in New Issue
Block a user