From 4c50234faa69016d1088d48ebcc15869a2ad6828 Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Thu, 15 Aug 2024 17:24:45 +0800 Subject: [PATCH] Fix missing icons --- Editor/Helper/Helper.cs | 49 +++++++++++++++++++++---------- Editor/Helper/RevertableHelper.cs | 3 +- Editor/ShaderDrawer.cs | 16 +++++----- package.json | 2 +- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Editor/Helper/Helper.cs b/Editor/Helper/Helper.cs index 30e9e37..929db62 100644 --- a/Editor/Helper/Helper.cs +++ b/Editor/Helper/Helper.cs @@ -325,8 +325,9 @@ public static void DrawHelpbox(PropertyStaticData propertyStaticData, PropertyDy } private static Texture _logoCache; + private static GUIContent _logoGuiContentCache; private static Texture _logo => _logoCache = _logoCache ?? AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("26b9d845eb7b1a747bf04dc84e5bcc2c")); - private static GUIContent _logoGuiContent = new GUIContent(string.Empty, _logo, + private static GUIContent _logoGuiContent => _logoGuiContentCache = _logoGuiContentCache ?? new GUIContent(string.Empty, _logo, "LWGUI (Light Weight Shader GUI)\n\n" + "A Lightweight, Flexible, Powerful Unity Shader GUI system.\n\n" + "Copyright (c) Jason Ma"); @@ -352,21 +353,37 @@ public static void DrawLogo() private static Material _copiedMaterial; private static List _copiedProps = new List(); - private static Texture _iconCopy = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("9cdef444d18d2ce4abb6bbc4fed4d109")); - private static Texture _iconPaste = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("8e7a78d02e4c3574998524a0842a8ccb")); - private static Texture _iconSelect = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("6f44e40b24300974eb607293e4224ecc")); - private static Texture _iconCheckout = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("72488141525eaa8499e65e52755cb6d0")); - private static Texture _iconExpand = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("2382450e7f4ddb94c9180d6634c41378")); - private static Texture _iconCollapse = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("929b6e5dfacc42b429d715a3e1ca2b57")); - private static Texture _iconVisibility = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("9576e23a695b35d49a9fc55c9a948b4f")); - - private static GUIContent _guiContentCopy = new GUIContent("", _iconCopy, "Copy Material Properties"); - private static GUIContent _guiContentPaste = new GUIContent("", _iconPaste, "Paste Material Properties\n\nRight-click to paste values by type."); - private static GUIContent _guiContentSelect = new GUIContent("", _iconSelect, "Select the Material Asset\n\nUsed to jump from a Runtime Material Instance to a Material Asset."); - private static GUIContent _guiContentChechout = new GUIContent("", _iconCheckout, "Checkout selected Material Assets"); - private static GUIContent _guiContentExpand = new GUIContent("", _iconExpand, "Expand All Groups"); - private static GUIContent _guiContentCollapse = new GUIContent("", _iconCollapse, "Collapse All Groups"); - private static GUIContent _guiContentVisibility = new GUIContent("", _iconVisibility, "Display Mode"); + private const string _iconCopyGUID = "9cdef444d18d2ce4abb6bbc4fed4d109"; + private const string _iconPasteGUID = "8e7a78d02e4c3574998524a0842a8ccb"; + private const string _iconSelectGUID = "6f44e40b24300974eb607293e4224ecc"; + private const string _iconCheckoutGUID = "72488141525eaa8499e65e52755cb6d0"; + private const string _iconExpandGUID = "2382450e7f4ddb94c9180d6634c41378"; + private const string _iconCollapseGUID = "929b6e5dfacc42b429d715a3e1ca2b57"; + private const string _iconVisibilityGUID = "9576e23a695b35d49a9fc55c9a948b4f"; + + private const string _iconCopyTooltip = "Copy Material Properties"; + private const string _iconPasteTooltip = "Paste Material Properties\n\nRight-click to paste values by type."; + private const string _iconSelectTooltip = "Select the Material Asset\n\nUsed to jump from a Runtime Material Instance to a Material Asset."; + private const string _iconCheckoutTooltip = "Checkout selected Material Assets"; + private const string _iconExpandTooltip = "Expand All Groups"; + private const string _iconCollapseTooltip = "Collapse All Groups"; + private const string _iconVisibilityTooltip = "Display Mode"; + + private static GUIContent _guiContentCopyCache; + private static GUIContent _guiContentPasteCache; + private static GUIContent _guiContentSelectCache; + private static GUIContent _guiContentChechoutCache; + private static GUIContent _guiContentExpandCache; + private static GUIContent _guiContentCollapseCache; + private static GUIContent _guiContentVisibilityCache; + + private static GUIContent _guiContentCopy => _guiContentCopyCache = _guiContentCopyCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconCopyGUID)), _iconCopyTooltip); + private static GUIContent _guiContentPaste => _guiContentPasteCache = _guiContentPasteCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconPasteGUID)), _iconPasteTooltip); + private static GUIContent _guiContentSelect => _guiContentSelectCache = _guiContentSelectCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconSelectGUID)), _iconSelectTooltip); + private static GUIContent _guiContentChechout => _guiContentChechoutCache = _guiContentChechoutCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconCheckoutGUID)), _iconCheckoutTooltip); + private static GUIContent _guiContentExpand => _guiContentExpandCache = _guiContentExpandCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconExpandGUID)), _iconExpandTooltip); + private static GUIContent _guiContentCollapse => _guiContentCollapseCache = _guiContentCollapseCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconCollapseGUID)), _iconCollapseTooltip); + private static GUIContent _guiContentVisibility => _guiContentVisibilityCache = _guiContentVisibilityCache ?? new GUIContent("", AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(_iconVisibilityGUID)), _iconVisibilityTooltip); private enum CopyMaterialValueMask diff --git a/Editor/Helper/RevertableHelper.cs b/Editor/Helper/RevertableHelper.cs index 815ae2e..908cc01 100644 --- a/Editor/Helper/RevertableHelper.cs +++ b/Editor/Helper/RevertableHelper.cs @@ -160,7 +160,8 @@ private static void DoRevertProperty(MaterialProperty prop, LWGUIMetaDatas metaD } } - private static readonly Texture _icon = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("e7bc1130858d984488bca32b8512ca96")); + private static Texture _iconCache; + private static Texture _icon => _iconCache = _iconCache ?? AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("e7bc1130858d984488bca32b8512ca96")); public static bool DrawRevertButton(Rect rect) { diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index d88c634..c687855 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -768,7 +768,7 @@ public override void BuildStaticMetaData(Shader inShader, MaterialProperty inPro public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { - Stack cProps = new Stack(); + var cProps = new Stack(); for (int i = 0; i < 4; i++) { if (i == 0) @@ -782,27 +782,25 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l cProps.Push(p); } - int count = cProps.Count; + var count = cProps.Count; var colorArray = cProps.ToArray(); - var rect = position; //EditorGUILayout.GetControlRect(); - EditorGUI.PrefixLabel(rect, label); + EditorGUI.PrefixLabel(position, label); for (int i = 0; i < count; i++) { EditorGUI.BeginChangeCheck(); var cProp = colorArray[i]; EditorGUI.showMixedValue = cProp.hasMixedValue; - Rect r = new Rect(rect); + var r = new Rect(position); var interval = 13 * i * (-0.25f + EditorGUI.indentLevel * 1.25f); - float w = EditorGUIUtility.fieldWidth * (0.8f + EditorGUI.indentLevel * 0.2f); + var w = EditorGUIUtility.fieldWidth * (0.8f + EditorGUI.indentLevel * 0.2f); r.xMin += r.width - w * (i + 1) + interval; r.xMax -= w * i - interval; - Color src, dst; - src = cProp.colorValue; + var src = cProp.colorValue; var isHdr = (colorArray[i].flags & MaterialProperty.PropFlags.HDR) != MaterialProperty.PropFlags.None; - dst = EditorGUI.ColorField(r, GUIContent.none, src, true, true, isHdr); + var dst = EditorGUI.ColorField(r, GUIContent.none, src, true, true, isHdr); if (Helper.EndChangeCheck(metaDatas, cProp)) { cProp.colorValue = dst; diff --git a/package.json b/package.json index 8987581..1b5385b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.jasonma.lwgui", - "version": "1.18.5", + "version": "1.18.6", "displayName": "LWGUI", "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [