Effect Attributes Animation

From PopcornFX
Jump to: navigation, search
Unity-logo-g.png

Particle effect attributes are exposed on the PKFxFX component's inspector view.

Using the PKFxAnimFloat* classes

  1. Add the PKFxAnimFloat component corresponding to your attribute's type to the GameObject holding the PKFxFX component.
  2. On the PKFxAnimFloat component, set the name of the attribute you want to manipulate.
  3. You can now access the attribute via the helper component's public variable : "value".

Accessing directly through scripts

Alternatively, you can access the attributes in your scripts using the PKFxFX component's public methods.

You need to know the name and the type of the attribute you want to access and call PKFxFX.SetAttribute() with the appropriate Attribute argument.

Setting an Attribute

So for example : setting an attribute named "MyColor" of type float4:

PKFxFX myFX = this.GetComponent<PKFxFX>();
Vector4 newColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

if (myFX != null)
    myFX.SetAttribute(new PKFxManager.Attribute("MyColor", newColor));


If you're not sure whether an effect has a specific attribute or not, you can check using PKFxFX.AtributesExist() with an AttributeDesc parameter built with the proper type and name.

Setting the same attribute as above after checking it exists:

PKFxFX myFX = this.GetComponent<PKFxFX>();
Vector4 newColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

PKFxManager.AttributeDesc desc = new PKFxManager.AttributeDesc(PKFxManager.BaseType.Float4, "MyColor");

if (myFX != null && myFX.AttributesExist(desc))
    myFX.SetAttribute(new PKFxManager.Attribute("MyColor", newColor));

Getting an Attribute

A much less common case, but for some reason you might need to retrieve an attribute's value.
To do so, you'll need to use :

 PKFxFX.GetAttribute(string name)

or

 PKFxFX.GetAttribute(string name,  PKFxManager.BaseType type)

So for example : getting an attribute named "MyColor" of type float4:

PKFxFX myFX = this.GetComponent<PKFxFX>();
Vector4 attrColor;
 
if (myFX != null)
{
    PKFxManager.Attribute attr = myFX.GetAttribute("MyColor");
    if (attr != null)
        attrColor = attr.ValueFloat4;
}