本文整理汇总了C#中ParticleSystem.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ParticleSystem.GetEnumerator方法的具体用法?C# ParticleSystem.GetEnumerator怎么用?C# ParticleSystem.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParticleSystem
的用法示例。
在下文中一共展示了ParticleSystem.GetEnumerator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public unsafe void Update(ParticleSystem particleSystem, float dt)
{
var lifetimeField = particleSystem.GetOrCreateField(LifetimeField);
// Iterate over particles
var particleEnumerator = particleSystem.GetEnumerator();
while (particleEnumerator.MoveNext())
{
var particle = particleEnumerator.Current;
var lifetime = (float*)particle[lifetimeField];
// Remove particle through enumerator.
// Enumerator will be valid again in next loop.
if ((*lifetime += dt) > Lifetime)
particleEnumerator.RemoveParticle();
}
}
示例2: UpdateSectorLight
protected void UpdateSectorLight (ParticleSystem<Spark>.ParticleCollection particles, LightSource lightSource) {
int particleCount = 0;
int rAccumulator = 0, gAccumulator = 0, bAccumulator = 0, aAccumulator = 0;
Vector2 positionAccumulator = Vector2.Zero;
Spark particle;
using (var e = particles.GetEnumerator())
while (e.GetNext(out particle)) {
particleCount += 1;
positionAccumulator += particle.Position;
var particleColor = particle.GetColor();
rAccumulator += particleColor.R;
gAccumulator += particleColor.G;
bAccumulator += particleColor.B;
aAccumulator += particleColor.A;
}
lightSource.Position = (positionAccumulator / particleCount);
float fParticleCount255 = particleCount * 255.0f;
// FIXME: Need to unpremultiply
lightSource.Color = new Vector4(
rAccumulator / fParticleCount255,
gAccumulator / fParticleCount255,
bAccumulator / fParticleCount255,
aAccumulator / fParticleCount255
);
lightSource.Color.W *= MathHelper.Clamp(particleCount / 20f, 0.1f, 1.0f) * 0.55f;
lightSource.RampStart = 24 + MathHelper.Clamp(particleCount * 0.25f, 0, 24);
lightSource.RampEnd = lightSource.RampStart + 32 + MathHelper.Clamp(particleCount * 0.5f, 0, 48);
lightSource.RampMode = LightSourceRampMode.Exponential;
}