diff --git a/Editor/CustomGUISample/CustomFooter.cs b/Editor/CustomGUISample/CustomFooter.cs index aa56fe9..1364ce9 100644 --- a/Editor/CustomGUISample/CustomFooter.cs +++ b/Editor/CustomGUISample/CustomFooter.cs @@ -15,7 +15,8 @@ public static void DoCustomFooter(LWGUI lwgui) [InitializeOnLoadMethod] private static void RegisterEvent() { - LWGUI.onDrawCustomFooter += DoCustomFooter; + // Register Event + // LWGUI.onDrawCustomFooter += DoCustomFooter; } } } \ No newline at end of file diff --git a/Editor/CustomGUISample/CustomHeader.cs b/Editor/CustomGUISample/CustomHeader.cs index 92894dc..6274785 100644 --- a/Editor/CustomGUISample/CustomHeader.cs +++ b/Editor/CustomGUISample/CustomHeader.cs @@ -15,7 +15,8 @@ public static void DoCustomHeader(LWGUI lwgui) [InitializeOnLoadMethod] private static void RegisterEvent() { - LWGUI.onDrawCustomHeader += DoCustomHeader; + // Register Event + // LWGUI.onDrawCustomHeader += DoCustomHeader; } } } \ No newline at end of file diff --git a/Editor/CustomGUISample/CustomMaterialAssetFinder.cs b/Editor/CustomGUISample/CustomMaterialAssetFinder.cs new file mode 100644 index 0000000..5be4e65 --- /dev/null +++ b/Editor/CustomGUISample/CustomMaterialAssetFinder.cs @@ -0,0 +1,48 @@ +using System.Linq; +using UnityEngine; +using UnityEditor; + +namespace LWGUI +{ + public static class CustomMaterialAssetFinder + { + public static Material FindMaterialAssetInRendererByMaterialInstance(Renderer renderer, Material materialInstance) + { + Material materialAsset = null; + + // Find the material asset by name + // if (materialAsset == null) + // { + // var name = materialInstance.name.Replace(" (Instance)", ""); + // var guids = AssetDatabase.FindAssets("t:Material " + name, new[] { "Assets" }).Select(guid => + // { + // var assetPath = AssetDatabase.GUIDToAssetPath(guid); + // if (string.IsNullOrEmpty(assetPath) || !assetPath.EndsWith(".mat")) + // return null; + // else + // return guid; + // }).ToArray(); + // + // if (guids != null && guids.Length > 0) + // { + // var matPath = AssetDatabase.GUIDToAssetPath(guids[0]); + // Selection.activeObject = AssetDatabase.LoadAssetAtPath(matPath); + // + // if (guids.Length > 1) + // { + // Debug.LogWarning($"LWGUI: Multiple materials with the same name were found, and the first one was selected: { matPath }"); + // } + // } + // } + + return materialAsset; + } + + [InitializeOnLoadMethod] + private static void RegisterEvent() + { + // Register Event + // Helper.onFindMaterialAssetInRendererByMaterialInstance = FindMaterialAssetInRendererByMaterialInstance; + } + } +} \ No newline at end of file diff --git a/Editor/CustomGUISample/CustomMaterialAssetFinder.cs.meta b/Editor/CustomGUISample/CustomMaterialAssetFinder.cs.meta new file mode 100644 index 0000000..412ac87 --- /dev/null +++ b/Editor/CustomGUISample/CustomMaterialAssetFinder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d476ea1a49c64eb4a29bca60d1e97c01 +timeCreated: 1732872239 \ No newline at end of file diff --git a/Editor/Helper/Helper.cs b/Editor/Helper/Helper.cs index 929db62..e379b6b 100644 --- a/Editor/Helper/Helper.cs +++ b/Editor/Helper/Helper.cs @@ -629,7 +629,7 @@ void OnSwitchDisplayMode(object data, string[] options, int selectedIndex) toolBarRect.xMin += 2; } - public static Func onFindMaterialAssetInRendererByMaterialInstance; + public static Func onFindMaterialAssetInRendererByMaterialInstance; private static bool FindMaterialAssetByMaterialInstance(Material material, LWGUIMetaDatas metaDatas, out Material materialAsset) { diff --git a/UnityEditorExtension/ReflectionHelper.cs b/UnityEditorExtension/ReflectionHelper.cs index 70f32aa..408b376 100644 --- a/UnityEditorExtension/ReflectionHelper.cs +++ b/UnityEditorExtension/ReflectionHelper.cs @@ -51,9 +51,9 @@ public static void DefaultShaderPropertyInternal(this MaterialEditor editor, Rec editor.DefaultShaderPropertyInternal(position, prop, label); } - public static List GetMeshRenderersByMaterialEditor(this MaterialEditor materialEditor) + public static List GetMeshRenderersByMaterialEditor(this MaterialEditor materialEditor) { - var outRenderers = new List(); + var outRenderers = new List(); // MaterialEditor.ShouldEditorBeHidden() PropertyEditor property = materialEditor.propertyViewer as PropertyEditor; @@ -63,6 +63,7 @@ public static List GetMeshRenderersByMaterialEditor(this MaterialE if (gameObject) { outRenderers.AddRange(gameObject.GetComponents()); + outRenderers.AddRange(gameObject.GetComponents()); } } diff --git a/UnityEditorExtension/UnityEditorExtension.cs b/UnityEditorExtension/UnityEditorExtension.cs index 899c36c..1db5a11 100644 --- a/UnityEditorExtension/UnityEditorExtension.cs +++ b/UnityEditorExtension/UnityEditorExtension.cs @@ -1,4 +1,4 @@ -// Copyright (c) Jason Ma +// Copyright (c) Jason Ma using UnityEditor; using UnityEngine; diff --git a/package.json b/package.json index 127072d..a95194a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.jasonma.lwgui", - "version": "1.20.1", + "version": "1.20.2", "displayName": "LWGUI", "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [