User Tools

Site Tools


scripting:shortcuts

Extension Methods

Enumerations

The NextGenSprites namespace comes with a set of Enums to guide you through the various Extension Methods - mainly the GetString() method.

ShaderFloat ShaderTexture ShaderFeature ShaderFeatureRuntime ShaderColor
CurvatureDepth Sprite SpriteMultiLayer Curvature Sprite
CurvatureGloss SpriteLayer1 SpriteScrolling Reflection SpriteLayer1
ReflectionStrength SpriteLayer2 SpriteStencil Emission SpriteLayer2
ReflectionBlur SpriteLayer3 Curvature Dissolve SpriteLayer3
ReflectionScrollSpeedX StencilMask Reflection Curvature
ReflectionScrollSpeedY Curvature Emission Emission
EmissionIntensity EmissionMask EmissionPusle EmissionLayer2
EmissionLayer1BlendAnimation Reflection Transmission EmissionLayer3
EmissionLayer1PulseSpeed ReflectionMask Dissolve DissolveGlow
EmissionLayer2Intensity Transmission DoubleSided
EmissionLayer2BlendAnimation Dissolve Pixelsnap
EmissionLayer2PulseSpeed Refraction AutoScrolling
EmissionLayer3Intensity Flow
EmissionLayer3BlendAnimation
EmissionLayer3PulseSpeed
TransmissionDensity
DissolveBlend
DissolveBorderWidth
DissolveGlowStrength
RefractionStrength
FlowIntensity
FlowSpeed
SpriteLayer0ScrollingX
SpriteLayer0ScrollingY
SpriteLayer1Opacity
SpriteLayer1ScrollingX
SpriteLayer1ScrollingY
SpriteLayer2Opacity
SpriteLayer2ScrollingX
SpriteLayer2ScrollingY
SpriteLayer3Opacity
SpriteLayer3ScrollingX
SpriteLayer3ScrollingY
SpriteAutoScrollingSpeed

GetString

GetString(this Enum)

In Unity you can get and set float, color, texture Material values and toggle shader features by parsing the Shader property as a string. Since you are confronted in NextGenSprites with a big stack of properties and typing strings values by hand are prone to errors, the GetString() method comes here to your rescue! Simply choose the property you need by the corresponding Enum and GetString will return the correct string.

using NextGenSprites;
...
void SetSomeValues(Material mat)
{
     //GetString() returns "_CurvatureDepth"
     mat.SetFloat(ShaderFloat.Curvature.GetString(), 0.25f);
 
     //GetString() returns "_EmissionTint"
     mat.SetColor(ShaderColor.Emission.GetString(), Color.blue);
 
     //GetString() returns "_ReflectionTex"
     mat.SetTexture(ShaderTexture.Reflection.GetString(), someNiceReflectionTexture);
 
     //GetString() returns "DISSOLVE_ON"
     mat.EnableKeyword (ShaderFeature.Dissolve.GetString ());
}

GetMin and GetMax

GetMin(this Enum)
GetMax(this Enum)

GetMin() and GetMax() returns either the recommended minimal or maximal float value and is used similar to the GetString() method. Useful for procedural stuff if you don't know before runtime what values you like to use.

using NextGenSprites;
...
void SetSomeValues(Material mat)
{
     var min = ShaderFloat.CurvatureDepth.GetMin ();
     //returns -1f
 
     var max = ShaderFloat.DissolveBorderWidth.GetMax ();
     // returns 100f
 
     Debug.Log (string.Format("Mininal value {0} and Maximal value {1}", min, max));
     //Prints: Minimal value -1 and Maximal value 100.
}

CopyToPropertyBlock

CopyToPropertyBlock(this MaterialPropertyBlock, Material mat)

This method copies all float, color and texture values from a Material to a MaterialPropertyBlock. Please note that you have to use beforehand Unity's GetPropertyBlock() method to get all Pre-Renderer data.

using NextGenSprites;
...
public MaterialPropertyBlock MatBlock { get; private set; }
 
void Start()
{
     //Make a new MaterialPropertieBlock instance
     MatBlock = new MaterialPropertieBlock();
}
 
void CreateMatBlock(Material mat)
{
     //Get the Sprite Renderer and SharedMaterial of this Gameobject
     var spriteRend = GetComponent<SpriteRenderer>();
     var sharedMat = spriteRend.sharedMaterial;
 
     //Get Pre-Renderer data from the SpriteRenderer
     spriteRend.GetPropertyBlock(MatBlock);
 
     //Copy all float, color and textures values from the Material to the MaterialPropertyBlock
     MatBlock.CopyToPropertyBlock(sharedMat);
}

ToggleShadowCasting

ToggleShadowCasting (this GameObject go, bool toogle)

Toggle shadow casting on the SpriteRenderer component. Don't forget to activate Shadow casting on your Scene Lights. Note: Receiving shadows is currently not supported, you can use a Quad to project your shadows on to.

Hint: If you notice Shadow acne set on the Light the Bias to around 0.35

scripting/shortcuts.txt · Last modified: 2015/12/11 16:55 by admin

Page Tools