Skip to main content

Scripting

Code Snippets​

The namespace
using ChocDino.UIFX;
Add the BlurFilter component to your GameObject
// Add the component to your GameObject and set default properties
var blur = AddComponent<BlurFilter>();

blur.BeginPropertyChange();
blur.Algorithm = BlurAlgorithm.MultiBox;
blur.Downsample = Downsample.Auto;
blur.Blur = 4f;
blur.Strength = 1f;
blur.BlurAxes2D = BlurAxes2D.Default;
blur.ApplyAlphaCurve = false;
blur.AlphaCurve = new AnimationCurve(new Keyframe(0f, 1f, -1f, -1f), new Keyframe(1f, 0f, -1f, -1f)); // AlphaCurve is optional and can be null
blur.EndPropertyChange();
Globally scale all BlurFilter Strength
BlurFilter.GlobalStrength = 0.5f;
Add the BlurDirectionalFilter component to your GameObject
// Add the component to your GameObject and set default properties
var blur = AddComponent<BlurDirectionalFilter>();

blur.BeginPropertyChange();
blur.Angle = 135;
blur.Length= 64f;
blur.Weights = BlurDirectionalWeighting.Falloff;
blur.WeightsPower = 1f;
blur.Side = BlurDirectionalSide.Both;
blur.Dither = 0f;
blur.ApplyAlphaCurve = false;
blur.AlphaCurve = new AnimationCurve(new Keyframe(0f, 1f, -1f, -1f), new Keyframe(1f, 0f, -1f, -1f)); // AlphaCurve is optional and can be null
blur.TintColor = Color.white;
blur.Power = 1f;
blur.Intensity = 1f;
blur.Blend = BlurDirectionalBlend.Replace;
blur.Strength = 1f;
blur.EndPropertyChange();
Add the BlurZoomFilter component to your GameObject
// Add the component to your GameObject and set default properties
var blur = AddComponent<BlurZoomFilter>();

blur.BeginPropertyChange();
blur.Center = Vector2.zero;
blur.Scale = 2f;
blur.Weights = BlurDirectionalWeighting.Falloff;
blur.WeightsPower = 1f;
blur.Direction = BlurZoomDirection.Out;
blur.Dither = 0f;
blur.ApplyAlphaCurve = false;
blur.AlphaCurve = new AnimationCurve(new Keyframe(0f, 1f, -1f, -1f), new Keyframe(1f, 0f, -1f, -1f)); // AlphaCurve is optional and can be null
blur.TintColor = Color.white;
blur.Power = 1f;
blur.Intensity = 1f;
blur.Blend = BlurDirectionalBlend.Replace;
blur.Strength = 1f;
blur.EndPropertyChange();

Complete Example​

TrailExample.cs
using UnityEngine;
using ChocDino.UIFX;

/// Demonstrates the scripting API for the BlurFilter component

/// Press keys 1 to 5 to test some API functionality.

/// NOTE: The GameObject is required to have a UI component of type Graphic
[RequireComponent(typeof(Graphic))]
public class BlurExample : MonoBehaviour
{
private BlurFilter _blur;
private float _blurTarget = 0f;

void Start()
{
// Get or create the component
_blur = GetComponent<BlurEffect>();
if (_blur == null)
{
_blur = AddComponent<BlurFilter>();
}
}

void Update()
{
// Keys 1..5 demonstrate some API functionality
if (Input.GetKeyDown(KeyCode.Alpha1))
{
_blur.BlurAxes2D = BlurAxes2D.Default;
}
else if (Input.GetKeyDown(KeyCode.Alpha2))
{
_blur.BlurAxes2D = BlurAxes2D.Horizontal;
}
else if (Input.GetKeyDown(KeyCode.Alpha3))
{
_blur.BlurAxes2D = BlurAxes2D.Vertical;
}
else if (Input.GetKeyDown(KeyCode.Alpha4))
{
_blurTarget = 0f;
}
else if (Input.GetKeyDown(KeyCode.Alpha5))
{
_blurTarget = 1f;
}

// Animate blur towards target amount
if (_blur.Strength != _blurTarget)
{
_blur.Strength = Mathf.MoveTowards(_blur.Strength, _blurTarget, Time.deltaTime);
}
}
}