Sprite Factory

ReadMe
Release Notes
Overview
Using the Editor
Upgrading

Concepts
Sprites
Master Sprites
Sprite Groups
Colliders
Locators
Material Sets
SpriteUpdater
SpriteCamera

Advanced
Working in Multiple Projects

Classes
Runtime Classes

Videos
Overview
Creating Sprites
Sprite Inspector
Frame Events
Collision System
Locator System
Material Sets

Links
Sprite Factory Site
Web Documentation
Support
Contact

SpriteFactory.Sprite.SpriteMaterial

Namespace: SpriteFactory

This class helps you make changes to all of a Sprite's materials and shaders simultaneously. The main purpose of this class is to allow you to change properties on the shaders of a Sprite without having to manually make changes to all the materials for every atlas. This makes it easy to create special effects that require animation of a shader's properties such as a fade.

When changing a shader property through any function in this class, if the Sprite is not using a Material Override, its current material will be set as the Material Override, the existing materials will be instanced, and modifications to the shaders will be done in these instanced materials. When you've finished modifying the shader properties and want to return to the previous unmodified material, call Revert. This is important to re-enable dyanmic draw batching because when a material is instanced, it cannot be batched with other Sprites on the screen. By calling Revert, you return the Sprite to using its original materials and it will be able to batch again. (The only exception to this is if you assigned a Material Override manually before making changes to the shader properties. When you call Revert in this case, it will revert back to your original Material Override, which by definition is instanced and cannot be batched.)

Properties

       
Name   Type   Description
isMaterialOverridden   bool   Is the Sprite's material currently overridden by a Material Override? (Read-only)

Functions

Name   Description
Revert   Restores the Sprite's previous materials and shaders. After you've finished modifying shader properties, call this to restore the original materials and re-enable batching.
ChangeMaterialSet   Change the current material set. (Same as Sprite.ChangeMaterialSet, included for convenience)
SetMaterialOverride   Assign an override material and enable it. (Same as Sprite.SetMaterialOverride, included for convenience)
EnableMaterialOverride   Switch to the override material if one has been set. (Same as Sprite.EnableMaterialOverride, included for convenience)
DisableMaterialOverride   Revert to original material. (Same as Sprite.DisableMaterialOverride, included for convenience)
CopyPropertiesFromMaterial   Copy properties from other material into all of the Sprite's materials.
DisableKeyword   Unset a shader keyword in all of the Sprite's current materials.
EnableKeyword   Set a shader keyword that is enabled by this material.
GetColor   Get a color value from the shader.
GetFloat   Get a float value from the shader.
GetInt   Get an integer value from the shader.
GetMatrix   Get a matrix value from the shader.
GetTag   Get the value of material's shader tag.
GetTexture   Get a named texture from the shader.
GetTextureOffset   Gets the placement offset of texture propertyName from the shader.
GetTextureScale   Gets the placement scale of texture propertyName from the shader.
GetVector   Get a vector value from the shader.
HasProperty   Checks if material's shader has a property of a given name or id.
Lerp   Interpolate properties between two materials.
SetBuffer   Set a ComputeBuffer value in all of the Sprite's current materials. (Unity 4.0+ required)
SetColor   Set a color value in the shader in all of the Sprite's current materials.
SetFloat   Set a float value in the shader in all of the Sprite's current materials.
SetInt   Set an integer value in the shader in all of the Sprite's current materials.
SetMatrix   Set a matrix in the shader in all of the Sprite's current materials.
SetTexture   Set a texture in the shader in all of the Sprite's current materials.
SetTextureOffset   Sets the placement offset of texture propertyName in the shader in all of the Sprite's current materials.
SetTextureScale   Sets the placement scale of texture propertyName in the shader in all of the Sprite's current materials.
SetVector   Set a vector value in the shader in all of the Sprite's current materials.