A helper class representing a 2D particle parameter where each component is a ParticleFloat. It stores X and Y ParticleFloat properties, provides constructors, an Evaluate method that returns a Vector2 by evaluating each component for a particle and seed, and an implicit conversion from Vector2.
namespace Sandbox;
/// <summary>
/// A two component vector whose X and Y are <see cref="ParticleFloat"/>s, so each
/// component can be a constant, a random range, or a curve evaluated per particle.
/// Mirrors the engine's <see cref="ParticleVector3"/> for the float2 case.
/// </summary>
public class ParticleVector2
{
[Property] public ParticleFloat X { get; set; }
[Property] public ParticleFloat Y { get; set; }
public ParticleVector2()
{
// Default to constant-zero components so Evaluate never dereferences a null
// ParticleFloat when the editor creates a fresh entry. JSON deserialization
// overwrites these from the serialized X/Y.
X = new ParticleFloat();
Y = new ParticleFloat();
}
public ParticleVector2( ParticleFloat x, ParticleFloat y )
{
X = x;
Y = y;
}
public Vector2 Evaluate( Particle particle, int seed )
{
return new Vector2( X.Evaluate( particle, seed ), Y.Evaluate( particle, seed ) );
}
public static implicit operator ParticleVector2( Vector2 v ) => new ParticleVector2( v.x, v.y );
}