Effect Attribute Samplers Animation

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

Available since Unity plugin v2.8.

See also : Effect Attribute Samplers

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

Accessing directly through scripts

You can access the samplers in your scripts using the PKFxFX component's public methods.

You need to know the name and the type of the sampler you want to access and call PKFxFX.SetSampler() with the appropriate Sampler argument.

Setting a Sampler

PKFxFX myFX = this.GetComponent<PKFxFX>();

Text

myFX.SetSampler(new PKFxManager.Sampler("MyText", "SomeText"));

Curve

AnimationCurve curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
myFX.SetSampler(new PKFxManager.Sampler("MyCurve", curve));

Texture

Texture2D texture = new Texture2D(128, 128);
myFX.SetSampler(new PKFxManager.Sampler("MyTexture", texture, PKFxManager.ETexcoordMode.Clamp));

Shape

Box

myFX.SetSampler(new PKFxManager.Sampler("MyShape", new PKFxManager.SamplerDescShapeBox(Vector3.zero, Vector3.one, Vector3.zero)));

Sphere

myFX.SetSampler(new PKFxManager.Sampler("MyShape", new PKFxManager.SamplerDescShapeSphere(Vector3.zero, 1.0f, 1.0f, Vector3.zero)));

Cylinder

myFX.SetSampler(new PKFxManager.Sampler("MyShape", new PKFxManager.SamplerDescShapeCylinder(Vector3.zero, 1.0f, 1.0f, 1.0f Vector3.zero)));

Capsule

myFX.SetSampler(new PKFxManager.Sampler("MyShape", new PKFxManager.SamplerDescShapeCapsule(Vector3.zero, 1.0f, 1.0f, 1.0f Vector3.zero)));

Mesh

Mesh mesh = GetComponent<MeshFilter>().mesh;
PKFxManager.SamplerDescShapeMesh samplerDescMesh = new PKFxManager.SamplerDescShapeMesh(Vector3.zero, Vector3.one, Vector3.zero, mesh, (int)PKFxManager.EMeshChannels.Channel_Position);
myFX.SetSampler(new PKFxManager.Sampler("MyShape", samplerDescMesh));

MeshFilter

MeshFilter mesh = GetComponent<MeshFilter>();
PKFxManager.SamplerDescShapeMeshFilter samplerDescMesh = new PKFxManager.SamplerDescShapeMeshFilter(Vector3.zero, Vector3.one, Vector3.zero, mesh, (int)PKFxManager.EMeshChannels.Channel_Position);
myFX.SetSampler(new PKFxManager.Sampler("MyShape", samplerDescMesh));

SkinnedMesh

SkinnedMeshRenderer mesh = GetComponent<SkinnedMeshRenderer>();
PKFxManager.SamplerDescShapeSkinnedMesh samplerDescMesh = new PKFxManager.SamplerDescShapeSkinnedMesh(Vector3.zero, Vector3.one, Vector3.zero, mesh, (int)PKFxManager.EMeshChannels.Channel_Position);
myFX.SetSampler(new PKFxManager.Sampler("MyShape", samplerDescMesh));

For the samplers Mesh, you can combine the PKFxManager.EMeshChannels to choose which channels you want to sample. You can use PKFxManager.EMeshChannels.Channel_Velocity only for the SkinnedMesh.

int samplingChannels =  (int)PKFxManager.EMeshChannels.Channel_Position | (int)PKFxManager.EMeshChannels.Channel_Normal;


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

PKFxFX myFX = this.GetComponent<PKFxFX>();
string newText = "SomeText";

PKFxManager.SamplerDesc desc = new PKFxManager.SamplerDesc("MyText", (int)PKFxManager.ESamplerType.SamplerText);

if (myFX != null && myFX.SamplerExists(desc))
    myFX.SetSampler(new PKFxManager.Sampler("MyText", newText));

Getting an Attribute

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

 PKFxFX.GetSampler(string name)

or

 PKFxFX.GetSampler(string name, PKFxManager.ESamplerType type)

So for example : getting a sampler named "MyImage" of type SamplerImage:

PKFxFX myFX = this.GetComponent<PKFxFX>();
Texture2D samplerImage;
 
if (myFX != null)
{
    PKFxManager.Sampler sampler = myFX.GetSampler("MyImage");
    if (attr != null)
        samplerImage = attr.m_Texture;
}