From 73b0cc28f3ac4b9245f07d4c9836277014d92e03 Mon Sep 17 00:00:00 2001 From: JasonMa <1312119064@qq.com> Date: Tue, 27 Jun 2023 19:31:20 +0800 Subject: [PATCH] - fix new ramp map alpha - internal to public --- Editor/GroupStateHelper.cs | 2 +- Editor/Helper.cs | 2 +- Editor/LWGUI.cs | 6 ++--- Editor/MetaDataHelper.cs | 2 +- Editor/PresetHelper.cs | 2 +- Editor/RampHelper.cs | 26 +++++++++++------- Editor/ReflectionHelper.cs | 2 +- Editor/RevertableHelper.cs | 2 +- Editor/ShaderDrawer.cs | 49 ++++++++++++++++++++-------------- Editor/ShaderPropertyPreset.cs | 2 +- Editor/VersionControlHelper.cs | 2 +- package.json | 2 +- 12 files changed, 57 insertions(+), 42 deletions(-) diff --git a/Editor/GroupStateHelper.cs b/Editor/GroupStateHelper.cs index f2a6b7e..a026daa 100644 --- a/Editor/GroupStateHelper.cs +++ b/Editor/GroupStateHelper.cs @@ -4,7 +4,7 @@ namespace LWGUI { - internal class GroupStateHelper + public class GroupStateHelper { // Used to Folding Group, key: group name, value: is folding private static Dictionary> _groups = new Dictionary>(); diff --git a/Editor/Helper.cs b/Editor/Helper.cs index 5858012..5c4e288 100644 --- a/Editor/Helper.cs +++ b/Editor/Helper.cs @@ -8,7 +8,7 @@ namespace LWGUI /// /// Misc Function /// - internal class Helper + public class Helper { #region Engine Misc diff --git a/Editor/LWGUI.cs b/Editor/LWGUI.cs index 44e5db3..74662fe 100644 --- a/Editor/LWGUI.cs +++ b/Editor/LWGUI.cs @@ -10,19 +10,19 @@ namespace LWGUI { /// when LwguiEventType.Init: get all metadata from drawer /// when LwguiEventType.Repaint: LWGUI decides how to draw each prop according to metadata - internal enum LwguiEventType + public enum LwguiEventType { Init, Repaint } - internal enum SearchMode + public enum SearchMode { All, Modified } - internal class LWGUI : ShaderGUI + public class LWGUI : ShaderGUI { public MaterialProperty[] props; public MaterialEditor materialEditor; diff --git a/Editor/MetaDataHelper.cs b/Editor/MetaDataHelper.cs index 46303a1..f6bce22 100644 --- a/Editor/MetaDataHelper.cs +++ b/Editor/MetaDataHelper.cs @@ -9,7 +9,7 @@ namespace LWGUI /// /// Provide Metadata for drawing /// - internal class MetaDataHelper + public class MetaDataHelper { #region Meta Data Container diff --git a/Editor/PresetHelper.cs b/Editor/PresetHelper.cs index 6ae86c6..4af4580 100644 --- a/Editor/PresetHelper.cs +++ b/Editor/PresetHelper.cs @@ -5,7 +5,7 @@ namespace LWGUI { - internal class PresetHelper + public class PresetHelper { private static Dictionary _loadedPresets = new Dictionary(); diff --git a/Editor/RampHelper.cs b/Editor/RampHelper.cs index 0d4ad8e..ec4bcc9 100644 --- a/Editor/RampHelper.cs +++ b/Editor/RampHelper.cs @@ -7,7 +7,7 @@ namespace LWGUI { - internal partial class RampHelper + public class RampHelper { #region RampEditor [Serializable] @@ -101,7 +101,7 @@ public static bool RampEditor( //Create texture and save PNG var saveUnityPath = absPath.Replace(projectPath, String.Empty); CreateAndSaveNewGradientTexture(defaultWidth, defaultHeight, saveUnityPath); - VersionControlHelper.Add(saveUnityPath); + // VersionControlHelper.Add(saveUnityPath); //Load created texture newTexture = AssetDatabase.LoadAssetAtPath(saveUnityPath); break; @@ -162,8 +162,8 @@ public static void SetGradientToTexture(Texture texture, GradientObject gradient // Save to texture var path = AssetDatabase.GetAssetPath(texture); var pixels = GetPixelsFromGradient(gradientObject.gradient, texture.width, texture.height); - texture2D.SetPixels(pixels); - texture2D.Apply(true, false); + texture2D.SetPixels32(pixels); + texture2D.Apply(); // Save gradient JSON to userData var assetImporter = AssetImporter.GetAtPath(path); @@ -224,6 +224,12 @@ public static bool CreateAndSaveNewGradientTexture(int width, int height, string textureImporter.isReadable = true; textureImporter.textureCompression = TextureImporterCompression.Uncompressed; textureImporter.alphaSource = TextureImporterAlphaSource.FromInput; + textureImporter.mipmapEnabled = false; + + var platformTextureSettings = textureImporter.GetDefaultPlatformTextureSettings(); + platformTextureSettings.format = TextureImporterFormat.ARGB32; + platformTextureSettings.textureCompression = TextureImporterCompression.Uncompressed; + textureImporter.SetPlatformTextureSettings(platformTextureSettings); //Gradient data embedded in userData textureImporter.userData = EncodeGradientToJSON(gradientObject, gradientObject); @@ -236,14 +242,14 @@ private static Texture2D CreateGradientTexture(Gradient gradient, int width, int { var ramp = new Texture2D(width, height, TextureFormat.RGBA32, true, true); var colors = GetPixelsFromGradient(gradient, width, height); - ramp.SetPixels(colors); - ramp.Apply(true); + ramp.SetPixels32(colors); + ramp.Apply(); return ramp; } - private static Color[] GetPixelsFromGradient(Gradient gradient, int width, int height) + private static Color32[] GetPixelsFromGradient(Gradient gradient, int width, int height) { - var pixels = new Color[width * height]; + var pixels = new Color32[width * height]; for (var x = 0; x < width; x++) { var delta = x / (float)width; @@ -287,7 +293,7 @@ public static void RampSelector(Rect rect, string rootPath, SwitchRampMapEvent s #endregion } - internal class RampSelectorWindow : EditorWindow + public class RampSelectorWindow : EditorWindow { private Texture2D[] _rampMaps; private Vector2 _scrollPosition; @@ -297,7 +303,7 @@ public static void ShowWindow(Rect rect, Texture2D[] rampMaps, RampHelper.Switch { RampSelectorWindow window = ScriptableObject.CreateInstance(); window.titleContent = new GUIContent("Ramp Selector"); - // window.minSize = new Vector2(250, 1000); + window.minSize = new Vector2(400, 500); window._rampMaps = rampMaps; window._switchRampMapEvent = switchRampMapEvent; window.ShowAuxWindow(); diff --git a/Editor/ReflectionHelper.cs b/Editor/ReflectionHelper.cs index 1a2032d..a7bf6a9 100644 --- a/Editor/ReflectionHelper.cs +++ b/Editor/ReflectionHelper.cs @@ -7,7 +7,7 @@ namespace LWGUI { - internal class ReflectionHelper + public class ReflectionHelper { private static Assembly UnityEditor_Assembly = Assembly.GetAssembly(typeof(Editor)); diff --git a/Editor/RevertableHelper.cs b/Editor/RevertableHelper.cs index 6fa5ea6..c0d0dad 100644 --- a/Editor/RevertableHelper.cs +++ b/Editor/RevertableHelper.cs @@ -10,7 +10,7 @@ namespace LWGUI /// /// Helpers for drawing Unreal Style Revertable Shader GUI /// - internal class RevertableHelper + public class RevertableHelper { public static readonly float revertButtonWidth = 15f; public static float fieldWidth; diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index 3abbc80..10f80ad 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -9,7 +9,7 @@ namespace LWGUI { - internal interface IBaseDrawer + public interface IBaseDrawer { void InitMetaData(Shader inShader, Material inMaterial, MaterialProperty inProp, MaterialProperty[] inProps); } @@ -22,7 +22,7 @@ internal interface IBaseDrawer /// default Toggle Displayed: "on" or "off" (Default: on) /// Target Property Type: FLoat, express Toggle value /// - internal class MainDrawer : MaterialPropertyDrawer, IBaseDrawer + public class MainDrawer : MaterialPropertyDrawer, IBaseDrawer { protected MaterialProperty[] props; protected LWGUI lwgui; @@ -107,7 +107,7 @@ public override void Apply(MaterialProperty prop) /// group:father group name, support suffix keyword for conditional display (Default: none) /// Target Property Type: Any /// - internal class SubDrawer : MaterialPropertyDrawer, IBaseDrawer + public class SubDrawer : MaterialPropertyDrawer, IBaseDrawer { protected string group = String.Empty; protected MaterialProperty prop; @@ -194,7 +194,7 @@ public virtual void DrawProp(Rect position, MaterialProperty prop, GUIContent la /// keyword:keyword used for toggle, "_" = ignore, none or "__" = Property Name + "_ON", always Upper (Default: none) /// Target Property Type: FLoat /// - internal class SubToggleDrawer : SubDrawer + public class SubToggleDrawer : SubDrawer { private string _keyWord = String.Empty; @@ -247,7 +247,7 @@ public override void Apply(MaterialProperty prop) /// power: power of slider (Default: 1) /// Target Property Type: Range /// - internal class SubPowerSliderDrawer : SubDrawer + public class SubPowerSliderDrawer : SubDrawer { private float _power = 1; @@ -276,7 +276,7 @@ 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: Range /// - internal class SubIntRangeDrawer : SubDrawer + public class SubIntRangeDrawer : SubDrawer { public SubIntRangeDrawer(string group) { @@ -317,7 +317,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// v(s): value /// Target Property Type: FLoat, express current keyword index /// - internal class KWEnumDrawer : SubDrawer + public class KWEnumDrawer : SubDrawer { private GUIContent[] _names; private string[] _keyWords; @@ -451,7 +451,7 @@ public override void Apply(MaterialProperty prop) } } - internal class SubEnumDrawer : KWEnumDrawer + public class SubEnumDrawer : KWEnumDrawer { // UnityEditor.MaterialEnumDrawer(string enumName) // enumName: like "UnityEngine.Rendering.BlendMode" @@ -493,7 +493,7 @@ public SubEnumDrawer(string group, string n1, float v1, string n2, float v2, str public override void Apply(MaterialProperty prop) { } } - internal class SubKeywordEnumDrawer : KWEnumDrawer + public class SubKeywordEnumDrawer : KWEnumDrawer { public SubKeywordEnumDrawer(string group, string kw1, string kw2) : base(group, new []{kw1, kw2}, new []{kw1, kw2}) { } @@ -522,7 +522,7 @@ public SubKeywordEnumDrawer(string group, string kw1, string kw2, string kw3, st /// Target Property Type: Texture /// Extra Property Type: Any, except Texture /// - internal class TexDrawer : SubDrawer + public class TexDrawer : SubDrawer { private string _extraPropName = String.Empty; private ChannelDrawer _channelDrawer = new ChannelDrawer("_"); @@ -626,7 +626,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// color2-4: extra color property name (Unity 2019.2+ only) /// Target Property Type: Color /// - internal class ColorDrawer : SubDrawer + public class ColorDrawer : SubDrawer { private string[] _colorStrings = new string[3]; @@ -733,7 +733,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// defaultWidth: default Ramp Width (Default: 512) /// Target Property Type: Texture2D /// - internal class RampDrawer : SubDrawer + public class RampDrawer : SubDrawer { protected static readonly string DefaultRootPath = "Assets"; @@ -773,6 +773,8 @@ protected virtual void OnSwitchRampMap(Texture newTexture) { } protected virtual void OnCreateNewRampMap(Texture newTexture) { } + protected virtual void OnEditRampMap() { } + // TODO: undo public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { @@ -841,6 +843,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l serializedObject.ApplyModifiedProperties(); // GradientObject > Tex RampHelper.SetGradientToTexture(prop.textureValue, gradientObject, doSaveGradient); + OnEditRampMap(); } // Discard gradient changes @@ -851,6 +854,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l // GradientObject > SerializedObject serializedObject.Update(); RampHelper.SetGradientToTexture(prop.textureValue, gradientObject, true); + OnEditRampMap(); } @@ -865,7 +869,12 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l EditorGUI.BeginChangeCheck(); var newManualSelectedTexture = (Texture2D)EditorGUI.ObjectField(rampFieldRect, prop.textureValue, typeof(Texture2D), false); if (EditorGUI.EndChangeCheck()) - OnSwitchRampMapEvent(newManualSelectedTexture); + { + if (AssetDatabase.GetAssetPath(newManualSelectedTexture).StartsWith(_rootPath)) + OnSwitchRampMapEvent(newManualSelectedTexture); + else + EditorUtility.DisplayDialog("Invalid Path", "Please select the subdirectory of '" + _rootPath + "'", "OK"); + } } @@ -891,7 +900,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// Target Property Type: Range, range limits express the MinMaxSlider value range /// Output Min/Max Property Type: Range, it's value is limited by it's range /// - internal class MinMaxSliderDrawer : SubDrawer + public class MinMaxSliderDrawer : SubDrawer { private string _minPropName; private string _maxPropName; @@ -996,7 +1005,7 @@ 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 /// - internal class ChannelDrawer : SubDrawer + public class ChannelDrawer : SubDrawer { private static GUIContent[] _names = new[] { new GUIContent("R"), @@ -1078,7 +1087,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// "Right Click > Create > LWGUI > Shader Property Preset" in Project window, /// *any Preset in the entire project cannot have the same name* /// - internal class PresetDrawer : SubDrawer + public class PresetDrawer : SubDrawer { public string presetFileName; public PresetDrawer(string presetFileName) : this("_", presetFileName) {} @@ -1150,7 +1159,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// header: string to display, "SpaceLine" or "_" = none (Default: none) /// height: line height (Default: 22) /// - internal class TitleDecorator : SubDrawer + public class TitleDecorator : SubDrawer { private string _header; private float _height; @@ -1186,7 +1195,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// Cooperate with Toggle to switch certain Passes /// lightModeName(s): Light Mode in Shader Pass (https://docs.unity3d.com/2017.4/Documentation/Manual/SL-PassTags.html) /// - internal class PassSwitchDecorator : SubDrawer + public class PassSwitchDecorator : SubDrawer { private string[] _lightModeNames; @@ -1231,7 +1240,7 @@ public override void Apply(MaterialProperty prop) /// You can also use "#Text" in DisplayName to add Tooltip that supports Multi-Language. /// tooltip:a single-line string to display, support up to 4 ','. (Default: Newline) /// - internal class TooltipDecorator : SubDrawer + public class TooltipDecorator : SubDrawer { private string _tooltip; @@ -1267,7 +1276,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l /// You can also use "%Text" in DisplayName to add Helpbox that supports Multi-Language. /// message:a single-line string to display, support up to 4 ','. (Default: Newline) /// - internal class HelpboxDecorator : TooltipDecorator + public class HelpboxDecorator : TooltipDecorator { private string _message; diff --git a/Editor/ShaderPropertyPreset.cs b/Editor/ShaderPropertyPreset.cs index bb0c240..c197802 100644 --- a/Editor/ShaderPropertyPreset.cs +++ b/Editor/ShaderPropertyPreset.cs @@ -9,7 +9,7 @@ namespace LWGUI { [CreateAssetMenu(fileName = "LWGUI_ShaderPropertyPreset.asset", menuName = "LWGUI/Shader Property Preset")] - internal class ShaderPropertyPreset : ScriptableObject + public class ShaderPropertyPreset : ScriptableObject { public enum PropertyType { diff --git a/Editor/VersionControlHelper.cs b/Editor/VersionControlHelper.cs index 3fa7e23..1bd86e6 100644 --- a/Editor/VersionControlHelper.cs +++ b/Editor/VersionControlHelper.cs @@ -4,7 +4,7 @@ namespace LWGUI { - internal class VersionControlHelper + public class VersionControlHelper { public static bool isVCEnabled { get { return Provider.enabled && Provider.isActive; } } diff --git a/package.json b/package.json index 0e2ba6f..68d2e2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.jasonma.lwgui", - "version": "1.8.1", + "version": "1.8.2", "displayName": "LWGUI", "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [