Added GetEnumValue;

Added EnumFlagsDrawer;
Added custom keywordName option to KeywordTexturePropertySingleLine;
This commit is contained in:
2025-02-03 15:44:46 +09:00
parent 4723c9833a
commit dc1f1fb4e7
6 changed files with 162 additions and 16 deletions

View File

@@ -81,9 +81,9 @@ namespace Misaki.ShaderGUI
/// <param name="label">The label of the texture property.</param>
/// <param name="textureProperty">The texture property to draw.</param>
/// <returns>True if the texture property is not null. Otherwise, false.</returns>
public static bool KeywordTexturePropertySingleLine(this MaterialEditor editor, GUIContent label, MaterialProperty textureProperty)
public static bool KeywordTexturePropertySingleLine(this MaterialEditor editor, GUIContent label, MaterialProperty textureProperty, string keywordName = null)
{
return KeywordTexturePropertySingleLine(editor, label, textureProperty, null, null);
return KeywordTexturePropertySingleLine(editor, label, textureProperty, null, null, keywordName);
}
/// <summary>
@@ -94,9 +94,9 @@ namespace Misaki.ShaderGUI
/// <param name="textureProperty">The texture property to draw.</param>
/// <param name="extraProperty">The first extra property to draw.</param>
/// <returns>True if the texture property is not null. Otherwise, false.</returns>
public static bool KeywordTexturePropertySingleLine(this MaterialEditor editor, GUIContent label, MaterialProperty textureProperty, MaterialProperty extraProperty)
public static bool KeywordTexturePropertySingleLine(this MaterialEditor editor, GUIContent label, MaterialProperty textureProperty, MaterialProperty extraProperty, string keywordName = null)
{
return KeywordTexturePropertySingleLine(editor, label, textureProperty, extraProperty, null);
return KeywordTexturePropertySingleLine(editor, label, textureProperty, extraProperty, null, keywordName);
}
/// <summary>
@@ -108,13 +108,13 @@ namespace Misaki.ShaderGUI
/// <param name="extraProperty1">The first extra property to draw.</param>
/// <param name="extraProperty2">The second extra property to draw.</param>
/// <returns>True if the texture property is not null. Otherwise, false.</returns>
public static bool KeywordTexturePropertySingleLine(this MaterialEditor editor, GUIContent label, MaterialProperty textureProperty, MaterialProperty extraProperty1, MaterialProperty extraProperty2)
public static bool KeywordTexturePropertySingleLine(this MaterialEditor editor, GUIContent label, MaterialProperty textureProperty, MaterialProperty extraProperty1, MaterialProperty extraProperty2, string keywordName = null)
{
EditorGUI.BeginChangeCheck();
editor.TexturePropertySingleLine(label, textureProperty, extraProperty1, extraProperty2);
if (EditorGUI.EndChangeCheck())
{
editor.SetKeyword(textureProperty.name.ToUpper(), textureProperty.textureValue != null);
editor.SetKeyword(string.IsNullOrEmpty(keywordName) ? textureProperty.name.ToUpper() : keywordName, textureProperty.textureValue != null);
}
return textureProperty.textureValue != null;

View File

@@ -28,5 +28,28 @@ namespace Misaki.ShaderGUI
throw new NotSupportedException("Property type is not supported.");
}
public static T GetEnumValue<T>(this MaterialProperty materialProperty) where T : Enum
{
#if UNITY_6000_1_OR_NEWER
if (materialProperty.propertyType == UnityEngine.Rendering.ShaderPropertyType.Float || materialProperty.propertyType == UnityEngine.Rendering.ShaderPropertyType.Range)
#else
if (materialProperty.type == MaterialProperty.PropType.Float || materialProperty.type == MaterialProperty.PropType.Range)
#endif
{
return (T)Enum.ToObject(typeof(T), (int)materialProperty.floatValue);
}
#if UNITY_6000_1_OR_NEWER
if (materialProperty.propertyType == UnityEngine.Rendering.ShaderPropertyType.Int)
#else
if (materialProperty.type == MaterialProperty.PropType.Int)
#endif
{
return (T)Enum.ToObject(typeof(T), materialProperty.intValue);
}
throw new NotSupportedException("Property type is not supported.");
}
}
}