-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from JasonMa0012/2.x
Add ApplyMaterialPropertyAndDecoratorDrawers() to fix PassSwitch() no…
- Loading branch information
Showing
7 changed files
with
66 additions
and
9 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
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,56 @@ | ||
// Copyright (c) Jason Ma | ||
|
||
using UnityEditor; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace LWGUI | ||
{ | ||
public static class UnityEditorExtension | ||
{ | ||
|
||
#region MaterialEditor | ||
|
||
// For Developers: Call this after a material has modified in code | ||
public static void ApplyMaterialPropertyAndDecoratorDrawers(Material material) | ||
{ | ||
var objs = new Object[] { material }; | ||
ApplyMaterialPropertyAndDecoratorDrawers(objs); | ||
} | ||
|
||
public static void ApplyMaterialPropertyAndDecoratorDrawers(Object[] targets) | ||
{ | ||
if (!EditorMaterialUtility.disableApplyMaterialPropertyDrawers) | ||
{ | ||
if (targets == null || targets.Length == 0) | ||
return; | ||
var target = targets[0] as Material; | ||
if (target == null) | ||
return; | ||
|
||
var shader = target.shader; | ||
string[] propNames = MaterialEditor.GetMaterialPropertyNames(targets); | ||
for (int i = 0; i < propNames.Length; i++) | ||
{ | ||
var prop = MaterialEditor.GetMaterialProperty(targets, i); | ||
var drawer = ReflectionHelper.GetPropertyDrawer(shader, prop, out var decoratorDrawers); | ||
|
||
if (drawer != null) | ||
{ | ||
drawer.Apply(prop); | ||
} | ||
if (decoratorDrawers != null) | ||
{ | ||
foreach (var decoratorDrawer in decoratorDrawers) | ||
{ | ||
decoratorDrawer.Apply(prop); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
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