Added EnumFlagsDrawer; Added custom keywordName option to KeywordTexturePropertySingleLine;
55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using System;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Misaki.ShaderGUI
|
|
{
|
|
public static class MaterialPropertyHelpers
|
|
{
|
|
public static bool GetBooleanValue(this MaterialProperty materialProperty)
|
|
{
|
|
#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 !Mathf.Approximately(materialProperty.floatValue, 0.0f);
|
|
}
|
|
|
|
#if UNITY_6000_1_OR_NEWER
|
|
if (materialProperty.propertyType == UnityEngine.Rendering.ShaderPropertyType.Int)
|
|
#else
|
|
if (materialProperty.type == MaterialProperty.PropType.Int)
|
|
#endif
|
|
{
|
|
return materialProperty.intValue != 0;
|
|
}
|
|
|
|
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.");
|
|
}
|
|
}
|
|
} |