Skip to main content

Scripting API

This page summarizes the public C# surface intended for shader package authors and editor extension authors.

All APIs are Editor-only.

For task-oriented guides, start with:

Namespaces​

NamespacePurpose
KIBA_.KIBAMaterialGUI.Editor.Corecontext, model, diagnostics
KIBA_.KIBAMaterialGUI.Editor.Extensibilityeditor injection and contribution APIs
KIBA_.KIBAMaterialGUI.Editor.ShaderLabShaderLab drawer bridge classes
KIBA_.KIBAMaterialGUI.Editor.UI.Propertyproperty renderer APIs and value write helpers

Core Context​

MaterialGUIContext​

Read-only context passed to extension callbacks.

MemberTypeDescription
MaterialEditorMaterialEditorUnity material editor instance.
MaterialMaterialPrimary selected material.
TargetsIReadOnlyList<Material>Selected materials.
PropertiesIReadOnlyList<MaterialProperty>Material properties for the current inspector.
CurrentLanguagestringActive localization language code.
SearchstringCurrent search text.
ModelMaterialGUIModelCurrent grouped property model.

MaterialGUIModel​

MemberTypeDescription
RootGroupNodeModelRoot group node.
PropertiesIReadOnlyList<ShaderPropertyModel>All property models.
DiagnosticsIReadOnlyList<MaterialGUIDiagnostic>Inspector diagnostics.

ShaderPropertyModel​

MemberTypeDescription
PropertyMaterialPropertyUnity material property.
PropertyNamestringShader property name.
LabelstringOriginal display label.
TranslatedLabelstringLocalized label.
GroupPathstringResolved group path.
PropertyTypeMaterialProperty.PropTypeUnity property type.
AttributesIReadOnlyList<ShaderAttributeInfo>ShaderLab attributes.
ChangedboolValue differs from shader default.
MixedboolMulti-selection mixed value state.
ConditionVisibleboolResult of [ShowIf] visibility.
SearchMatchedboolResult of current search.
VisibleboolFinal row visibility.
ConditionalVisibilityConditionalVisibilityInfoParsed condition state.
DiagnosticsIReadOnlyList<MaterialGUIDiagnostic>Property diagnostics.
WarningCountintWarning/error diagnostic count.

GroupNodeModel​

MemberTypeDescription
NamestringGroup segment name.
PathKeystringFull group path.
ExpandedboolFoldout state.
VisibleboolFinal group visibility.
SearchMatchedSelfboolWhether the group path matched search.
PropertiesIReadOnlyList<ShaderPropertyModel>Direct properties in the group.
ChildrenIReadOnlyDictionary<string, GroupNodeModel>Child groups.
TotalPropertyCountintTotal visible-aware property count.
VisiblePropertyCountintCurrently visible property count.
ChangedCountintChanged property count.
WarningCountintWarning/error count.
HasMixedboolWhether the group contains mixed values.

MaterialGUIDiagnostic​

public MaterialGUIDiagnostic(
MaterialGUIDiagnosticSeverity severity,
string message,
string propertyName = null,
string groupPath = null)

Use diagnostics for shader-author feedback. Severity values are Info, Warning, and Error.

Property Renderer API​

See also:

IMaterialGUIPropertyRenderer​

public interface IMaterialGUIPropertyRenderer
{
float GetHeight(PropertyRendererArgs args);
Rect OnGUI(PropertyRendererArgs args);
}

IMaterialGUIPropertyRendererFilter​

public interface IMaterialGUIPropertyRendererFilter
{
bool CanRender(PropertyRendererArgs args);
}

Implement this when static attribute filters are not enough.

MaterialGUIPropertyRendererAttribute​

PropertyTypeDescription
OrderintLower values resolve first.
ShaderNameEqualsstring[]Exact shader name filters.
ShaderNameContainsstring[]Substring shader name filters.
ShaderNameRegexstringRegex shader name filter.
RequirePropertiesstring[]Required material properties.
RequireKeywordsstring[]Required enabled keywords.
PropertyNamestringRequired property name.
PropertyTypesMaterialProperty.PropType[]Required property types.
RequireShaderAttributesstring[]Required ShaderLab attributes.
ExcludeShaderAttributesstring[]Disallowed ShaderLab attributes.

PropertyRendererArgs​

MemberTypeDescription
PositionRectFull row rect passed to the renderer.
LayoutPropertyRowLayoutDetailed row layout.
MaterialEditorMaterialEditorUnity material editor.
MaterialMaterialPrimary material.
PropertyMaterialPropertyCurrent property.
LabelstringLocalized label.
MiniGrayGUIStyleSmall gray label style.
ShaderShaderResolved shader.
ModelShaderPropertyModelOptional property model.
LabelRectRectLabel rect.
FieldRectRectField rect.
ResetRectRectReset button rect.

Methods:

  • HasShaderAttribute(string attributeName)
  • TryGetShaderAttribute(string attributeName, out ShaderAttributeInfo attribute)
  • GetShaderAttributes()
  • SetFloatValue(float value, string undoName = null)
  • SetColorValue(Color value, string undoName = null)
  • SetVectorValue(Vector4 value, string undoName = null)
  • SetTextureValue(Texture value, string undoName = null)
  • SetTextureScaleAndOffset(Vector4 value, string undoName = null)
  • RegisterPropertyValueChange(string undoName = null)

ShaderPropertyRenderer<TArgs>​

Convenience base class for one-attribute renderers.

public abstract class ShaderPropertyRenderer<TArgs> :
IMaterialGUIPropertyRenderer,
IMaterialGUIPropertyRendererFilter

Override:

  • AttributeName
  • SupportsPropertyType
  • TryParseArguments
  • GetHeight
  • OnGUI

There are also two-, three-, and four-argument base classes:

  • ShaderPropertyRenderer<T1, T2>
  • ShaderPropertyRenderer<T1, T2, T3>
  • ShaderPropertyRenderer<T1, T2, T3, T4>

ShaderLab Bridge API​

ShaderPropertyDrawer​

Base class for ShaderLab attribute bridge drawers.

using KIBA_.KIBAMaterialGUI.Editor.ShaderLab;

public sealed class MyHintDrawer : ShaderPropertyDrawer
{
public MyHintDrawer() {}
}

Create a drawer class named {AttributeName}Drawer so Unity accepts [AttributeName] in shader properties.

Injection API​

See also:

IShaderEditor​

public interface IShaderEditor
{
void OnGUI(InjectionArgs args);
}

ShaderEditorInjectionAttribute​

PropertyTypeDescription
HookHookPointRequired constructor argument.
OrderintLower values draw first.
ShaderNameEqualsstring[]Exact shader filters.
ShaderNameContainsstring[]Substring shader filters.
ShaderNameRegexstringRegex shader filter.
RequirePropertiesstring[]Required material properties.
RequireKeywordsstring[]Required enabled keywords.
GroupPathstringRequired group path.
PropertyNamestringRequired property name.

HookPoint​

Values:

  • BeforeHeader
  • AfterHeader
  • BeforeToolbar
  • AfterToolbar
  • BeforeTree
  • AfterTree
  • BeforeGroupHeader
  • AfterGroupHeader
  • BeforeGroupContent
  • AfterGroupContent
  • BeforeProperty
  • AfterProperty
  • BeforeFooter
  • AfterFooter

InjectionArgs​

MemberTypeDescription
HookHookPointCurrent hook point.
ContextMaterialGUIContextInspector context.
GroupPathstringCurrent group path when available.
PropertyMaterialPropertyCurrent property when available.
PropertyLabelstringCurrent localized label when available.
DepthintGroup depth for group hooks.

Contribution API​

See also:

MaterialGUIContributionAttribute​

[MaterialGUIContribution(ContributionTarget.Toolbar, Order = 10)]

Filters:

  • Order
  • ShaderNameEquals
  • ShaderNameContains
  • ShaderNameRegex
  • GroupPath

Targets:

  • Toolbar
  • GroupContextMenu
  • GroupAction
  • Diagnostic
  • Filter

Contributor Interfaces​

public interface IToolbarContributor
{
void Contribute(ToolbarModel model, InjectionArgs args);
}

public interface IGroupMenuContributor
{
void Contribute(ContextMenuModel model, InjectionArgs args);
}

public interface IMaterialGUIGroupActionContributor
{
void Contribute(GroupActionModel model, InjectionArgs args);
}

public interface IMaterialGUIDiagnosticProvider
{
void Contribute(List<MaterialGUIDiagnostic> diagnostics, InjectionArgs args);
}

public interface IMaterialGUIFilterProvider
{
void Contribute(ToolbarModel model, InjectionArgs args);
}

Model APIs​

ToolbarModel​

Methods:

  • Add(ToolbarItem item)
  • Remove(string id)
  • Find(string id)
  • Hide(string id)
  • Lock(string id, bool locked = true)

ToolbarItem supports:

  • Toggle
  • Button
  • Input
  • Dropdown

GroupActionModel​

Methods:

  • Add(GroupActionItem item)
  • Remove(string id)
  • Find(string id)

Properties:

  • Items
  • BeginDrag

ContextMenuModel​

Methods:

  • Add(ContextMenuItem item)
  • Remove(string id)
  • Find(string id)
  • Hide(string id)
  • Lock(string id, bool locked = true)

ContextMenuItemType values:

  • Toggle
  • Button
  • Separator

Value Write Utility​

Use MaterialGUIPropertyChangeUtility outside property renderers.

MaterialGUIPropertyChangeUtility.SetFloat(context, property, value, "Change Float");
MaterialGUIPropertyChangeUtility.SetColor(context, property, value, "Change Color");
MaterialGUIPropertyChangeUtility.SetVector(context, property, value, "Change Vector");
MaterialGUIPropertyChangeUtility.SetTexture(context, property, value, "Change Texture");
MaterialGUIPropertyChangeUtility.SetTextureScaleAndOffset(context, property, value, "Change Texture Scale");
MaterialGUIPropertyChangeUtility.RegisterChange(context, property, "Change Material Property");

These methods register Unity undo through MaterialEditor, set GUI.changed, and then write the material property value.