Skip to content

Commit

Permalink
Merge pull request #11 from StansAssets/enhancement/show-if-material
Browse files Browse the repository at this point in the history
ShowIfMaterialPropertyDrawer minor enhancement
  • Loading branch information
Tinaynox authored Apr 2, 2020
2 parents 4d7dc23 + 5ae6005 commit 4e90967
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace StansAssets.Foundation.Editor.Shading
/// </example>
public class ShowIfDrawer : MaterialPropertyDrawer
{
string[] m_RequiredKeywords;
readonly string[] m_RequiredKeywords;
bool m_IsElementHidden;

/// <summary>
Expand All @@ -28,7 +28,7 @@ public class ShowIfDrawer : MaterialPropertyDrawer
public ShowIfDrawer(
string keyword0)
{
m_RequiredKeywords = new string[] {keyword0};
m_RequiredKeywords = new[] {keyword0};
}

/// <summary>
Expand All @@ -38,7 +38,7 @@ public ShowIfDrawer(
string keyword0,
string keyword1)
{
m_RequiredKeywords = new string[] {keyword0, keyword1};
m_RequiredKeywords = new[] {keyword0, keyword1};
}

/// <summary>
Expand All @@ -49,7 +49,7 @@ public ShowIfDrawer(
string keyword1,
string keyword2)
{
m_RequiredKeywords = new string[] {keyword0, keyword1, keyword2};
m_RequiredKeywords = new[] {keyword0, keyword1, keyword2};
}

/// <summary>
Expand All @@ -61,7 +61,7 @@ public ShowIfDrawer(
string keyword2,
string keyword3)
{
m_RequiredKeywords = new string[] {keyword0, keyword1, keyword2, keyword3};
m_RequiredKeywords = new[] {keyword0, keyword1, keyword2, keyword3};
}

public override void OnGUI(
Expand All @@ -72,15 +72,15 @@ public override void OnGUI(
{
m_IsElementHidden = false;

for (int i = 0; i < editor.targets.Length; ++i)
foreach (var target in editor.targets)
{
Material mat = editor.targets[i] as Material;
var mat = target as Material;

if (mat != null)
{
for (int j = 0; j < m_RequiredKeywords.Length; ++j)
foreach (var keyword in m_RequiredKeywords)
{
if (!mat.IsKeywordEnabled(m_RequiredKeywords[j]))
if (!mat.IsKeywordEnabled(keyword))
{
m_IsElementHidden = true;
break;
Expand All @@ -95,6 +95,13 @@ public override void OnGUI(
}
}

/// <summary>
/// Will always return <c>0</c>
/// </summary>
/// <param name="prop">The <see cref="MaterialProperty"/> to make the custom GUI for.</param>
/// <param name="label">The label of this property.</param>
/// <param name="editor">Current material editor.</param>
/// <returns>Property height in pixels</returns>
public override float GetPropertyHeight (
MaterialProperty prop,
string label,
Expand Down
File renamed without changes.

0 comments on commit 4e90967

Please sign in to comment.