Skip to content

Commit 92338d4

Browse files
committed
Fix Select Material Button, and Add CustomMaterialAssetFinder Sample
1 parent 87aad57 commit 92338d4

File tree

8 files changed

+61
-7
lines changed

8 files changed

+61
-7
lines changed

Editor/CustomGUISample/CustomFooter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static void DoCustomFooter(LWGUI lwgui)
1515
[InitializeOnLoadMethod]
1616
private static void RegisterEvent()
1717
{
18-
LWGUI.onDrawCustomFooter += DoCustomFooter;
18+
// Register Event
19+
// LWGUI.onDrawCustomFooter += DoCustomFooter;
1920
}
2021
}
2122
}

Editor/CustomGUISample/CustomHeader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static void DoCustomHeader(LWGUI lwgui)
1515
[InitializeOnLoadMethod]
1616
private static void RegisterEvent()
1717
{
18-
LWGUI.onDrawCustomHeader += DoCustomHeader;
18+
// Register Event
19+
// LWGUI.onDrawCustomHeader += DoCustomHeader;
1920
}
2021
}
2122
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Linq;
2+
using UnityEngine;
3+
using UnityEditor;
4+
5+
namespace LWGUI
6+
{
7+
public static class CustomMaterialAssetFinder
8+
{
9+
public static Material FindMaterialAssetInRendererByMaterialInstance(Renderer renderer, Material materialInstance)
10+
{
11+
Material materialAsset = null;
12+
13+
// Find the material asset by name
14+
// if (materialAsset == null)
15+
// {
16+
// var name = materialInstance.name.Replace(" (Instance)", "");
17+
// var guids = AssetDatabase.FindAssets("t:Material " + name, new[] { "Assets" }).Select(guid =>
18+
// {
19+
// var assetPath = AssetDatabase.GUIDToAssetPath(guid);
20+
// if (string.IsNullOrEmpty(assetPath) || !assetPath.EndsWith(".mat"))
21+
// return null;
22+
// else
23+
// return guid;
24+
// }).ToArray();
25+
//
26+
// if (guids != null && guids.Length > 0)
27+
// {
28+
// var matPath = AssetDatabase.GUIDToAssetPath(guids[0]);
29+
// Selection.activeObject = AssetDatabase.LoadAssetAtPath<Material>(matPath);
30+
//
31+
// if (guids.Length > 1)
32+
// {
33+
// Debug.LogWarning($"LWGUI: Multiple materials with the same name were found, and the first one was selected: { matPath }");
34+
// }
35+
// }
36+
// }
37+
38+
return materialAsset;
39+
}
40+
41+
[InitializeOnLoadMethod]
42+
private static void RegisterEvent()
43+
{
44+
// Register Event
45+
// Helper.onFindMaterialAssetInRendererByMaterialInstance = FindMaterialAssetInRendererByMaterialInstance;
46+
}
47+
}
48+
}

Editor/CustomGUISample/CustomMaterialAssetFinder.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Helper/Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ void OnSwitchDisplayMode(object data, string[] options, int selectedIndex)
629629
toolBarRect.xMin += 2;
630630
}
631631

632-
public static Func<MeshRenderer, Material, Material> onFindMaterialAssetInRendererByMaterialInstance;
632+
public static Func<Renderer, Material, Material> onFindMaterialAssetInRendererByMaterialInstance;
633633

634634
private static bool FindMaterialAssetByMaterialInstance(Material material, LWGUIMetaDatas metaDatas, out Material materialAsset)
635635
{

UnityEditorExtension/ReflectionHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public static void DefaultShaderPropertyInternal(this MaterialEditor editor, Rec
5151
editor.DefaultShaderPropertyInternal(position, prop, label);
5252
}
5353

54-
public static List<MeshRenderer> GetMeshRenderersByMaterialEditor(this MaterialEditor materialEditor)
54+
public static List<Renderer> GetMeshRenderersByMaterialEditor(this MaterialEditor materialEditor)
5555
{
56-
var outRenderers = new List<MeshRenderer>();
56+
var outRenderers = new List<Renderer>();
5757

5858
// MaterialEditor.ShouldEditorBeHidden()
5959
PropertyEditor property = materialEditor.propertyViewer as PropertyEditor;
@@ -63,6 +63,7 @@ public static List<MeshRenderer> GetMeshRenderersByMaterialEditor(this MaterialE
6363
if (gameObject)
6464
{
6565
outRenderers.AddRange(gameObject.GetComponents<MeshRenderer>());
66+
outRenderers.AddRange(gameObject.GetComponents<SkinnedMeshRenderer>());
6667
}
6768
}
6869

UnityEditorExtension/UnityEditorExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Jason Ma
1+
// Copyright (c) Jason Ma
22

33
using UnityEditor;
44
using UnityEngine;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.jasonma.lwgui",
3-
"version": "1.20.1",
3+
"version": "1.20.2",
44
"displayName": "LWGUI",
55
"description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.",
66
"keywords": [

0 commit comments

Comments
 (0)