From 617eb096c49721d121500ae1df23172480087c56 Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Wed, 24 Jul 2024 18:23:44 +0800 Subject: [PATCH] Fix null reference errors --- Editor/Helper/Helper.cs | 56 ++++++++--------------------------------- package.json | 2 +- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/Editor/Helper/Helper.cs b/Editor/Helper/Helper.cs index a9c2e95..30e9e37 100644 --- a/Editor/Helper/Helper.cs +++ b/Editor/Helper/Helper.cs @@ -177,57 +177,22 @@ public static float PowPreserveSign(float f, float p) // Tips: Use properties to fix null reference errors private static GUIStyle _guiStyles_IconButton; - - public static GUIStyle guiStyles_IconButton - { - get - { - if (_guiStyles_IconButton == null) - { - _guiStyles_IconButton = new GUIStyle(EditorStyles.iconButton) { fixedHeight = 0, fixedWidth = 0 }; - } - return _guiStyles_IconButton; - } - } + public static GUIStyle guiStyles_IconButton => _guiStyles_IconButton ?? new GUIStyle(EditorStyles.iconButton) { fixedHeight = 0, fixedWidth = 0 }; private static GUIStyle _guiStyle_Foldout; - - public static GUIStyle guiStyle_Foldout + public static GUIStyle guiStyle_Foldout => _guiStyle_Foldout ?? new GUIStyle(EditorStyles.miniButton) { - get - { - if (_guiStyle_Foldout == null) - { - _guiStyle_Foldout = - new GUIStyle(EditorStyles.miniButton) - { - contentOffset = new Vector2(22, 0), - fixedHeight = 27, - alignment = TextAnchor.MiddleLeft, - font = EditorStyles.boldLabel.font, - fontSize = EditorStyles.boldLabel.fontSize + 1, - }; - } - return _guiStyle_Foldout; - } - } + contentOffset = new Vector2(22, 0), + fixedHeight = 27, + alignment = TextAnchor.MiddleLeft, + font = EditorStyles.boldLabel.font, + fontSize = EditorStyles.boldLabel.fontSize + 1 + }; private static GUIStyle _guiStyle_Helpbox; - - public static GUIStyle guiStyle_Helpbox - { - get - { - if (_guiStyle_Helpbox == null) - { - _guiStyle_Helpbox = new GUIStyle(EditorStyles.helpBox) { fontSize = 12 }; - } - return _guiStyle_Helpbox; - } - } + public static GUIStyle guiStyle_Helpbox => _guiStyle_Helpbox ?? new GUIStyle(EditorStyles.helpBox) { fontSize = 12 }; private static GUIStyle _guiStyles_ToolbarSearchTextFieldPopup; - public static GUIStyle guiStyles_ToolbarSearchTextFieldPopup { get @@ -359,7 +324,8 @@ public static void DrawHelpbox(PropertyStaticData propertyStaticData, PropertyDy } } - private static Texture _logo = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("26b9d845eb7b1a747bf04dc84e5bcc2c")); + private static Texture _logoCache; + private static Texture _logo => _logoCache = _logoCache ?? AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("26b9d845eb7b1a747bf04dc84e5bcc2c")); private static GUIContent _logoGuiContent = new GUIContent(string.Empty, _logo, "LWGUI (Light Weight Shader GUI)\n\n" + "A Lightweight, Flexible, Powerful Unity Shader GUI system.\n\n" diff --git a/package.json b/package.json index 443529e..963a8bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.jasonma.lwgui", - "version": "1.18.0", + "version": "1.18.1", "displayName": "LWGUI", "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [