-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Select Material Button, and Add CustomMaterialAssetFinder Sample
- Loading branch information
1 parent
87aad57
commit 92338d4
Showing
8 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Material>(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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) Jason Ma | ||
// Copyright (c) Jason Ma | ||
|
||
using UnityEditor; | ||
using UnityEngine; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters