Skip to content

Commit

Permalink
Merge pull request #33 from JasonMa0012/dev
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
JasonMa0012 authored Jun 27, 2023
2 parents db73321 + 73b0cc2 commit b72ec6a
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Editor/GroupStateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object, Dictionary<string, bool>> _groups = new Dictionary<Object, Dictionary<string, bool>>();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LWGUI
/// <summary>
/// Misc Function
/// </summary>
internal class Helper
public class Helper
{
#region Engine Misc

Expand Down
6 changes: 3 additions & 3 deletions Editor/LWGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Editor/MetaDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LWGUI
/// <summary>
/// Provide Metadata for drawing
/// </summary>
internal class MetaDataHelper
public class MetaDataHelper
{
#region Meta Data Container

Expand Down
2 changes: 1 addition & 1 deletion Editor/PresetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace LWGUI
{
internal class PresetHelper
public class PresetHelper
{
private static Dictionary<string /*FileName*/, ShaderPropertyPreset> _loadedPresets = new Dictionary<string, ShaderPropertyPreset>();

Expand Down
26 changes: 16 additions & 10 deletions Editor/RampHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace LWGUI
{
internal partial class RampHelper
public class RampHelper
{
#region RampEditor
[Serializable]
Expand Down Expand Up @@ -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<Texture2D>(saveUnityPath);
break;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -297,7 +303,7 @@ public static void ShowWindow(Rect rect, Texture2D[] rampMaps, RampHelper.Switch
{
RampSelectorWindow window = ScriptableObject.CreateInstance<RampSelectorWindow>();
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();
Expand Down
2 changes: 1 addition & 1 deletion Editor/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace LWGUI
{
internal class ReflectionHelper
public class ReflectionHelper
{
private static Assembly UnityEditor_Assembly = Assembly.GetAssembly(typeof(Editor));

Expand Down
2 changes: 1 addition & 1 deletion Editor/RevertableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LWGUI
/// <summary>
/// Helpers for drawing Unreal Style Revertable Shader GUI
/// </summary>
internal class RevertableHelper
public class RevertableHelper
{
public static readonly float revertButtonWidth = 15f;
public static float fieldWidth;
Expand Down
59 changes: 34 additions & 25 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace LWGUI
{
internal interface IBaseDrawer
public interface IBaseDrawer
{
void InitMetaData(Shader inShader, Material inMaterial, MaterialProperty inProp, MaterialProperty[] inProps);
}
Expand All @@ -22,7 +22,7 @@ internal interface IBaseDrawer
/// default Toggle Displayed: "on" or "off" (Default: on)
/// Target Property Type: FLoat, express Toggle value
/// </summary>
internal class MainDrawer : MaterialPropertyDrawer, IBaseDrawer
public class MainDrawer : MaterialPropertyDrawer, IBaseDrawer
{
protected MaterialProperty[] props;
protected LWGUI lwgui;
Expand Down Expand Up @@ -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
/// </summary>
internal class SubDrawer : MaterialPropertyDrawer, IBaseDrawer
public class SubDrawer : MaterialPropertyDrawer, IBaseDrawer
{
protected string group = String.Empty;
protected MaterialProperty prop;
Expand Down Expand Up @@ -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
/// </summary>
internal class SubToggleDrawer : SubDrawer
public class SubToggleDrawer : SubDrawer
{
private string _keyWord = String.Empty;

Expand Down Expand Up @@ -247,7 +247,7 @@ public override void Apply(MaterialProperty prop)
/// power: power of slider (Default: 1)
/// Target Property Type: Range
/// </summary>
internal class SubPowerSliderDrawer : SubDrawer
public class SubPowerSliderDrawer : SubDrawer
{
private float _power = 1;

Expand Down Expand Up @@ -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
/// </summary>
internal class SubIntRangeDrawer : SubDrawer
public class SubIntRangeDrawer : SubDrawer
{
public SubIntRangeDrawer(string group)
{
Expand Down Expand Up @@ -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
/// </summary>
internal class KWEnumDrawer : SubDrawer
public class KWEnumDrawer : SubDrawer
{
private GUIContent[] _names;
private string[] _keyWords;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}) { }
Expand Down Expand Up @@ -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
/// </summary>
internal class TexDrawer : SubDrawer
public class TexDrawer : SubDrawer
{
private string _extraPropName = String.Empty;
private ChannelDrawer _channelDrawer = new ChannelDrawer("_");
Expand Down Expand Up @@ -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
/// </summary>
internal class ColorDrawer : SubDrawer
public class ColorDrawer : SubDrawer
{
private string[] _colorStrings = new string[3];

Expand Down Expand Up @@ -733,14 +733,14 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l
/// defaultWidth: default Ramp Width (Default: 512)
/// Target Property Type: Texture2D
/// </summary>
internal class RampDrawer : SubDrawer
public class RampDrawer : SubDrawer
{
private static readonly string DefaultRootPath = "Assets";
protected static readonly string DefaultRootPath = "Assets";

private string _rootPath;
private string _defaultFileName;
private float _defaultWidth;
private float _defaultHeight = 2;
protected string _rootPath;
protected string _defaultFileName;
protected float _defaultWidth;
protected float _defaultHeight = 2;

private static readonly GUIContent _iconMixImage = EditorGUIUtility.IconContent("darkviewbackground");

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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();
}


Expand All @@ -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");
}
}


Expand All @@ -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
/// </summary>
internal class MinMaxSliderDrawer : SubDrawer
public class MinMaxSliderDrawer : SubDrawer
{
private string _minPropName;
private string _maxPropName;
Expand Down Expand Up @@ -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
/// </summary>
internal class ChannelDrawer : SubDrawer
public class ChannelDrawer : SubDrawer
{
private static GUIContent[] _names = new[] {
new GUIContent("R"),
Expand Down Expand Up @@ -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*
/// </summary>
internal class PresetDrawer : SubDrawer
public class PresetDrawer : SubDrawer
{
public string presetFileName;
public PresetDrawer(string presetFileName) : this("_", presetFileName) {}
Expand Down Expand Up @@ -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)
/// </summary>
internal class TitleDecorator : SubDrawer
public class TitleDecorator : SubDrawer
{
private string _header;
private float _height;
Expand Down Expand Up @@ -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)
/// </summary>
internal class PassSwitchDecorator : SubDrawer
public class PassSwitchDecorator : SubDrawer
{
private string[] _lightModeNames;

Expand Down Expand Up @@ -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)
/// </summary>
internal class TooltipDecorator : SubDrawer
public class TooltipDecorator : SubDrawer
{
private string _tooltip;

Expand Down Expand Up @@ -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)
/// </summary>
internal class HelpboxDecorator : TooltipDecorator
public class HelpboxDecorator : TooltipDecorator
{
private string _message;

Expand Down
2 changes: 1 addition & 1 deletion Editor/ShaderPropertyPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion Editor/VersionControlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LWGUI
{
internal class VersionControlHelper
public class VersionControlHelper
{
public static bool isVCEnabled { get { return Provider.enabled && Provider.isActive; } }

Expand Down
Loading

0 comments on commit b72ec6a

Please sign in to comment.