diff --git a/Editor/DrawerUtility.cs b/Editor/DrawerUtility.cs index 7383066..e7cb996 100644 --- a/Editor/DrawerUtility.cs +++ b/Editor/DrawerUtility.cs @@ -1,13 +1,12 @@ +// Copyright (c) 2022 Jason Ma using System; using System.IO; -using System.Collections; using System.Collections.Generic; -using System.Globalization; -using System.Linq; using UnityEditor; using UnityEngine; using UnityEngine.Events; +using UnityEngine.Rendering; // Obsolete namespace JTRP.ShaderDrawer @@ -38,17 +37,69 @@ public class LWGUI : ShaderGUI { // Used for access to all props in Drawer public MaterialProperty[] props; - public MaterialEditor materialEditor; - + public MaterialEditor materialEditor; + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { this.props = props; this.materialEditor = materialEditor; + RevertableHelper.defaultMaterial = new Material((materialEditor.target as Material).shader); - base.OnGUI(materialEditor, props); + // base.OnGUI(materialEditor, props); + { + // move fields left to make rect for Revert Button + materialEditor.SetDefaultGUIWidths(); + EditorGUIUtility.fieldWidth += RevertableHelper.revertButtonWidth; + EditorGUIUtility.labelWidth -= RevertableHelper.revertButtonWidth; + RevertableHelper.fieldWidth = EditorGUIUtility.fieldWidth; + RevertableHelper.labelWidth = EditorGUIUtility.labelWidth; + + for (int index = 0; index < props.Length; ++index) + { + var prop = props[index]; + if ((prop.flags & MaterialProperty.PropFlags.HideInInspector) == 0) + { + var height = materialEditor.GetPropertyHeight(prop, prop.displayName); + // ignored when in Folding Group + if (height <= 0) continue; + + var rect = EditorGUILayout.GetControlRect(true, height, EditorStyles.layerMaskField); + var revertButtonRect = RevertableHelper.GetRevertButtonRect(prop, rect); + rect.xMax -= RevertableHelper.revertButtonWidth; + + // Process some builtin types display misplaced + switch (prop.type) + { + case MaterialProperty.PropType.Texture: + case MaterialProperty.PropType.Range: + materialEditor.SetDefaultGUIWidths(); + break; + default: + EditorGUIUtility.fieldWidth = RevertableHelper.fieldWidth; + EditorGUIUtility.labelWidth = RevertableHelper.labelWidth; + break; + } + + RevertableHelper.RevertButton(revertButtonRect, prop, materialEditor); + materialEditor.ShaderProperty(rect, prop, prop.displayName); + } + } + materialEditor.SetDefaultGUIWidths(); + + EditorGUILayout.Space(); + EditorGUILayout.Space(); +#if UNITY_2019_1_OR_NEWER + if (SupportedRenderingFeatures.active.editableMaterialRenderQueue) +#endif + { + materialEditor.RenderQueueField(); + } + materialEditor.EnableInstancingField(); + materialEditor.DoubleSidedGIField(); + } } - - public static MaterialProperty FindProp(string propertyName, MaterialProperty[] properties, bool propertyIsMandatory = false) + + public static MaterialProperty FindProp(string propertyName, MaterialProperty[] properties, bool propertyIsMandatory = false) { if (properties == null) { @@ -60,6 +111,187 @@ public static MaterialProperty FindProp(string propertyName, MaterialProperty[] } } + /// + /// Helpers for drawing Unreal Style Revertable Shader GUI + /// + public class RevertableHelper + { + public static readonly float revertButtonWidth = 15f; + public static float fieldWidth; + public static float labelWidth; + public static Material defaultMaterial; + + public static Rect GetRevertButtonRect(MaterialProperty prop, Rect rect, bool isCallInDrawer = false) + { + float defaultHeightWithoutDrawers; + switch (prop.type) + { + case MaterialProperty.PropType.Vector: + defaultHeightWithoutDrawers = 18f; + break; + default: + defaultHeightWithoutDrawers = MaterialEditor.GetDefaultPropertyHeight(prop); + break; + } + if (isCallInDrawer) rect.xMax += revertButtonWidth; + var revertButtonRect = new Rect(rect.xMax - revertButtonWidth + 2f, rect.yMax - defaultHeightWithoutDrawers * 0.5f - (revertButtonWidth - 3f) * 0.5f - + #if UNITY_2019_1_OR_NEWER + 1f, + #else + 2f, + #endif + revertButtonWidth - 2f, revertButtonWidth - 3f); + return revertButtonRect; + } + + public static void SetPropertyToDefault(MaterialProperty prop) + { + switch (prop.type) + { + case MaterialProperty.PropType.Color: + prop.colorValue = defaultMaterial.GetColor(prop.name); + break; + case MaterialProperty.PropType.Vector: + prop.vectorValue = defaultMaterial.GetVector(prop.name); + break; + case MaterialProperty.PropType.Float: + case MaterialProperty.PropType.Range: + prop.floatValue = defaultMaterial.GetFloat(prop.name); + break; + case MaterialProperty.PropType.Texture: + prop.textureValue = defaultMaterial.GetTexture(prop.name); + break; +#if UNITY_2021_1_OR_NEWER + case MaterialProperty.PropType.Int: + prop.intValue = defaultMaterial.GetInt(prop.name); + break; +#endif + } + } + + + // ======================= Draw revert button ======================= + public static bool RevertButton(Rect position, MaterialProperty prop, MaterialEditor materialEditor) + { + bool doRevert = false; + Rect rect = position; + switch (prop.type) + { + case MaterialProperty.PropType.Color: + var color = defaultMaterial.GetColor(prop.name); + if (color == prop.colorValue && !prop.hasMixedValue) + break; + if (DoRevertButton(rect)) + { + AddProperty(prop.targets, prop.name); + prop.colorValue = color; + doRevert = true; + } + break; + + case MaterialProperty.PropType.Vector: + var vector = defaultMaterial.GetVector(prop.name); + if (vector == prop.vectorValue && !prop.hasMixedValue) + break; + if (DoRevertButton(rect)) + { + AddProperty(prop.targets, prop.name); + prop.vectorValue = vector; + doRevert = true; + } + break; + + case MaterialProperty.PropType.Range: + case MaterialProperty.PropType.Float: + var value = defaultMaterial.GetFloat(prop.name); + if (value == prop.floatValue && !prop.hasMixedValue) + break; + if (DoRevertButton(rect)) + { + AddProperty(prop.targets, prop.name); + prop.floatValue = value; + doRevert = true; + // refresh keywords + MaterialEditor.ApplyMaterialPropertyDrawers(materialEditor.targets); + } + break; + + case MaterialProperty.PropType.Texture: + // var tex = defaultMaterial.GetTexture(prop.name); + // if (tex == prop.textureValue && !prop.hasMixedValue) + // break; + // if (DoRevertButton(rect)) + // { + // AddProperty(prop.targets, prop.name); + // prop.textureValue = tex; + // } + break; + } + return doRevert; + } + + private static readonly Texture _icon = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("e7bc1130858d984488bca32b8512ca96")); + private static bool DoRevertButton(Rect rect) + { + if (_icon == null) Debug.LogError("RevertIcon.png + meta is missing!"); + GUI.DrawTexture(rect, _icon); + var e = Event.current; + if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition)) + { + e.Use(); + return true; + } + return false; + } + + // ========== Call drawers to do revert and refresh keywords ========== + private static Dictionary> _needRevertPropsPool; + + public static void AddProperty(UnityEngine.Object[] materials, string propName) + { + if (_needRevertPropsPool == null) + _needRevertPropsPool = new Dictionary>(); + foreach (var material in materials) + { + if (_needRevertPropsPool.ContainsKey(material)) + { + if (!_needRevertPropsPool[material].Contains(propName)) + _needRevertPropsPool[material].Add(propName); + } + else + { + _needRevertPropsPool.Add(material, new List { propName }); + } + } + } + + public static void RemoveProperty(UnityEngine.Object[] materials, string propName) + { + if (_needRevertPropsPool == null) return; + foreach (var material in materials) + { + if (_needRevertPropsPool.ContainsKey(material)) + { + if (_needRevertPropsPool[material].Contains(propName)) + _needRevertPropsPool[material].Remove(propName); + } + } + } + + public static bool ContainsProperty(UnityEngine.Object material, string propName) + { + if (_needRevertPropsPool == null) return false; + if (_needRevertPropsPool.ContainsKey(material)) + { + return _needRevertPropsPool[material].Contains(propName); + } + else + { + return false; + } + } + } + /// /// Misc Function /// @@ -117,24 +349,9 @@ public static void SetShaderKeyWord(UnityEngine.Object[] materials, string[] key for (int i = 0; i < keyWords.Length; i++) { SetShaderKeyWord(materials, keyWords[i], index == i); - if (GUIData.keyWord.ContainsKey(keyWords[i])) - { - GUIData.keyWord[keyWords[i]] = index == i; - } - else - { - Debug.LogError("KeyWord: "+keyWords[i]+" not exist! Throw a shader error to refresh the instance."); - } } } - //public static float GetDefaultFloatValue(MaterialProperty prop) - //{ - // var shader = ((Material)prop.targets[0]).shader; - // var propIndex = shader.FindPropertyIndex(prop.name); - // return propIndex >= 0 ? shader.GetPropertyDefaultFloatValue(propIndex) : 0; - //} - public static void TurnColorDraw(Color useColor, UnityAction action) { var c = GUI.color; @@ -262,7 +479,7 @@ public static bool Foldout(Rect position, ref bool isFolding, bool toggleValue, style.fontSize = (int)(style.fontSize * 1.5f); style.contentOffset = new Vector2(30f, -2f); - var rect = GUILayoutUtility.GetRect(position.width, 24f, style); + var rect = position;//GUILayoutUtility.GetRect(position.width, 24f, style); GUI.backgroundColor = isFolding ? Color.white : new Color(0.85f, 0.85f, 0.85f); GUI.Box(rect, title, style); @@ -310,21 +527,23 @@ public static void PowerSlider(MaterialProperty prop, float power, Rect position var labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; - Rect position2 = EditorGUI.PrefixLabel(position, label); - position2 = new Rect(position2.x, position2.y, position2.width - EditorGUIUtility.fieldWidth - 5, position2.height); - - if (position2.width >= 50f) - value = GUI.Slider(position2, value, 0.0f, start, end, GUI.skin.horizontalSlider, !EditorGUI.showMixedValue ? GUI.skin.horizontalSliderThumb : (GUIStyle)"SliderMixed", true, controlId); + var rectAfterLabel = EditorGUI.PrefixLabel(position, label); + + Rect sliderRect = MaterialEditor.GetFlexibleRectBetweenLabelAndField(position); + if (sliderRect.width >= 50f) + value = GUI.Slider(sliderRect, value, 0.0f, start, end, GUI.skin.horizontalSlider, !EditorGUI.showMixedValue ? GUI.skin.horizontalSliderThumb : (GUIStyle)"SliderMixed", true, controlId); if ((double)power != 1.0) value = Helper.PowPreserveSign(value, power); - position.xMin += position.width - SubDrawer.propRight; - value = EditorGUI.FloatField(position, value); + position.xMin = Mathf.Max(rectAfterLabel.xMin, sliderRect.xMax - 10f); + var floatRect = position; + value = EditorGUI.FloatField(floatRect, value); - EditorGUIUtility.labelWidth = labelWidth; if (value != originValue) prop.floatValue = Mathf.Clamp(value, Mathf.Min(left, right), Mathf.Max(left, right)); + + EditorGUIUtility.labelWidth = labelWidth; } #endregion } @@ -476,7 +695,7 @@ public static void SetGradientToTexture(Texture texture, GradientObject gradient { var systemPath = projectPath + path; File.WriteAllBytes(systemPath, texture2D.EncodeToPNG()); - // assetImporter.SaveAndReimport(); + assetImporter.SaveAndReimport(); } } @@ -560,137 +779,5 @@ private static Color[] GetPixelsFromGradient(Gradient gradient, int width, int h } - /// - /// Helpers for drawing Unreal Style Revertable Shader GUI - /// - public class RevertableHelper - { - // ======================= Draw revert button ======================= - private static Texture _icon; - - public static void DrawRevertButton(Rect position, MaterialProperty prop, Material defaultMaterial) - { - // ignore drawer height - position.yMin += position.height - MaterialEditor.GetDefaultPropertyHeight(prop); - Rect rect = new Rect(); - var w = EditorGUIUtility.labelWidth; - switch (prop.type) - { - case MaterialProperty.PropType.Color: - var c = defaultMaterial.GetColor(prop.name); - if (c == prop.colorValue && !prop.hasMixedValue) - break; - rect = MaterialEditor.GetRectAfterLabelWidth(position); - GetButtonRect(ref rect); - if (DrawRevertButtonAtRect(rect)) - prop.colorValue = c; - break; - - case MaterialProperty.PropType.Vector: - EditorGUIUtility.labelWidth = 0; - var v = defaultMaterial.GetVector(prop.name); - if (v == prop.vectorValue && !prop.hasMixedValue) - break; - rect = MaterialEditor.GetRectAfterLabelWidth(position); - GetButtonRect(ref rect); - if (DrawRevertButtonAtRect(rect)) - prop.vectorValue = v; - break; - - case MaterialProperty.PropType.Range: - case MaterialProperty.PropType.Float: - if (prop.type == MaterialProperty.PropType.Range) - EditorGUIUtility.labelWidth = 0; - var f = defaultMaterial.GetFloat(prop.name); - if (f == prop.floatValue && !prop.hasMixedValue) - break; - rect = MaterialEditor.GetRectAfterLabelWidth(position); - GetButtonRect(ref rect); - if (DrawRevertButtonAtRect(rect)) - { - if (prop.type == MaterialProperty.PropType.Float) - AddProperty(prop.targets, prop.name); - prop.floatValue = f; - } - break; - - case MaterialProperty.PropType.Texture: - break; - } - EditorGUIUtility.labelWidth = w; - } - - public static bool DrawRevertButtonAtRect(Rect rect) - { - if (_icon == null) - _icon = EditorGUIUtility.IconContent("refresh").image; - - GUI.DrawTexture(rect, _icon); - var e = Event.current; - if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition)) - { - e.Use(); - - return true; - } - return false; - } - - private static void GetButtonRect(ref Rect rect) - { - rect.xMin -= 20f; - rect.width = 15f; - rect.yMin += 2f; - rect.height = 14f; - } - - - // ========== Make the drawer know when to refresh the keyword ========== - private static Dictionary> _revertablePropPool; - - public static void AddProperty(UnityEngine.Object[] materials, string propName) - { - if (_revertablePropPool == null) - _revertablePropPool = new Dictionary>(); - foreach (var material in materials) - { - if (_revertablePropPool.ContainsKey(material)) - { - if (!_revertablePropPool[material].Contains(propName)) - _revertablePropPool[material].Add(propName); - } - else - { - _revertablePropPool.Add(material, new List { propName }); - } - } - } - - public static void RemoveProperty(UnityEngine.Object[] materials, string propName) - { - if (_revertablePropPool == null) return; - foreach (var material in materials) - { - if (_revertablePropPool.ContainsKey(material)) - { - if (_revertablePropPool[material].Contains(propName)) - _revertablePropPool[material].Remove(propName); - } - } - } - - public static bool ContainsProperty(UnityEngine.Object material, string propName) - { - if (_revertablePropPool == null) return false; - if (_revertablePropPool.ContainsKey(material)) - { - return _revertablePropPool[material].Contains(propName); - } - else - { - return false; - } - } - } } //namespace LWGUI diff --git a/Editor/RevertIcon.png b/Editor/RevertIcon.png new file mode 100644 index 0000000..154375a Binary files /dev/null and b/Editor/RevertIcon.png differ diff --git a/Editor/RevertIcon.png.meta b/Editor/RevertIcon.png.meta new file mode 100644 index 0000000..7141f6a --- /dev/null +++ b/Editor/RevertIcon.png.meta @@ -0,0 +1,158 @@ +fileFormatVersion: 2 +guid: e7bc1130858d984488bca32b8512ca96 +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 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + 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: 2 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 8192 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 8192 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 8192 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 8192 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Windows Store Apps + maxTextureSize: 8192 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 8192 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index 4862e4a..98a3999 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -1,9 +1,9 @@ -using System.Collections; +// Copyright (c) 2022 Jason Ma + using System.Collections.Generic; +using System.Linq; using UnityEditor; using UnityEngine; -using UnityEngine.Events; -using System.IO; namespace LWGUI { @@ -23,6 +23,8 @@ public class MainDrawer : MaterialPropertyDrawer private bool _defaultFoldingState; private bool _defaultToggleDisplayed; + private static readonly float _height = 28f; + public MainDrawer() : this("") { } public MainDrawer(string group) : this(group, "") { } @@ -51,24 +53,25 @@ public override void OnGUI(Rect position, MaterialProperty prop, GUIContent labe EditorGUI.showMixedValue = prop.hasMixedValue; var toggleValue = prop.floatValue == 1.0f; - string finalGroupName = _group != "" ? _group : prop.name; + string finalGroupName = (_group != "" && _group != "_") ? _group : prop.name; bool isFirstFrame = !GUIData.group.ContainsKey(finalGroupName); _isFolding = isFirstFrame ? !_defaultFoldingState : GUIData.group[finalGroupName]; + EditorGUI.BeginChangeCheck(); bool toggleResult = Helper.Foldout(position, ref _isFolding, toggleValue, _defaultToggleDisplayed, label.text); EditorGUI.showMixedValue = false; - if (toggleResult != toggleValue) + if (EditorGUI.EndChangeCheck()) { prop.floatValue = toggleResult ? 1.0f : 0.0f; Helper.SetShaderKeyWord(editor.targets, Helper.GetKeyWord(_keyword, prop.name), toggleResult); } // Sometimes the Toggle is activated but the key is not activated - else - { - if (!prop.hasMixedValue) - Helper.SetShaderKeyWord(editor.targets, Helper.GetKeyWord(_keyword, prop.name), toggleResult); - } + // else + // { + // if (!prop.hasMixedValue) + // Helper.SetShaderKeyWord(editor.targets, Helper.GetKeyWord(_keyword, prop.name), toggleResult); + // } if (isFirstFrame) GUIData.group.Add(finalGroupName, _isFolding); @@ -76,11 +79,20 @@ public override void OnGUI(Rect position, MaterialProperty prop, GUIContent labe GUIData.group[finalGroupName] = _isFolding; } - // If use OnGUI(Rect position) as Rect, we need to accurately set GetPropertyHeight() - // if use EditorGUILayout.GetControlRect() as Rect, GetPropertyHeight() only increases the interval public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { - return 4f; + return _height; + } + + public override void Apply(MaterialProperty prop) + { + base.Apply(prop); + if (!prop.hasMixedValue && (prop.type == MaterialProperty.PropType.Float +#if UNITY_2021_1_OR_NEWER + || prop.type == MaterialProperty.PropType.Int +#endif + )) + Helper.SetShaderKeyWord(prop.targets, Helper.GetKeyWord(_keyword, prop.name), prop.floatValue > 0f); } } @@ -91,16 +103,14 @@ public override float GetPropertyHeight(MaterialProperty prop, string label, Mat /// public class SubDrawer : MaterialPropertyDrawer { - public static readonly int propRight = 80; - protected string group = ""; protected MaterialProperty prop; protected MaterialProperty[] props; protected bool IsVisible() { return Helper.IsVisible(group); } - protected virtual float GetVisibleHeight() { return 0; } - protected virtual float GetInvisibleHeight() { return -2; } // Remove the redundant height when invisible + protected virtual float GetVisibleHeight() { return 18f; } + // protected virtual float GetInvisibleHeight() { return -2; } // Remove the redundant height when invisible protected virtual bool IsMatchPropType() { return true; } @@ -116,44 +126,46 @@ public override void OnGUI(Rect position, MaterialProperty prop, GUIContent labe this.prop = prop; props = Helper.GetProperties(editor); + var rect = position; + if (group != "" && group != "_") - { EditorGUI.indentLevel++; - if (IsVisible()) - { - if (IsMatchPropType()) - DrawProp(position, prop, label, editor); - else - { - Debug.LogWarning( - this.GetType() + " does not support this MaterialProperty type:'" + prop.type + "'!"); - editor.DefaultShaderProperty(prop, label.text); - } - } - - EditorGUI.indentLevel--; - } - else + + if (IsVisible()) { if (IsMatchPropType()) - DrawProp(position, prop, label, editor); + { + EditorGUIUtility.fieldWidth = RevertableHelper.fieldWidth; + EditorGUIUtility.labelWidth = RevertableHelper.labelWidth; + DrawProp(rect, prop, label, editor); + } else { Debug.LogWarning(this.GetType() + " does not support this MaterialProperty type:'" + prop.type + "'!"); - editor.DefaultShaderProperty(prop, label.text); + editor.DefaultShaderProperty(rect, prop, label.text); } } + + if (group != "" && group != "_") + EditorGUI.indentLevel--; } public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { - return IsVisible() || group == "" || group == "_" ? GetVisibleHeight() : GetInvisibleHeight(); + return IsVisible() || group == "" || group == "_" ? GetVisibleHeight() : 0; } // Draws a custom style property public virtual void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { - editor.DefaultShaderProperty(prop, label.text); + // Process some builtin types display misplaced + switch (prop.type) + { + case MaterialProperty.PropType.Range: + editor.SetDefaultGUIWidths(); + break; + } + editor.DefaultShaderProperty(position, prop, label.text); } } @@ -165,8 +177,9 @@ public virtual void DrawProp(Rect position, MaterialProperty prop, GUIContent la /// public class SubToggleDrawer : SubDrawer { - private string _keyWord; + private string _keyWord = ""; + public SubToggleDrawer() { } public SubToggleDrawer(string group) : this(group, "") { } public SubToggleDrawer(string group, string keyWord) @@ -181,7 +194,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l { EditorGUI.showMixedValue = prop.hasMixedValue; EditorGUI.BeginChangeCheck(); - var rect = EditorGUILayout.GetControlRect(); + var rect = position;//EditorGUILayout.GetControlRect(); var value = EditorGUI.Toggle(rect, label, prop.floatValue > 0.0f); string k = Helper.GetKeyWord(_keyWord, prop.name); if (EditorGUI.EndChangeCheck()) @@ -189,11 +202,11 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l prop.floatValue = value ? 1.0f : 0.0f; Helper.SetShaderKeyWord(editor.targets, k, value); } - else - { - if (!prop.hasMixedValue) - Helper.SetShaderKeyWord(editor.targets, k, value); - } + // else + // { + // if (!prop.hasMixedValue) + // Helper.SetShaderKeyWord(editor.targets, k, value); + // } if (GUIData.keyWord.ContainsKey(k)) { @@ -206,6 +219,13 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l EditorGUI.showMixedValue = false; } + + public override void Apply(MaterialProperty prop) + { + base.Apply(prop); + if (!prop.hasMixedValue && prop.type == MaterialProperty.PropType.Float) + Helper.SetShaderKeyWord(prop.targets, Helper.GetKeyWord(_keyWord, prop.name), prop.floatValue > 0f); + } } /// @@ -216,9 +236,9 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// public class SubPowerSliderDrawer : SubDrawer { - private float _power; + private float _power = 1; - public SubPowerSliderDrawer(string group) : this(group, 1) { } + public SubPowerSliderDrawer(float power) : this("_", power) { } public SubPowerSliderDrawer(string group, float power) { @@ -230,8 +250,9 @@ public SubPowerSliderDrawer(string group, float power) public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { + editor.SetDefaultGUIWidths(); EditorGUI.showMixedValue = prop.hasMixedValue; - var rect = EditorGUILayout.GetControlRect(); + var rect = position; //EditorGUILayout.GetControlRect(); Helper.PowerSlider(prop, _power, rect, label); EditorGUI.showMixedValue = false; } @@ -251,6 +272,21 @@ public class KWEnumDrawer : SubDrawer #region + public KWEnumDrawer(string n1, string k1) + : this("_", new string[1] { n1 }, new string[1] { k1 }) { } + + public KWEnumDrawer(string n1, string k1, string n2, string k2) + : this("_", new string[2] { n1, n2 }, new string[2] { k1, k2 }) { } + + public KWEnumDrawer(string n1, string k1, string n2, string k2, string n3, string k3) + : this("_", new string[3] { n1, n2, n3 }, new string[3] { k1, k2, k3 }) { } + + public KWEnumDrawer(string n1, string k1, string n2, string k2, string n3, string k3, string n4, string k4) + : this("_", new string[4] { n1, n2, n3, n4 }, new string[4] { k1, k2, k3, k4 }) { } + + public KWEnumDrawer(string n1, string k1, string n2, string k2, string n3, string k3, string n4, string k4, string n5, string k5) + : this("_", new string[5] { n1, n2, n3, n4, n5 }, new string[5] { k1, k2, k3, k4, k5 }) { } + public KWEnumDrawer(string group, string n1, string k1) : this(group, new string[1] { n1 }, new string[1] { k1 }) { } @@ -291,19 +327,48 @@ public KWEnumDrawer(string group, string[] names, string[] keyWords) public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { - var rect = EditorGUILayout.GetControlRect(); + var rect = position; //EditorGUILayout.GetControlRect(); int index = (int)prop.floatValue; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; - int num = EditorGUI.IntPopup(rect, label.text, index, this._names, this._values); + int newIndex = EditorGUI.IntPopup(rect, label.text, index, this._names, this._values); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { - prop.floatValue = (float)num; + prop.floatValue = (float)newIndex; + Helper.SetShaderKeyWord(editor.targets, _keyWords, newIndex); } + + // set keyword for conditional display + for (int i = 0; i < _keyWords.Length; i++) + { + if (GUIData.keyWord.ContainsKey(_keyWords[i])) + { + GUIData.keyWord[_keyWords[i]] = newIndex == i; + } + else + { + GUIData.keyWord.Add(_keyWords[i], newIndex == i); + } + } + } - Helper.SetShaderKeyWord(editor.targets, _keyWords, num); + public override void Apply(MaterialProperty prop) + { + base.Apply(prop); + if (!prop.hasMixedValue && (prop.type == MaterialProperty.PropType.Float +#if UNITY_2021_1_OR_NEWER + || prop.type == MaterialProperty.PropType.Int +#endif + )) + Helper.SetShaderKeyWord(prop.targets, _keyWords, prop.type == MaterialProperty.PropType.Float ? (int)prop.floatValue : +#if UNITY_2021_1_OR_NEWER + prop.intValue +#else + (int)prop.floatValue +#endif + ); } } @@ -312,13 +377,14 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// group:father group name, support suffix keyword for conditional display (Default: none) /// extraPropName: extra property name (Unity 2019.2+ only) (Default: none) /// Target Property Type: Texture - /// Extra Property Type: Any + /// Extra Property Type: Any, except Texture /// public class TexDrawer : SubDrawer { - private string _extraPropName; + private string _extraPropName = ""; + private ChannelDrawer _channelDrawer = new ChannelDrawer("_"); - public TexDrawer() : this("", "") { } + public TexDrawer() { } public TexDrawer(string group) : this(group, "") { } @@ -333,34 +399,45 @@ public TexDrawer(string group, string extraPropName) public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { EditorGUI.showMixedValue = prop.hasMixedValue; - var rect = EditorGUILayout.GetControlRect(); + var rect = position; //EditorGUILayout.GetControlRect(); + + editor.TexturePropertyMiniThumbnail(rect, prop, label.text, label.tooltip); + MaterialProperty extraProp = null; if (_extraPropName != "" && _extraPropName != "_") extraProp = LWGUI.FindProp(_extraPropName, props, true); - if (extraProp != null) + if (extraProp != null && extraProp.type != MaterialProperty.PropType.Texture) { Rect extraPropRect = Rect.zero; if (extraProp.type == MaterialProperty.PropType.Range) { - var w = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; + EditorGUIUtility.fieldWidth = RevertableHelper.fieldWidth - 12f; extraPropRect = MaterialEditor.GetRectAfterLabelWidth(rect); - EditorGUIUtility.labelWidth = w; } else extraPropRect = MaterialEditor.GetRectAfterLabelWidth(rect); - editor.TexturePropertyMiniThumbnail(rect, prop, label.text, label.tooltip); var i = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; - editor.ShaderProperty(extraPropRect, extraProp, ""); + if (extraProp.type == MaterialProperty.PropType.Vector) + { + _channelDrawer.DrawProp(extraPropRect, extraProp, new GUIContent(""), editor); + } + else + { + editor.ShaderProperty(extraPropRect, extraProp, ""); + } EditorGUI.indentLevel = i; - } - else - { - editor.TexturePropertyMiniThumbnail(rect, prop, label.text, label.tooltip); + + + var revertButtonRect = RevertableHelper.GetRevertButtonRect(extraProp, position, true); + if (RevertableHelper.RevertButton(revertButtonRect, extraProp, editor)) + { + RevertableHelper.SetPropertyToDefault(extraProp); + } } EditorGUI.showMixedValue = false; @@ -377,8 +454,6 @@ public class ColorDrawer : SubDrawer { private string[] _colorStrings = new string[3]; - public ColorDrawer(string group) : this(group, "", "", "") { } - public ColorDrawer(string group, string color2) : this(group, color2, "", "") { } public ColorDrawer(string group, string color2, string color3) : this(group, color2, color3, "") { } @@ -410,19 +485,20 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l } int count = cProps.Count; - var rect = EditorGUILayout.GetControlRect(); + var colorArray = cProps.ToArray(); + var rect = position; //EditorGUILayout.GetControlRect(); - var p1 = cProps.Pop(); + var p1 = colorArray[0]; EditorGUI.showMixedValue = p1.hasMixedValue; editor.ColorProperty(rect, p1, label.text); for (int i = 1; i < count; i++) { - var cProp = cProps.Pop(); + var cProp = colorArray[i]; EditorGUI.showMixedValue = cProp.hasMixedValue; Rect r = new Rect(rect); var interval = 13 * i * (-0.25f + EditorGUI.indentLevel * 1.25f); - float w = propRight * (0.8f + EditorGUI.indentLevel * 0.2f); + float w = EditorGUIUtility.fieldWidth * (0.8f + EditorGUI.indentLevel * 0.2f); r.xMin += r.width - w * (i + 1) + interval; r.xMax -= w * i - interval; @@ -441,12 +517,29 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l } } + var revertButtonRect = RevertableHelper.GetRevertButtonRect(prop, position, true); + bool[] needRevert = new bool[count]; + for (int i = 0; i < needRevert.Length; i++) + { + if (i == 0) needRevert[i] = RevertableHelper.ContainsProperty(prop.targets[0], colorArray[i].name); + else needRevert[i] = RevertableHelper.RevertButton(revertButtonRect, colorArray[i], editor); + } + + if (needRevert.Contains(true)) + { + for (int i = 1; i < count; i++) + { + RevertableHelper.SetPropertyToDefault(colorArray[i]); + } + RevertableHelper.RemoveProperty(prop.targets, prop.name); + } + EditorGUI.showMixedValue = false; } } /// - /// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 2 * 512) + /// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 512 * 2) /// group:father group name, support suffix keyword for conditional display (Default: none) /// defaultFileName: default Ramp Map file name when create a new one (Default: RampMap) /// defaultWidth: default Ramp Width (Default: 512) @@ -466,9 +559,9 @@ public class RampDrawer : SubDrawer private static readonly GUIContent _iconMixImage = EditorGUIUtility.IconContent("darkviewbackground"); + protected override float GetVisibleHeight() { return 18f * 2f; } public RampDrawer() : this("") { } - public RampDrawer(string group) : this(group, "RampMap") { } public RampDrawer(string group, string defaultFileName) : this(group, defaultFileName, 512) { } @@ -489,7 +582,8 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l _serializedObject = new SerializedObject(_gradientObject); // Draw Label - var labelRect = EditorGUILayout.GetControlRect(); + var labelRect = new Rect(position);//EditorGUILayout.GetControlRect(); + labelRect.yMax -= position.height * 0.5f; EditorGUI.PrefixLabel(labelRect, new GUIContent(label)); // Ramp buttons Rect @@ -497,9 +591,11 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l var indentLevel = EditorGUI.indentLevel; EditorGUIUtility.labelWidth = 0; EditorGUI.indentLevel = 0; - var buttonRect = EditorGUILayout.GetControlRect(); + var buttonRect = new Rect(position);//EditorGUILayout.GetControlRect(); + buttonRect.yMin += position.height * 0.5f; buttonRect = MaterialEditor.GetRectAfterLabelWidth(buttonRect); - + if (buttonRect.width < 50f) return; + // Draw Ramp Editor bool hasChange, doSave, doDiscard; Texture newUserTexture, newCreatedTexture; @@ -561,10 +657,10 @@ public class MinMaxSliderDrawer : SubDrawer private string _minPropName; private string _maxPropName; + public MinMaxSliderDrawer(string minPropName, string maxPropName) : this("_", minPropName, maxPropName) { } public MinMaxSliderDrawer(string group, string minPropName, string maxPropName) { this.group = group; - this._minPropName = minPropName; this._maxPropName = maxPropName; } @@ -585,7 +681,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l float maxf = max.floatValue; // define draw area - Rect controlRect = EditorGUILayout.GetControlRect(); // this is the full length rect area + Rect controlRect = position; //EditorGUILayout.GetControlRect(); // this is the full length rect area var w = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; Rect inputRect = MaterialEditor.GetRectAfterLabelWidth(controlRect); // this is the remaining rect area after label's area @@ -617,7 +713,8 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; - EditorGUI.MinMaxSlider(splittedRect[1], ref minf, ref maxf, prop.rangeLimits.x, prop.rangeLimits.y); + if (splittedRect[1].width > 50f) + EditorGUI.MinMaxSlider(splittedRect[1], ref minf, ref maxf, prop.rangeLimits.x, prop.rangeLimits.y); EditorGUI.showMixedValue = false; // write back min max if changed @@ -627,6 +724,14 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l max.floatValue = Mathf.Clamp(maxf, max.rangeLimits.x, max.rangeLimits.y); } + var revertButtonRect = RevertableHelper.GetRevertButtonRect(prop, position, true); + if (RevertableHelper.RevertButton(revertButtonRect, min, editor) || + RevertableHelper.RevertButton(revertButtonRect, max, editor)) + { + RevertableHelper.SetPropertyToDefault(min); + RevertableHelper.SetPropertyToDefault(max); + } + } } @@ -635,12 +740,12 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// group:father group name, support suffix keyword for conditional display (Default: none) /// Target Property Type: Vector, used to dot() with Texture Sample Value /// - public class RGBAChannelMaskToVec4Drawer : ChannelDrawer {public RGBAChannelMaskToVec4Drawer(string group):base(group){}} public class ChannelDrawer : SubDrawer { private string[] _names = new string[] { "R", "G", "B", "A", "RGB Average", "RGB Luminance" }; private int[] _values = new int[] { 0, 1, 2, 3, 4, 5 }; + public ChannelDrawer() { } public ChannelDrawer(string group) { this.group = group; @@ -658,7 +763,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l Vector4 RGBAverage = new Vector4(1f / 3f, 1f / 3f, 1f / 3f, 0); Vector4 RGBLuminance = new Vector4(0.2126f, 0.7152f, 0.0722f, 0); - var rect = EditorGUILayout.GetControlRect(); + var rect = position; //EditorGUILayout.GetControlRect(); int index; if (prop.vectorValue == R) index = 0; @@ -713,19 +818,28 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l } } } + + // Obsolete + public class RGBAChannelMaskToVec4Drawer : ChannelDrawer + { + public RGBAChannelMaskToVec4Drawer() { Helper.ObsoleteWarning("RGBAChannelMaskToVec4Drawer()", "ChannelDrawer()"); } + public RGBAChannelMaskToVec4Drawer(string group) : base(group) { Helper.ObsoleteWarning("RGBAChannelMaskToVec4Drawer()", "ChannelDrawer()"); } + } + /// -/// Similar to Header() -/// group:father group name, support suffix keyword for conditional display (Default: none) -/// header: string to display + /// Similar to Header() + /// group:father group name, support suffix keyword for conditional display (Default: none) + /// header: string to display, "SpaceLine" or "_" = none (Default: none) /// public class TitleDecorator : SubDrawer { private string _header; protected override float GetVisibleHeight() { return 24f; } - protected override float GetInvisibleHeight() { return 0f; } + // protected override float GetInvisibleHeight() { return 0f; } + public TitleDecorator(string header) : this("_", header) {} public TitleDecorator(string group, string header) { this.group = group; diff --git a/Editor/Test/KeywordTestShader.shader b/Editor/Test/KeywordTestShader.shader new file mode 100644 index 0000000..339fd95 --- /dev/null +++ b/Editor/Test/KeywordTestShader.shader @@ -0,0 +1,89 @@ +Shader "Hidden" +{ + Properties + { + [KWEnum(_, Name 1, _KWENUM_KEY1, Name 2, _KWENUM_KEY2)] + _kwenum ("KWEnum", float) = 0 + + [KeywordEnum(key1, key2)] + _enum ("KeywordEnum", float) = 0 + + [SubToggle(_, _SUBTOGGLE_KEYWORD)] _toggle ("Sub Toggle", float) = 0 + [SubToggle(_, _TOGGLE_KEYWORD)] _toggle1 ("Toggle", float) = 0 + + } + SubShader + { + Tags { "RenderType"="Opaque" } + LOD 100 + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + // make fog work + #pragma multi_compile_fog + #pragma multi_compile _KWENUM_KEY1 _KWENUM_KEY2 + #pragma multi_compile _ENUM_KEY1 _ENUM_KEY2 + #pragma multi_compile _ _SUBTOGGLE_KEYWORD + #pragma multi_compile _ _TOGGLE_KEYWORD + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + UNITY_FOG_COORDS(1) + float4 vertex : SV_POSITION; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + + v2f vert (appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + UNITY_TRANSFER_FOG(o,o.vertex); + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + fixed4 col = 0; + + #if _KWENUM_KEY1 + col.x = 0; + #elif _KWENUM_KEY2 + col.x = 1; + #endif + + #if _ENUM_KEY1 + col.y = 0; + #elif _ENUM_KEY2 + col.y = 1; + #endif + + #if _SUBTOGGLE_KEYWORD + col.z = 0.5; + #endif + + #if _TOGGLE_KEYWORD + col.z = 1; + #endif + + return col; + } + ENDCG + } + } + CustomEditor "LWGUI.LWGUI" +} diff --git a/Editor/Test/KeywordTestShader.shader.meta b/Editor/Test/KeywordTestShader.shader.meta new file mode 100644 index 0000000..d55fb83 --- /dev/null +++ b/Editor/Test/KeywordTestShader.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 52d4969be96ad35418215d6bda45665b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Test/LWGUI_KeywordTest 1.mat b/Editor/Test/LWGUI_KeywordTest 1.mat new file mode 100644 index 0000000..f46de2d --- /dev/null +++ b/Editor/Test/LWGUI_KeywordTest 1.mat @@ -0,0 +1,34 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: LWGUI_KeywordTest 1 + m_Shader: {fileID: 4800000, guid: 52d4969be96ad35418215d6bda45665b, type: 3} + m_ValidKeywords: + - _ENUM_KEY2 + - _KWENUM_KEY2 + - _SUBTOGGLE_KEYWORD + - _TOGGLE_KEYWORD + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: [] + m_Ints: [] + m_Floats: + - _enum: 1 + - _kwenum: 1 + - _toggle: 1 + - _toggle1: 1 + m_Colors: [] + m_BuildTextureStacks: [] diff --git a/Editor/Test/LWGUI_KeywordTest 1.mat.meta b/Editor/Test/LWGUI_KeywordTest 1.mat.meta new file mode 100644 index 0000000..33c2403 --- /dev/null +++ b/Editor/Test/LWGUI_KeywordTest 1.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bb8663d0faf43214abeee1d0c3fdd118 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Test/LWGUI_KeywordTest.mat b/Editor/Test/LWGUI_KeywordTest.mat new file mode 100644 index 0000000..64c32ab --- /dev/null +++ b/Editor/Test/LWGUI_KeywordTest.mat @@ -0,0 +1,32 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: LWGUI_KeywordTest + m_Shader: {fileID: 4800000, guid: 52d4969be96ad35418215d6bda45665b, type: 3} + m_ValidKeywords: + - _ENUM_KEY1 + - _KWENUM_KEY1 + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: [] + m_Ints: [] + m_Floats: + - _enum: 0 + - _kwenum: 0 + - _toggle: 0 + - _toggle1: 0 + m_Colors: [] + m_BuildTextureStacks: [] diff --git a/Editor/Test/LWGUI_KeywordTest.mat.meta b/Editor/Test/LWGUI_KeywordTest.mat.meta new file mode 100644 index 0000000..0021ffe --- /dev/null +++ b/Editor/Test/LWGUI_KeywordTest.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 64f63a798b03f4a448ef2a853da686c9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Test/LWGUI_SampleDrawer 1.mat b/Editor/Test/LWGUI_SampleDrawer 1.mat index 73bd0f6..dd553b8 100644 --- a/Editor/Test/LWGUI_SampleDrawer 1.mat +++ b/Editor/Test/LWGUI_SampleDrawer 1.mat @@ -11,12 +11,10 @@ Material: m_Shader: {fileID: 4800000, guid: 7ee048c9536c0344bb8b4860595a4d9b, type: 3} m_ValidKeywords: [] m_InvalidKeywords: - - KEY1 - _GROUP_ON - _KEY1 - _KEY2 - _KEY3 - - _KEYWORD - _TOGGLE_KEYWORD m_LightmapFlags: 4 m_EnableInstancingVariants: 0 @@ -28,7 +26,7 @@ Material: serializedVersion: 3 m_TexEnvs: - _Ramp: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: 87addb69bcbcc9b4ea7336eff8d6a52b, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _normal: @@ -39,31 +37,58 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _tex_channel: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_color: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_float: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_range: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_toggle: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: - - _enum: 2 - - _float: 0 - - _float1: 0 - - _float2: 0 + - _enum: 1 + - _float: -0.8 + - _float1: 0.33 + - _float2: -0.35 - _float3: 0 + - _float4: 2 - _floatN: 0 - - _group: 0 - - _group1: 1 + - _group: 1 + - _group1: 0 - _group2: 0 + - _group3: 0 - _key1_Float1: 0 - _key2_Float2: 0 - - _key3_Float3: 0 - - _key3_Float4_PowerSlider: 0.5 + - _key3_Float3: -0.34 + - _key3_Float3_Range: 0.329 + - _key3_Float4_PowerSlider: 0 - _minMaxSlider: 1 - - _rangeEnd: 0.6857636 - - _rangeStart: 0 + - _range: 0.42 + - _rangeEnd: 0.67997557 + - _rangeStart: 0.25601953 - _toggle: 1 + - _toggle1: 1 m_Colors: - - _color: {r: 1, g: 0, b: 0, a: 1} - - _color1: {r: 0.7, g: 0.7, b: 1, a: 1} - - _mColor: {r: 1, g: 1, b: 1, a: 1} - - _mColor1: {r: 1, g: 0, b: 0, a: 1} - - _mColor2: {r: 0, g: 1, b: 0, a: 1} - - _mColor3: {r: 0, g: 0, b: 1, a: 1} - - _textureChannelMask: {r: 0, g: 1, b: 0, a: 0} + - _color: {r: 0.6698113, g: 0.40062296, b: 0.40062296, a: 1} + - _color1: {r: 0.07924521, g: 0.07924521, b: 1, a: 1} + - _mColor: {r: 0.7169812, g: 0.44236386, b: 0.44236386, a: 1} + - _mColor1: {r: 0.49056602, g: 0.30266997, b: 0.30266997, a: 1} + - _mColor2: {r: 0.2696155, g: 0.4811321, b: 0.2696155, a: 1} + - _mColor3: {r: 0.5754717, g: 0.2953364, b: 0.2953364, a: 1} + - _textureChannelMask: {r: 0, g: 0, b: 1, a: 0} + - _textureChannelMask1: {r: 0, g: 0, b: 0, a: 1} + - _vector1: {r: 1, g: 1, b: 1, a: 1} m_BuildTextureStacks: [] diff --git a/Editor/Test/LWGUI_SampleDrawer 2.mat b/Editor/Test/LWGUI_SampleDrawer 2.mat index 91248f2..313c587 100644 --- a/Editor/Test/LWGUI_SampleDrawer 2.mat +++ b/Editor/Test/LWGUI_SampleDrawer 2.mat @@ -11,12 +11,8 @@ Material: m_Shader: {fileID: 4800000, guid: 7ee048c9536c0344bb8b4860595a4d9b, type: 3} m_ValidKeywords: [] m_InvalidKeywords: - - KEY1 - _GROUP_ON - - _KEY1 - - _KEY2 - _KEY3 - - _KEYWORD - _TOGGLE_KEYWORD m_LightmapFlags: 4 m_EnableInstancingVariants: 0 @@ -39,31 +35,58 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _tex_channel: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_color: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_float: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_range: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _tex_toggle: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: - _enum: 2 - - _float: 0 - - _float1: 0 - - _float2: 0 + - _float: 0.53 + - _float1: 0.15 + - _float2: -0.57 - _float3: 0 + - _float4: 1 - _floatN: 0 - - _group: 0 - - _group1: 1 + - _group: 1 + - _group1: 0 - _group2: 0 + - _group3: 0 - _key1_Float1: 0 - _key2_Float2: 0 - _key3_Float3: 0 - - _key3_Float4_PowerSlider: 0 + - _key3_Float3_Range: 0 + - _key3_Float4_PowerSlider: 0.000088794855 - _minMaxSlider: 1 - - _rangeEnd: 1 - - _rangeStart: 0 + - _range: 0.305 + - _rangeEnd: 0.7474536 + - _rangeStart: 0.24745372 - _toggle: 1 + - _toggle1: 0 m_Colors: - - _color: {r: 1, g: 0, b: 0, a: 1} + - _color: {r: 0.6698113, g: 0.38798502, b: 0.38798502, a: 1} - _color1: {r: 0.7, g: 0.7, b: 1, a: 1} - - _mColor: {r: 1, g: 1, b: 1, a: 1} - - _mColor1: {r: 1, g: 0, b: 0, a: 1} + - _mColor: {r: 0.4852941, g: 0.23907872, b: 0.23907872, a: 1} + - _mColor1: {r: 0.7264151, g: 0.46189037, b: 0.46189037, a: 1} - _mColor2: {r: 0, g: 1, b: 0, a: 1} - - _mColor3: {r: 0, g: 0, b: 1, a: 1} + - _mColor3: {r: 0.3404414, g: 0.3404414, b: 0.6886792, a: 1} - _textureChannelMask: {r: 0, g: 1, b: 0, a: 0} + - _textureChannelMask1: {r: 0, g: 1, b: 0, a: 0} + - _vector1: {r: 1, g: 1.47, b: 1.39, a: 1} m_BuildTextureStacks: [] diff --git a/Editor/Test/LWGUI_SampleDrawer.mat b/Editor/Test/LWGUI_SampleDrawer.mat index c5663f0..ac0ca0d 100644 --- a/Editor/Test/LWGUI_SampleDrawer.mat +++ b/Editor/Test/LWGUI_SampleDrawer.mat @@ -4,13 +4,11 @@ Material: serializedVersion: 6 m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} m_Name: LWGUI_SampleDrawer m_Shader: {fileID: 4800000, guid: ded91f399f8343d4f9b0cf33eda0088d, type: 3} - m_ShaderKeywords: KEY2 _GROUP3_ON _GROUP4_ON _GROUP5_ON _GROUP6_ON _GROUP7_ON _GROUP8_ON - _GROUP_ON _KEYWORD + m_ShaderKeywords: KEY2 _KEYWORD m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -28,10 +26,14 @@ Material: m_Texture: {fileID: 2800000, guid: df4a1e363556192459af030f3e1d4e89, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - - _normal: + - _Ramp2: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _normal: + m_Texture: {fileID: 2800000, guid: 7cfdb589134f93c4abec6de50366e82d, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _tex: m_Texture: {fileID: 2800000, guid: 936423d97fbdd3c40bd47377240f5c64, type: 3} m_Scale: {x: 1, y: 1} @@ -59,7 +61,7 @@ Material: - _float36: 2 - _float4: 2 - _float_keyword: 0 - - _group: 1 + - _group: 0 - _group2: 1 - _group3: 1 - _group4: 1 @@ -75,5 +77,5 @@ Material: - _hdr: {r: 1, g: 1, b: 1, a: 1} - _mColor: {r: 1, g: 1, b: 1, a: 1} - _mColor1: {r: 1, g: 0, b: 0, a: 1} - - _mColor2: {r: 0, g: 1, b: 0, a: 1} + - _mColor2: {r: 0.68301886, g: 1, b: 0.68301886, a: 1} - _mColor3: {r: 0, g: 0, b: 1, a: 1} diff --git a/Editor/Test/RampMap.png b/Editor/Test/RampMap.png index d0778bc..756da0f 100644 Binary files a/Editor/Test/RampMap.png and b/Editor/Test/RampMap.png differ diff --git a/Editor/Test/RampMap.png.meta b/Editor/Test/RampMap.png.meta index 7daaa39..359dd0a 100644 --- a/Editor/Test/RampMap.png.meta +++ b/Editor/Test/RampMap.png.meta @@ -1,9 +1,9 @@ fileFormatVersion: 2 guid: df4a1e363556192459af030f3e1d4e89 TextureImporter: - internalIDToNameTable: [] + fileIDToRecycleName: {} externalObjects: {} - serializedVersion: 11 + serializedVersion: 4 mipmaps: mipMapMode: 0 enableMipMap: 1 @@ -21,10 +21,6 @@ TextureImporter: heightScale: 0.25 normalMapFilter: 0 isReadable: 1 - streamingMipmaps: 0 - streamingMipmapsPriority: 0 - vTOnly: 0 - ignoreMasterTextureLimit: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -55,17 +51,11 @@ TextureImporter: spriteTessellationDetail: -1 textureType: 0 textureShape: 1 - singleChannelComponent: 0 - flipbookRows: 1 - flipbookColumns: 1 maxTextureSizeSet: 0 compressionQualitySet: 0 textureFormatSet: 0 - ignorePngGamma: 0 - applyGammaDecoding: 1 platformSettings: - - serializedVersion: 3 - buildTarget: DefaultTexturePlatform + - buildTarget: DefaultTexturePlatform maxTextureSize: 8192 resizeAlgorithm: 0 textureFormat: -1 @@ -75,9 +65,7 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 1 - - serializedVersion: 3 - buildTarget: Standalone + - buildTarget: Standalone maxTextureSize: 8192 resizeAlgorithm: 0 textureFormat: -1 @@ -87,9 +75,7 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 1 - - serializedVersion: 3 - buildTarget: iPhone + - buildTarget: iPhone maxTextureSize: 8192 resizeAlgorithm: 0 textureFormat: -1 @@ -99,9 +85,7 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 1 - - serializedVersion: 3 - buildTarget: Android + - buildTarget: Android maxTextureSize: 8192 resizeAlgorithm: 0 textureFormat: -1 @@ -111,9 +95,7 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 1 - - serializedVersion: 3 - buildTarget: Windows Store Apps + - buildTarget: Windows Store Apps maxTextureSize: 8192 resizeAlgorithm: 0 textureFormat: -1 @@ -123,9 +105,7 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 1 - - serializedVersion: 3 - buildTarget: Server + - buildTarget: Server maxTextureSize: 8192 resizeAlgorithm: 0 textureFormat: -1 @@ -135,24 +115,12 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 1 spriteSheet: serializedVersion: 2 sprites: [] outline: [] physicsShape: [] - bones: [] - spriteID: - internalID: 0 - vertices: [] - indices: - edges: [] - weights: [] - secondaryTextures: [] - nameFileIdTable: {} spritePackingTag: - pSDRemoveMatte: 0 - pSDShowRemoveMatteOption: 0 - userData: '{"MonoBehaviour":{"m_Enabled":true,"m_EditorHideFlags":0,"m_Name":"","m_EditorClassIdentifier":"LWGUI:LWGUI:RampHelper/GradientObject","gradient":{"serializedVersion":"2","key0":{"r":0.0,"g":1.0,"b":0.9728269577026367,"a":1.0},"key1":{"r":0.6437801718711853,"g":0.43921566009521487,"b":1.0,"a":1.0},"key2":{"r":1.0,"g":0.7137255072593689,"b":0.8696789145469666,"a":0.0},"key3":{"r":1.0,"g":0.8751868605613709,"b":0.36226409673690798,"a":0.0},"key4":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key5":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key6":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key7":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"ctime0":0,"ctime1":22359,"ctime2":40092,"ctime3":65535,"ctime4":0,"ctime5":0,"ctime6":0,"ctime7":0,"atime0":0,"atime1":65535,"atime2":0,"atime3":0,"atime4":0,"atime5":0,"atime6":0,"atime7":0,"m_Mode":0,"m_NumColorKeys":4,"m_NumAlphaKeys":2}}}#{"MonoBehaviour":{"m_Enabled":true,"m_EditorHideFlags":0,"m_Name":"","m_EditorClassIdentifier":"LWGUI:LWGUI:RampHelper/GradientObject","gradient":{"serializedVersion":"2","key0":{"r":0.0,"g":1.0,"b":0.9728269577026367,"a":1.0},"key1":{"r":0.6437801718711853,"g":0.43921566009521487,"b":1.0,"a":1.0},"key2":{"r":1.0,"g":0.7137255072593689,"b":0.8696789145469666,"a":0.0},"key3":{"r":1.0,"g":0.8751868605613709,"b":0.36226409673690798,"a":0.0},"key4":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key5":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key6":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key7":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"ctime0":0,"ctime1":22359,"ctime2":40092,"ctime3":65535,"ctime4":0,"ctime5":0,"ctime6":0,"ctime7":0,"atime0":0,"atime1":65535,"atime2":0,"atime3":0,"atime4":0,"atime5":0,"atime6":0,"atime7":0,"m_Mode":0,"m_NumColorKeys":4,"m_NumAlphaKeys":2}}}' + userData: '{"MonoBehaviour":{"m_Enabled":true,"m_EditorHideFlags":0,"m_Name":"","m_EditorClassIdentifier":"LWGUI:LWGUI:RampHelper/GradientObject","gradient":{"serializedVersion":"2","key0":{"r":0.0,"g":1.0,"b":0.9728269577026367,"a":1.0},"key1":{"r":0.6437801718711853,"g":0.43921566009521487,"b":1.0,"a":1.0},"key2":{"r":1.0,"g":0.7137255072593689,"b":0.8696789145469666,"a":0.0},"key3":{"r":1.0,"g":0.8751868605613709,"b":0.36226409673690798,"a":0.0},"key4":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key5":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key6":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key7":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"ctime0":0,"ctime1":21588,"ctime2":48380,"ctime3":65535,"ctime4":0,"ctime5":0,"ctime6":0,"ctime7":0,"atime0":0,"atime1":65535,"atime2":0,"atime3":0,"atime4":0,"atime5":0,"atime6":0,"atime7":0,"m_Mode":0,"m_NumColorKeys":4,"m_NumAlphaKeys":2}}}#{"MonoBehaviour":{"m_Enabled":true,"m_EditorHideFlags":0,"m_Name":"","m_EditorClassIdentifier":"LWGUI:LWGUI:RampHelper/GradientObject","gradient":{"serializedVersion":"2","key0":{"r":0.0,"g":1.0,"b":0.9728269577026367,"a":1.0},"key1":{"r":0.6437801718711853,"g":0.43921566009521487,"b":1.0,"a":1.0},"key2":{"r":1.0,"g":0.7137255072593689,"b":0.8696789145469666,"a":0.0},"key3":{"r":1.0,"g":0.8751868605613709,"b":0.36226409673690798,"a":0.0},"key4":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key5":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key6":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"key7":{"r":0.0,"g":0.0,"b":0.0,"a":0.0},"ctime0":0,"ctime1":21588,"ctime2":48380,"ctime3":65535,"ctime4":0,"ctime5":0,"ctime6":0,"ctime7":0,"atime0":0,"atime1":65535,"atime2":0,"atime3":0,"atime4":0,"atime5":0,"atime6":0,"atime7":0,"m_Mode":0,"m_NumColorKeys":4,"m_NumAlphaKeys":2}}}' assetBundleName: assetBundleVariant: diff --git a/Editor/Test/SampleDrawer 1.shader b/Editor/Test/SampleDrawer 1.shader index f9e52d1..3e46f55 100644 --- a/Editor/Test/SampleDrawer 1.shader +++ b/Editor/Test/SampleDrawer 1.shader @@ -2,47 +2,55 @@ Shader "Hidden" { Properties { - [Title(_, Main Samples)] - + [Title(Main Samples)] [Main(GroupName)] _group ("Group", float) = 0 [Sub(GroupName)] _float ("Float", float) = 0 - [Main(Group1, _KEYWORD, on)] - _group1 ("Group - Default Open", float) = 1 + [Main(Group1, _KEYWORD, on)] _group1 ("Group - Default Open", float) = 1 [Sub(Group1)] _float1 ("Sub Float", float) = 0 - [Sub(Group1)][HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1) + [Sub(Group1)] _vector1 ("Sub Vector", vector) = (1, 1, 1, 1) + [Sub(Group1)] [HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1) [Title(Group1, Conditional Display Samples Enum)] [KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)] - _enum ("Sub Enum", float) = 0 + _enum ("KWEnum", float) = 0 // Display when the keyword ("group name + keyword") is activated [Sub(Group1_KEY1)] _key1_Float1 ("Key1 Float", float) = 0 [Sub(Group1_KEY2)] _key2_Float2 ("Key2 Float", float) = 0 - [Sub(Group1_KEY3)] _key3_Float3 ("Key3 Float", float) = 0 + [Sub(Group1_KEY3)] _key3_Float3_Range ("Key3 Float Range", Range(0, 1)) = 0 [SubPowerSlider(Group1_KEY3, 10)] _key3_Float4_PowerSlider ("Key3 Power Slider", Range(0, 1)) = 0 [Title(Group1, Conditional Display Samples Toggle)] - [SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("Sub Toggle", float) = 0 + [SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("SubToggle", float) = 0 [Tex(Group1_TOGGLE_KEYWORD)][Normal] _normal ("Normal Keyword", 2D) = "bump" { } [Sub(Group1_TOGGLE_KEYWORD)] _float2 ("Float Keyword", float) = 0 - [Main(Group2, _, off, off)] - _group2 ("Group - Without Toggle", float) = 0 + [Main(Group2, _, off, off)] _group2 ("Group - Without Toggle", float) = 0 [Sub(Group2)] _float3 ("Float 2", float) = 0 - + [Space] - [Title(_, Tex and Color Samples)] + [Title(Channel Samples)] + [Channel] _textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0) - [Tex(_, _color)] _tex ("Tex with Color", 2D) = "white" { } + + [Space] + [Main(Group3, _, on)] _group3 ("Group - Tex and Color Samples", float) = 0 + [Tex(Group3, _color)] _tex_color ("Tex with Color", 2D) = "white" { } [HideInInspector] _color (" ", Color) = (1, 0, 0, 1) + [Tex(Group3, _float4)] _tex_float ("Tex with Float", 2D) = "white" { } + [HideInInspector] _float4 (" ", float) = 0 + [Tex(Group3, _range)] _tex_range ("Tex with Range", 2D) = "white" { } + [HideInInspector] _range (" ", Range(0,1)) = 0 + [Tex(Group3, _textureChannelMask1)] _tex_channel ("Tex with Channel", 2D) = "white" { } + [HideInInspector] _textureChannelMask1(" ", Vector) = (0,0,0,1) // Display up to 4 colors in a single line (Unity 2019.2+) - [Color(_, _mColor1, _mColor2, _mColor3)] + [Color(Group3, _mColor1, _mColor2, _mColor3)] _mColor ("Multi Color", Color) = (1, 1, 1, 1) [HideInInspector] _mColor1 (" ", Color) = (1, 0, 0, 1) [HideInInspector] _mColor2 (" ", Color) = (0, 1, 0, 1) @@ -50,21 +58,17 @@ Shader "Hidden" [Space] - [Title(_, Ramp Samples)] + [Title(Ramp Samples)] [Ramp] _Ramp ("Ramp Map", 2D) = "white" { } [Space] - [Title(_, MinMaxSlider Samples)] - - [MinMaxSlider(_, _rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0 - [HideInInspector] _rangeStart("Range Start", Range(0.0, 0.5)) = 0.0 - [HideInInspector] _rangeEnd("Range End", Range(0.5, 1.0)) = 1.0 + [Title(MinMaxSlider Samples)] + [MinMaxSlider(_rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0 + _rangeStart("Range Start", Range(0.0, 0.5)) = 0.0 + [PowerSlider(10)] _rangeEnd("Range End PowerSlider", Range(0.5, 1.0)) = 1.0 - [Space] - [Title(_, Channel Samples)] - [Channel(_)]_textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0) } HLSLINCLUDE diff --git a/Editor/Test/SampleDrawer.shader b/Editor/Test/SampleDrawer.shader index 4f54c45..084b529 100644 --- a/Editor/Test/SampleDrawer.shader +++ b/Editor/Test/SampleDrawer.shader @@ -9,10 +9,10 @@ Shader "Hidden" [Ramp]_Ramp ("Ramp", 2D) = "white" { } // use Title on LWGUI attribute - [Title(_, Title)] + [Title(Title)] [Tex(_, _mColor2)] _tex ("tex color", 2D) = "white" { } - [Title(_, Title on Group)] + [Title(Title on Group)] // Create a folding group with name "g1" [Main(g1)] _group ("Group", float) = 1 [Sub(g1)] _float ("float", float) = 2 diff --git a/LICENSE b/LICENSE index 03228ff..03550c4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 JasonMa +Copyright (c) 2022 Jason Ma Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 6723b8e..515a636 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Use simple MaterialProperty Drawer syntax to achieve complex Shader GUI, save a ![LWGUI](README_CN.assets/LWGUI.png) -- [LWGUI (Light Weight Shader GUI)](#lwgui--light-weight-shader-gui-) * [Installation](#installation) * [Usage](#usage) + [Getting Started](#getting-started) @@ -20,9 +19,9 @@ Use simple MaterialProperty Drawer syntax to achieve complex Shader GUI, save a - [SubPower](#subpower) - [KWEnum](#kwenum) - [Tex & Color](#tex---color) + - [Channel](#channel) - [Ramp](#ramp) - [MinMaxSlider](#minmaxslider) - - [Channel](#channel) - [Title](#title) + [Unity Builtin Drawers](#unity-builtin-drawers) - [Space](#space) @@ -78,48 +77,46 @@ SubDrawer(string group) Example: -```c -[Title(_, Main Samples)] - +```c# +[Title(Main Samples)] [Main(GroupName)] _group ("Group", float) = 0 [Sub(GroupName)] _float ("Float", float) = 0 -[Main(Group1, _KEYWORD, on)] -_group1 ("Group - Default Open", float) = 1 +[Main(Group1, _KEYWORD, on)] _group1 ("Group - Default Open", float) = 1 [Sub(Group1)] _float1 ("Sub Float", float) = 0 -[Sub(Group1)][HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1) +[Sub(Group1)] _vector1 ("Sub Vector", vector) = (1, 1, 1, 1) +[Sub(Group1)] [HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1) [Title(Group1, Conditional Display Samples Enum)] [KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)] -_enum ("Sub Enum", float) = 0 +_enum ("KWEnum", float) = 0 // Display when the keyword ("group name + keyword") is activated [Sub(Group1_KEY1)] _key1_Float1 ("Key1 Float", float) = 0 [Sub(Group1_KEY2)] _key2_Float2 ("Key2 Float", float) = 0 -[Sub(Group1_KEY3)] _key3_Float3 ("Key3 Float", float) = 0 +[Sub(Group1_KEY3)] _key3_Float3_Range ("Key3 Float Range", Range(0, 1)) = 0 [SubPowerSlider(Group1_KEY3, 10)] _key3_Float4_PowerSlider ("Key3 Power Slider", Range(0, 1)) = 0 [Title(Group1, Conditional Display Samples Toggle)] -[SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("Sub Toggle", float) = 0 +[SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("SubToggle", float) = 0 [Tex(Group1_TOGGLE_KEYWORD)][Normal] _normal ("Normal Keyword", 2D) = "bump" { } [Sub(Group1_TOGGLE_KEYWORD)] _float2 ("Float Keyword", float) = 0 -[Main(Group2, _, off, off)] -_group2 ("Group - Without Toggle", float) = 0 +[Main(Group2, _, off, off)] _group2 ("Group - Without Toggle", float) = 0 [Sub(Group2)] _float3 ("Float 2", float) = 0 ``` Default result: -![image-20220821235853220](README_CN.assets/image-20220821235853220.png) +![image-20220828003026556](README_CN.assets/image-20220828003026556.png) Then change values: -![image-20220821235941896](README_CN.assets/image-20220821235941896.png) +![image-20220828003129588](README_CN.assets/image-20220828003129588.png) #### SubToggle @@ -165,7 +162,7 @@ For usage, please refer to the Main & Sub example /// group:father group name, support suffix keyword for conditional display (Default: none) /// extraPropName: extra property name (Unity 2019.2+ only) (Default: none) /// Target Property Type: Texture -/// Extra Property Type: Any +/// Extra Property Type: Any, except Texture TexDrawer(string group, string extraPropName) ``` @@ -180,14 +177,18 @@ ColorDrawer(string group, string color2, string color3, string color4) Example: ```c# -[Space(50)] -[Title(_, Tex and Color Samples)] - -[Tex(_, _color)] _tex ("Tex with Color", 2D) = "white" { } +[Main(Group3, _, on)] _group3 ("Group - Tex and Color Samples", float) = 0 +[Tex(Group3, _color)] _tex_color ("Tex with Color", 2D) = "white" { } [HideInInspector] _color (" ", Color) = (1, 0, 0, 1) +[Tex(Group3, _float4)] _tex_float ("Tex with Float", 2D) = "white" { } +[HideInInspector] _float4 (" ", float) = 0 +[Tex(Group3, _range)] _tex_range ("Tex with Range", 2D) = "white" { } +[HideInInspector] _range (" ", Range(0,1)) = 0 +[Tex(Group3, _textureChannelMask1)] _tex_channel ("Tex with Channel", 2D) = "white" { } +[HideInInspector] _textureChannelMask1(" ", Vector) = (0,0,0,1) // Display up to 4 colors in a single line (Unity 2019.2+) -[Color(_, _mColor1, _mColor2, _mColor3)] +[Color(Group3, _mColor1, _mColor2, _mColor3)] _mColor ("Multi Color", Color) = (1, 1, 1, 1) [HideInInspector] _mColor1 (" ", Color) = (1, 0, 0, 1) [HideInInspector] _mColor2 (" ", Color) = (0, 1, 0, 1) @@ -197,12 +198,35 @@ _mColor ("Multi Color", Color) = (1, 1, 1, 1) Result: -![image-20220821233857850](README_CN.assets/image-20220821233857850.png) +![image-20220828003507825](README_CN.assets/image-20220828003507825.png) + +#### Channel + +```c# +/// Draw a R/G/B/A drop menu +/// group:father group name, support suffix keyword for conditional display (Default: none) +/// Target Property Type: Vector, used to dot() with Texture Sample Value +ChannelDrawer(string group) +``` +Example: + +```c# +[Title(_, Channel Samples)] +[Channel(_)]_textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0) + +...... + +float selectedChannelValue = dot(tex2D(_Tex, uv), _textureChannelMask); +``` + + + +![image-20220822010511978](README_CN.assets/image-20220822010511978.png) #### Ramp ```c# -/// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 2 * 512) +/// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 512 * 2) /// group:father group name, support suffix keyword for conditional display (Default: none) /// defaultFileName: default Ramp Map file name when create a new one (Default: RampMap) /// defaultWidth: default Ramp Width (Default: 512) @@ -245,40 +269,18 @@ MinMaxSliderDrawer(string group, string minPropName, string maxPropName) Example: ```c# -[Title(_, MinMaxSlider Samples)] - -[MinMaxSlider(_, _rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0 -[HideInInspector] _rangeStart("Range Start", Range(0.0, 0.5)) = 0.0 -[HideInInspector] _rangeEnd("Range End", Range(0.5, 1.0)) = 1.0 +[Title(MinMaxSlider Samples)] +[MinMaxSlider(_rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0 +_rangeStart("Range Start", Range(0.0, 0.5)) = 0.0 +[PowerSlider(10)] _rangeEnd("Range End PowerSlider", Range(0.5, 1.0)) = 1.0 ``` Result: -![image-20220822004854392](README_CN.assets/image-20220822004854392.png) +![image-20220828003810353](README_CN.assets/image-20220828003810353.png) -#### Channel - -```c# -/// Draw a R/G/B/A drop menu -/// group:father group name, support suffix keyword for conditional display (Default: none) -/// Target Property Type: Vector, used to dot() with Texture Sample Value -ChannelDrawer(string group) -``` -Example: -```c# -[Title(_, Channel Samples)] -[Channel(_)]_textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0) - -...... - -float selectedChannelValue = dot(tex2D(_Tex, uv), _textureChannelMask); -``` - - - -![image-20220822010511978](README_CN.assets/image-20220822010511978.png) #### Title @@ -324,7 +326,7 @@ MaterialIntRangeDrawer() #### KeywordEnum ```c# -MaterialKeywordEnumDrawer(string n1, float v1, string n2, float v2, string n3, float v3, string n4, float v4, string n5, float v5, string n6, float v6, string n7, float v7) +MaterialKeywordEnumDrawer(string kw1, string kw2, string kw3, string kw4, string kw5, string kw6, string kw7, string kw8, string kw9) ``` @@ -347,12 +349,14 @@ MaterialToggleUIDrawer(string keyword) ### Tips -1. SubToggle and SubPower, named 'Sub' + 'built-in Drawer name', have the same Drawer functionality as the built-in version, with the added functionality of being displayed within the fold group. +1. Drawer's first parameter is always `Group`, so when there is only one parameter, the behavior of different Drawers may be different. Therefore, if you want to use Drawers outside the Folding Group, the first parameter is best to give “_”. +1. It is best to use `Title()` instead of the built-in `Header()` , otherwise there will be misplaced. +1. If you change the Shader but the GUI is not updated, manually change the Shader to throw an error, and then change it back to refresh the GUI. ## TODO - [ ] Per material save the Folding Group open state -- [ ] Support for Unreal Style Revertable GUI +- [x] Support for Unreal Style Revertable GUI - [ ] Support for HelpBox - [ ] Support for Tooltip, displays default values and custom content - [ ] Support for upper-right menu, can be all expanded or collapsed diff --git a/README_CN.assets/LWGUI.png b/README_CN.assets/LWGUI.png index d12fe02..fe0dca9 100644 Binary files a/README_CN.assets/LWGUI.png and b/README_CN.assets/LWGUI.png differ diff --git a/README_CN.assets/image-20220821233857850.png b/README_CN.assets/image-20220821233857850.png deleted file mode 100644 index 9abaa66..0000000 Binary files a/README_CN.assets/image-20220821233857850.png and /dev/null differ diff --git a/README_CN.assets/image-20220821235853220.png b/README_CN.assets/image-20220821235853220.png deleted file mode 100644 index fcb050d..0000000 Binary files a/README_CN.assets/image-20220821235853220.png and /dev/null differ diff --git a/README_CN.assets/image-20220821235941896.png b/README_CN.assets/image-20220821235941896.png deleted file mode 100644 index 00cab6c..0000000 Binary files a/README_CN.assets/image-20220821235941896.png and /dev/null differ diff --git a/README_CN.assets/image-20220822004854392.png b/README_CN.assets/image-20220822004854392.png deleted file mode 100644 index ed1f93d..0000000 Binary files a/README_CN.assets/image-20220822004854392.png and /dev/null differ diff --git a/README_CN.assets/image-20220828003026556.png b/README_CN.assets/image-20220828003026556.png new file mode 100644 index 0000000..03d52b2 Binary files /dev/null and b/README_CN.assets/image-20220828003026556.png differ diff --git a/README_CN.assets/image-20220821235941896.png.meta b/README_CN.assets/image-20220828003026556.png.meta similarity index 98% rename from README_CN.assets/image-20220821235941896.png.meta rename to README_CN.assets/image-20220828003026556.png.meta index 7895872..0b1b43d 100644 --- a/README_CN.assets/image-20220821235941896.png.meta +++ b/README_CN.assets/image-20220828003026556.png.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f3ddbefacfdeaab4e81f543dfb905096 +guid: f57598d1ee836e54aada022b23716091 TextureImporter: internalIDToNameTable: [] externalObjects: {} diff --git a/README_CN.assets/image-20220828003129588.png b/README_CN.assets/image-20220828003129588.png new file mode 100644 index 0000000..b47b2c9 Binary files /dev/null and b/README_CN.assets/image-20220828003129588.png differ diff --git a/README_CN.assets/image-20220821233857850.png.meta b/README_CN.assets/image-20220828003129588.png.meta similarity index 98% rename from README_CN.assets/image-20220821233857850.png.meta rename to README_CN.assets/image-20220828003129588.png.meta index f7ad39e..2be749a 100644 --- a/README_CN.assets/image-20220821233857850.png.meta +++ b/README_CN.assets/image-20220828003129588.png.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5fd07127115e9e2458c59779311c4872 +guid: e73a1ef727d62b8489f9a925cfb2392e TextureImporter: internalIDToNameTable: [] externalObjects: {} diff --git a/README_CN.assets/image-20220828003507825.png b/README_CN.assets/image-20220828003507825.png new file mode 100644 index 0000000..56e4b7d Binary files /dev/null and b/README_CN.assets/image-20220828003507825.png differ diff --git a/README_CN.assets/image-20220822004854392.png.meta b/README_CN.assets/image-20220828003507825.png.meta similarity index 98% rename from README_CN.assets/image-20220822004854392.png.meta rename to README_CN.assets/image-20220828003507825.png.meta index 785dfaa..95078e2 100644 --- a/README_CN.assets/image-20220822004854392.png.meta +++ b/README_CN.assets/image-20220828003507825.png.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 076ea2fede91876478268823246dfb41 +guid: 69bfa534b0c16f64f941ac348d81e50d TextureImporter: internalIDToNameTable: [] externalObjects: {} diff --git a/README_CN.assets/image-20220828003810353.png b/README_CN.assets/image-20220828003810353.png new file mode 100644 index 0000000..6a16a41 Binary files /dev/null and b/README_CN.assets/image-20220828003810353.png differ diff --git a/README_CN.assets/image-20220821235853220.png.meta b/README_CN.assets/image-20220828003810353.png.meta similarity index 98% rename from README_CN.assets/image-20220821235853220.png.meta rename to README_CN.assets/image-20220828003810353.png.meta index 865efec..184fa2e 100644 --- a/README_CN.assets/image-20220821235853220.png.meta +++ b/README_CN.assets/image-20220828003810353.png.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4366e06e8466ec74aa7f776eeeeef35e +guid: 7647da0b10087ff4797359b5fcce7b22 TextureImporter: internalIDToNameTable: [] externalObjects: {} diff --git a/README_CN.md b/README_CN.md index d30db79..163ea6a 100644 --- a/README_CN.md +++ b/README_CN.md @@ -10,7 +10,6 @@ ![LWGUI](README_CN.assets/LWGUI.png) -- [LWGUI (Light Weight Shader GUI)](#lwgui--light-weight-shader-gui-) * [Installation](#installation) * [Usage](#usage) + [Getting Started](#getting-started) @@ -20,9 +19,9 @@ - [SubPower](#subpower) - [KWEnum](#kwenum) - [Tex & Color](#tex---color) + - [Channel](#channel) - [Ramp](#ramp) - [MinMaxSlider](#minmaxslider) - - [Channel](#channel) - [Title](#title) + [Unity Builtin Drawers](#unity-builtin-drawers) - [Space](#space) @@ -78,48 +77,46 @@ SubDrawer(string group) Example: -```c -[Title(_, Main Samples)] - +```c# +[Title(Main Samples)] [Main(GroupName)] _group ("Group", float) = 0 [Sub(GroupName)] _float ("Float", float) = 0 -[Main(Group1, _KEYWORD, on)] -_group1 ("Group - Default Open", float) = 1 +[Main(Group1, _KEYWORD, on)] _group1 ("Group - Default Open", float) = 1 [Sub(Group1)] _float1 ("Sub Float", float) = 0 -[Sub(Group1)][HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1) +[Sub(Group1)] _vector1 ("Sub Vector", vector) = (1, 1, 1, 1) +[Sub(Group1)] [HDR] _color1 ("Sub HDR Color", color) = (0.7, 0.7, 1, 1) [Title(Group1, Conditional Display Samples Enum)] [KWEnum(Group1, Name 1, _KEY1, Name 2, _KEY2, Name 3, _KEY3)] -_enum ("Sub Enum", float) = 0 +_enum ("KWEnum", float) = 0 // Display when the keyword ("group name + keyword") is activated [Sub(Group1_KEY1)] _key1_Float1 ("Key1 Float", float) = 0 [Sub(Group1_KEY2)] _key2_Float2 ("Key2 Float", float) = 0 -[Sub(Group1_KEY3)] _key3_Float3 ("Key3 Float", float) = 0 +[Sub(Group1_KEY3)] _key3_Float3_Range ("Key3 Float Range", Range(0, 1)) = 0 [SubPowerSlider(Group1_KEY3, 10)] _key3_Float4_PowerSlider ("Key3 Power Slider", Range(0, 1)) = 0 [Title(Group1, Conditional Display Samples Toggle)] -[SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("Sub Toggle", float) = 0 +[SubToggle(Group1, _TOGGLE_KEYWORD)] _toggle ("SubToggle", float) = 0 [Tex(Group1_TOGGLE_KEYWORD)][Normal] _normal ("Normal Keyword", 2D) = "bump" { } [Sub(Group1_TOGGLE_KEYWORD)] _float2 ("Float Keyword", float) = 0 -[Main(Group2, _, off, off)] -_group2 ("Group - Without Toggle", float) = 0 +[Main(Group2, _, off, off)] _group2 ("Group - Without Toggle", float) = 0 [Sub(Group2)] _float3 ("Float 2", float) = 0 ``` Default result: -![image-20220821235853220](README_CN.assets/image-20220821235853220.png) +![image-20220828003026556](README_CN.assets/image-20220828003026556.png) Then change values: -![image-20220821235941896](README_CN.assets/image-20220821235941896.png) +![image-20220828003129588](README_CN.assets/image-20220828003129588.png) #### SubToggle @@ -165,7 +162,7 @@ KWEnumDrawer(string group, string n1, string k1, string n2, string k2, string n3 /// group:father group name, support suffix keyword for conditional display (Default: none) /// extraPropName: extra property name (Unity 2019.2+ only) (Default: none) /// Target Property Type: Texture -/// Extra Property Type: Any +/// Extra Property Type: Any, except Texture TexDrawer(string group, string extraPropName) ``` @@ -180,14 +177,18 @@ ColorDrawer(string group, string color2, string color3, string color4) Example: ```c# -[Space(50)] -[Title(_, Tex and Color Samples)] - -[Tex(_, _color)] _tex ("Tex with Color", 2D) = "white" { } +[Main(Group3, _, on)] _group3 ("Group - Tex and Color Samples", float) = 0 +[Tex(Group3, _color)] _tex_color ("Tex with Color", 2D) = "white" { } [HideInInspector] _color (" ", Color) = (1, 0, 0, 1) +[Tex(Group3, _float4)] _tex_float ("Tex with Float", 2D) = "white" { } +[HideInInspector] _float4 (" ", float) = 0 +[Tex(Group3, _range)] _tex_range ("Tex with Range", 2D) = "white" { } +[HideInInspector] _range (" ", Range(0,1)) = 0 +[Tex(Group3, _textureChannelMask1)] _tex_channel ("Tex with Channel", 2D) = "white" { } +[HideInInspector] _textureChannelMask1(" ", Vector) = (0,0,0,1) // Display up to 4 colors in a single line (Unity 2019.2+) -[Color(_, _mColor1, _mColor2, _mColor3)] +[Color(Group3, _mColor1, _mColor2, _mColor3)] _mColor ("Multi Color", Color) = (1, 1, 1, 1) [HideInInspector] _mColor1 (" ", Color) = (1, 0, 0, 1) [HideInInspector] _mColor2 (" ", Color) = (0, 1, 0, 1) @@ -197,12 +198,36 @@ _mColor ("Multi Color", Color) = (1, 1, 1, 1) Result: -![image-20220821233857850](README_CN.assets/image-20220821233857850.png) +![image-20220828003507825](README_CN.assets/image-20220828003507825.png) + +#### Channel + +```c# +/// Draw a R/G/B/A drop menu +/// group:father group name, support suffix keyword for conditional display (Default: none) +/// Target Property Type: Vector, used to dot() with Texture Sample Value +ChannelDrawer(string group) +``` + +Example: + +```c# +[Title(_, Channel Samples)] +[Channel(_)]_textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0) + +...... + +float selectedChannelValue = dot(tex2D(_Tex, uv), _textureChannelMask); +``` + + + +![image-20220822010511978](README_CN.assets/image-20220822010511978.png) #### Ramp ```c# -/// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 2 * 512) +/// Draw a Ramp Map Editor (Defaulf Ramp Map Resolution: 512 * 2) /// group:father group name, support suffix keyword for conditional display (Default: none) /// defaultFileName: default Ramp Map file name when create a new one (Default: RampMap) /// defaultWidth: default Ramp Width (Default: 512) @@ -245,40 +270,16 @@ MinMaxSliderDrawer(string group, string minPropName, string maxPropName) Example: ```c# -[Title(_, MinMaxSlider Samples)] - -[MinMaxSlider(_, _rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0 -[HideInInspector] _rangeStart("Range Start", Range(0.0, 0.5)) = 0.0 -[HideInInspector] _rangeEnd("Range End", Range(0.5, 1.0)) = 1.0 +[Title(MinMaxSlider Samples)] +[MinMaxSlider(_rangeStart, _rangeEnd)] _minMaxSlider("Min Max Slider (0 - 1)", Range(0.0, 1.0)) = 1.0 +_rangeStart("Range Start", Range(0.0, 0.5)) = 0.0 +[PowerSlider(10)] _rangeEnd("Range End PowerSlider", Range(0.5, 1.0)) = 1.0 ``` Result: -![image-20220822004854392](README_CN.assets/image-20220822004854392.png) - -#### Channel - -```c# -/// Draw a R/G/B/A drop menu -/// group:father group name, support suffix keyword for conditional display (Default: none) -/// Target Property Type: Vector, used to dot() with Texture Sample Value -ChannelDrawer(string group) -``` -Example: - -```c# -[Title(_, Channel Samples)] -[Channel(_)]_textureChannelMask("Texture Channel Mask (Default G)", Vector) = (0,1,0,0) - -...... - -float selectedChannelValue = dot(tex2D(_Tex, uv), _textureChannelMask); -``` - - - -![image-20220822010511978](README_CN.assets/image-20220822010511978.png) +![image-20220828003810353](README_CN.assets/image-20220828003810353.png) #### Title @@ -324,7 +325,7 @@ MaterialIntRangeDrawer() #### KeywordEnum ```c# -MaterialKeywordEnumDrawer(string n1, float v1, string n2, float v2, string n3, float v3, string n4, float v4, string n5, float v5, string n6, float v6, string n7, float v7) +MaterialKeywordEnumDrawer(string kw1, string kw2, string kw3, string kw4, string kw5, string kw6, string kw7, string kw8, string kw9) ``` @@ -347,14 +348,16 @@ MaterialToggleUIDrawer(string keyword) ### Tips -1. SubToggle和SubPower这种以”Sub”+”内置Drawer”命名的Drawer功能与内置版本相同, 只增加了在折叠组内显示的功能 +1. Drawer的第一个参数永远是`group`, 所以在只有一个参数的情况下, 不同Drawer的行为可能不同, 因此如果要在折叠组外使用Drawer, 第一个参数最好赋予“_” +1. 最好使用Title()替代内置的Header(), 否则会有错位 +1. 如果出现改了Shader但GUI没有更新的情况请手动修改Shader使其报错, 然后再改回来以刷新GUI ## TODO - [ ] 支持ShaderGraph or ASE - [ ] per material保存折叠组打开状态 -- [ ] 支持Unreal风格的Revertable GUI +- [x] 支持Unreal风格的Revertable GUI - [ ] 支持HelpBox - [ ] 支持改文字格式 - [ ] 支持Tooltip, 显示默认值和自定义内容 diff --git a/package.json b/package.json index c08ff1e..e9637f2 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "com.jasonma.lwgui", - "version": "0.1.0", + "version": "1.0.0", "displayName": "LWGUI", - "description": "A Lightweight, Flexible, Powerful and Subversive Shader GUI System for Unity.", + "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [ "shader", "gui"