本文整理汇总了C#中ParticlePlayground.PlaygroundParticlesC.SendEvent方法的典型用法代码示例。如果您正苦于以下问题:C# PlaygroundParticlesC.SendEvent方法的具体用法?C# PlaygroundParticlesC.SendEvent怎么用?C# PlaygroundParticlesC.SendEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParticlePlayground.PlaygroundParticlesC
的用法示例。
在下文中一共展示了PlaygroundParticlesC.SendEvent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendDeathEvents
/// <summary>
/// Sends the death events.
/// </summary>
/// <param name="playgroundParticles">Playground particles.</param>
/// <param name="p">Particle index.</param>
public static void SendDeathEvents(PlaygroundParticlesC playgroundParticles, int p)
{
if ((playgroundParticles.playgroundCache.life[p]>0||playgroundParticles.playgroundCache.changedByPropertyDeath[p]) && !playgroundParticles.playgroundCache.isNonBirthed[p]) {
if (playgroundParticles.loop || (!playgroundParticles.loop && playgroundParticles.playgroundCache.isFirstLoop[p])) {
playgroundParticles.SendEvent(EVENTTYPEC.Death, p);
}
}
if (playgroundParticles.hasEventManipulatorLocal) {
for (int i = 0; i<playgroundParticles.manipulators.Count; i++) {
if (playgroundParticles.manipulators[i].trackParticles &&
playgroundParticles.manipulators[i].RemoveParticle (playgroundParticles.particleSystemId, p)) {
if (playgroundParticles.manipulators[i].sendEventDeath) {
playgroundParticles.UpdateEventParticle(playgroundParticles.manipulators[i].manipulatorEventParticle, p);
playgroundParticles.manipulators[i].SendParticleEventDeath();
}
}
}
}
if (playgroundParticles.hasEventManipulatorGlobal) {
for (int i = 0; i<PlaygroundC.reference.manipulators.Count; i++) {
if (PlaygroundC.reference.manipulators[i].trackParticles &&
PlaygroundC.reference.manipulators[i].RemoveParticle (playgroundParticles.particleSystemId, p)) {
if (PlaygroundC.reference.manipulators[i].sendEventDeath) {
playgroundParticles.UpdateEventParticle(PlaygroundC.reference.manipulators[i].manipulatorEventParticle, p);
PlaygroundC.reference.manipulators[i].SendParticleEventDeath();
}
}
}
}
playgroundParticles.playgroundCache.isNonBirthed[p] = true;
}
示例2: ThreadedCalculations
//.........这里部分代码省略.........
playgroundParticles.particleCache[p].velocity = Vector3.Slerp (playgroundParticles.particleCache[p].velocity, (playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.previousParticlePosition[p])/playgroundParticles.realSimulationTime, t*playgroundParticles.stretchSpeed)*playgroundParticles.stretchLifetime.Evaluate(playgroundParticles.playgroundCache.life[p]/lifeInSeconds);
} else {
if (playgroundParticles.stretchSpeed>0)
playgroundParticles.particleCache[p].velocity = Vector3.Slerp (playgroundParticles.particleCache[p].velocity, (playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.previousParticlePosition[p])/playgroundParticles.realSimulationTime, t*playgroundParticles.stretchSpeed);
else playgroundParticles.particleCache[p].velocity = playgroundParticles.stretchStartDirection;
}
}
playgroundParticles.playgroundCache.previousTargetPosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
}
// Rotation
if (t!=0) {
if (!playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.rotation[p] += playgroundParticles.playgroundCache.rotationSpeed[p]*t;
else if (playgroundParticles.playgroundCache.life[p]!=0) {
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p]+SignedAngle(
up,
playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.previousParticlePosition[p],
playgroundParticles.rotationNormal
);
}
}
if (!playgroundParticles.syncPositionsOnMainThread && playgroundParticles.playgroundCache.life[p]>0)
playgroundParticles.particleCache[p].rotation = playgroundParticles.playgroundCache.rotation[p];
// Set previous particle position
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.position[p];
// Send timed event
if (playgroundParticles.hasTimerEvent)
playgroundParticles.SendEvent(EVENTTYPEC.Time, p);
} else {
playgroundParticles.particleCache[p].size = 0;
playgroundParticles.playgroundCache.position[p] = PlaygroundC.initialTargetPosition;
}
// Calculate lifetime
float evaluatedLife = (playgroundParticles.localTime-playgroundParticles.playgroundCache.birth[p])/lifeInSeconds;
// Lifetime
if (playgroundParticles.playgroundCache.life[p]<playgroundParticles.playgroundCache.death[p]-playgroundParticles.playgroundCache.birth[p]) {
playgroundParticles.playgroundCache.life[p] = lifeInSeconds*evaluatedLife;
if (!playgroundParticles.syncPositionsOnMainThread)
playgroundParticles.particleCache[p].lifetime = Mathf.Clamp (lifeInSeconds*(1f-evaluatedLife), playgroundParticles.minShurikenLifetime, playgroundParticles.playgroundCache.death[p]-playgroundParticles.playgroundCache.birth[p]);
if (playgroundParticles.lifetimeValueMethod==VALUEMETHOD.RandomBetweenTwoValues && playgroundParticles.playgroundCache.life[p]>lifeInSeconds) {
// Send death event for particles with lifetime subtraction
if ((playgroundParticles.hasEvent||playgroundParticles.hasEventManipulatorGlobal||playgroundParticles.hasEventManipulatorLocal) && !playgroundParticles.playgroundCache.isNonBirthed[p])
SendDeathEvents(playgroundParticles, p);
playgroundParticles.particleCache[p].size = 0;
playgroundParticles.particleCache[p].velocity = zero;
playgroundParticles.playgroundCache.position[p] = PlaygroundC.initialTargetPosition;
}
} else {
// Particle exceeded with death property
if (!playgroundParticles.loop && !playgroundParticles.playgroundCache.isNonBirthed[p]) {
// Send death event for particles which died of unnatural cause such as property death, the worst type of death
if (playgroundParticles.hasEvent||playgroundParticles.hasEventManipulatorGlobal||playgroundParticles.hasEventManipulatorLocal)
示例3: Collisions
/// <summary>
/// Calculates particle collisions, this runs automatically if collision is set to true. (Must currently run on main-thread due to the Physics.Raycast dependency.)
/// </summary>
/// <param name="playgroundParticles">Particle Playground system.</param>
public static void Collisions(PlaygroundParticlesC playgroundParticles)
{
if (!playgroundParticles.onlySourcePositioning && !playgroundParticles.onlyLifetimePositioning && playgroundParticles.collisionRadius>0) {
Ray ray = new Ray();
float distance;
bool is3d = playgroundParticles.collisionType==COLLISIONTYPEC.Physics3D;
bool hasCollisionExclusion = playgroundParticles.collisionExclusion!=null && playgroundParticles.collisionExclusion.Count>0;
RaycastHit hitInfo;
RaycastHit2D hitInfo2D;
bool hasEvents = playgroundParticles.events.Count>0;
Vector3 preCollisionVelocity;
// Prepare the infinite collision planes
if (playgroundParticles.collision && playgroundParticles.colliders.Count>0) {
for (int c = 0; c<playgroundParticles.colliders.Count; c++) {
playgroundParticles.colliders[c].UpdatePlane();
}
}
// Check cache length
if (playgroundParticles.playgroundCache.noForce.Length!=playgroundParticles.particleCount)
playgroundParticles.playgroundCache.noForce = new bool[playgroundParticles.particleCount];
if (playgroundParticles.playgroundCache.lifetimeSubtraction.Length!=playgroundParticles.particleCount)
playgroundParticles.playgroundCache.lifetimeSubtraction = new float[playgroundParticles.particleCount];
for (int p = 0; p<playgroundParticles.particleCount; p++) {
if (playgroundParticles.playgroundCache.life[p]==0 || playgroundParticles.playgroundCache.life[p]>=(playgroundParticles.playgroundCache.death[p]-playgroundParticles.playgroundCache.birth[p])-playgroundParticles.playgroundCache.lifetimeSubtraction[p] || playgroundParticles.playgroundCache.noForce[p]) continue;
// Playground Plane colliders (never exceed these)
for (int c = 0; c<playgroundParticles.colliders.Count; c++) {
if (playgroundParticles.colliders[c].enabled && playgroundParticles.colliders[c].transform && !playgroundParticles.colliders[c].plane.GetSide(playgroundParticles.playgroundCache.position[p])) {
// Set particle to location
ray.origin = playgroundParticles.playgroundCache.position[p];
ray.direction = playgroundParticles.colliders[c].plane.normal;
if (playgroundParticles.colliders[c].plane.Raycast(ray, out distance))
playgroundParticles.playgroundCache.position[p] = ray.GetPoint(distance);
// Store velocity before collision
preCollisionVelocity = playgroundParticles.playgroundCache.velocity[p];
// Reflect particle
playgroundParticles.playgroundCache.velocity[p] = Vector3.Reflect(playgroundParticles.playgroundCache.velocity[p], playgroundParticles.colliders[c].plane.normal+RandomVector3(playgroundParticles.internalRandom01, playgroundParticles.bounceRandomMin, playgroundParticles.bounceRandomMax))*playgroundParticles.bounciness;
// Apply lifetime loss
if (playgroundParticles.lifetimeLoss>0) {
playgroundParticles.playgroundCache.birth[p] -= playgroundParticles.playgroundCache.life[p]/(1f-playgroundParticles.lifetimeLoss);
playgroundParticles.playgroundCache.changedByPropertyDeath[p] = true;
}
// Send event
if (hasEvents)
playgroundParticles.SendEvent(EVENTTYPEC.Collision, p, preCollisionVelocity, playgroundParticles.colliders[c].transform);
}
}
// Colliders in scene
if (playgroundParticles.playgroundCache.velocity[p].magnitude>PlaygroundC.collisionSleepVelocity) {
// Collide by checking for potential passed collider in the direction of this particle's velocity from the previous frame
if (is3d) {
if (Physics.Raycast(
playgroundParticles.playgroundCache.collisionParticlePosition[p],
(playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.collisionParticlePosition[p]).normalized,
out hitInfo,
(Vector3.SqrMagnitude(playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.collisionParticlePosition[p])+playgroundParticles.collisionRadius)*2f,
playgroundParticles.collisionMask))
{
// Check that this object isn't excluded
if (hasCollisionExclusion) {
if (playgroundParticles.collisionExclusion.Contains(hitInfo.transform))
continue;
}
// Set particle to location
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.collisionParticlePosition[p];
// Store velocity before collision
preCollisionVelocity = playgroundParticles.playgroundCache.velocity[p];
// Reflect particle
playgroundParticles.playgroundCache.velocity[p] = Vector3.Reflect(playgroundParticles.playgroundCache.velocity[p], hitInfo.normal+RandomVector3(playgroundParticles.internalRandom01, playgroundParticles.bounceRandomMin, playgroundParticles.bounceRandomMax))*playgroundParticles.bounciness;
// Apply lifetime loss
if (playgroundParticles.lifetimeLoss>0) {
playgroundParticles.playgroundCache.birth[p] -= playgroundParticles.playgroundCache.life[p]/(1f-playgroundParticles.lifetimeLoss);
playgroundParticles.playgroundCache.changedByPropertyDeath[p] = true;
}
// Add force to rigidbody
if (playgroundParticles.affectRigidbodies && hitInfo.rigidbody)
hitInfo.rigidbody.AddForceAtPosition((playgroundParticles.inverseRigidbodyCollision?-preCollisionVelocity:preCollisionVelocity)*playgroundParticles.mass, playgroundParticles.playgroundCache.position[p]);
// Send event
//.........这里部分代码省略.........
示例4: Rebirth
//.........这里部分代码省略.........
} else {
if (!playgroundParticles.applyLifetimePositioningPositionScale) {
playgroundParticles.playgroundCache.position[p] =
playgroundParticles.playgroundCache.targetPosition[p]+
playgroundParticles.lifetimePositioning.Evaluate(0, playgroundParticles.lifetimePositioningScale);
} else {
playgroundParticles.playgroundCache.position[p] =
playgroundParticles.playgroundCache.targetPosition[p]+
playgroundParticles.lifetimePositioning.Evaluate(0, playgroundParticles.lifetimePositioningScale)*
playgroundParticles.lifetimePositioningPositionScale.Evaluate(0);
}
}
if (!playgroundParticles.syncPositionsOnMainThread)
playgroundParticles.particleCache[p].position = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.playgroundCache.collisionParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
}
if (playgroundParticles.applyInitialColorOnRebirth) {
playgroundParticles.particleCache[p].color = playgroundParticles.playgroundCache.initialColor[p];
playgroundParticles.playgroundCache.color[p] = playgroundParticles.playgroundCache.initialColor[p];
}
} else {
playgroundParticles.particleCache[p].position = PlaygroundC.initialTargetPosition;
}
// Set new random rotation
if (playgroundParticles.applyRandomRotationOnRebirth && !playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.initialRotation[p] = RandomRange(random, playgroundParticles.initialRotationMin, playgroundParticles.initialRotationMax);
if (!playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p];
else {
Vector3 particleDir;
if (!playgroundParticles.onlySourcePositioning&&playgroundParticles.onlyLifetimePositioning)
particleDir = (playgroundParticles.playgroundCache.position[p]+playgroundParticles.lifetimePositioning.Evaluate(.01f, playgroundParticles.lifetimePositioningScale))-playgroundParticles.playgroundCache.position[p];
else
particleDir = playgroundParticles.playgroundCache.velocity[p];
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p]+SignedAngle(
Vector3.up,
particleDir,
playgroundParticles.rotationNormal
);
}
if (!playgroundParticles.syncPositionsOnMainThread)
playgroundParticles.particleCache[p].rotation = playgroundParticles.playgroundCache.rotation[p];
// Set size
if (playgroundParticles.applyLifetimeSize && !playgroundParticles.applyParticleArraySize)
playgroundParticles.playgroundCache.size[p] = playgroundParticles.playgroundCache.initialSize[p]*playgroundParticles.lifetimeSize.Evaluate(0)*playgroundParticles.scale;
else if (playgroundParticles.applyLifetimeSize && playgroundParticles.applyParticleArraySize)
playgroundParticles.playgroundCache.size[p] = playgroundParticles.playgroundCache.initialSize[p]*playgroundParticles.lifetimeSize.Evaluate(0)*playgroundParticles.particleArraySize.Evaluate((p*1f)/(playgroundParticles.particleCount*1f))*playgroundParticles.scale;
else if (playgroundParticles.applyParticleArraySize)
playgroundParticles.playgroundCache.size[p] = playgroundParticles.playgroundCache.initialSize[p]*playgroundParticles.particleArraySize.Evaluate((p*1f)/(playgroundParticles.particleCount*1f))*playgroundParticles.scale;
else playgroundParticles.playgroundCache.size[p] = playgroundParticles.playgroundCache.initialSize[p]*playgroundParticles.scale;
if (!playgroundParticles.syncPositionsOnMainThread)
playgroundParticles.particleCache[p].size = playgroundParticles.playgroundCache.maskAlpha[p]>0?playgroundParticles.playgroundCache.size[p]:0;
// Set color gradient id
if (playgroundParticles.colorSource==COLORSOURCEC.LifetimeColors && playgroundParticles.lifetimeColors.Count>0) {
playgroundParticles.lifetimeColorId++;playgroundParticles.lifetimeColorId=playgroundParticles.lifetimeColorId%playgroundParticles.lifetimeColors.Count;
playgroundParticles.playgroundCache.lifetimeColorId[p] = playgroundParticles.lifetimeColorId;
}
// Local Manipulators
if (playgroundParticles.calculateManipulatorOnRebirth) {
for (int m = 0; m<playgroundParticles.manipulators.Count; m++) {
if (playgroundParticles.manipulators[m].transform!=null) {
CalculateManipulator(playgroundParticles, playgroundParticles.manipulators[m], p, playgroundParticles.t, playgroundParticles.playgroundCache.life[p], playgroundParticles.playgroundCache.position[p], (playgroundParticles.localSpace?playgroundParticles.manipulators[m].transform.localPosition:playgroundParticles.manipulators[m].transform.position)+playgroundParticles.manipulatorFix, playgroundParticles.localSpace);
}
}
}
// Send birth event
if (playgroundParticles.events.Count>0 && playgroundParticles.playgroundCache.rebirth[p])
playgroundParticles.SendEvent(EVENTTYPEC.Birth, p);
if (playgroundParticles.hasEventManipulatorLocal) {
for (int i = 0; i<playgroundParticles.manipulators.Count; i++) {
if (playgroundParticles.manipulators[i].trackParticles &&
playgroundParticles.manipulators[i].sendEventBirth &&
playgroundParticles.manipulators[i].Contains (playgroundParticles.playgroundCache.targetPosition[p], playgroundParticles.manipulators[i].transform.position)) {
playgroundParticles.UpdateEventParticle(playgroundParticles.manipulators[i].manipulatorEventParticle, p);
playgroundParticles.manipulators[i].SendParticleEventBirth();
}
}
}
if (playgroundParticles.hasEventManipulatorGlobal) {
for (int i = 0; i<PlaygroundC.reference.manipulators.Count; i++) {
if (PlaygroundC.reference.manipulators[i].trackParticles &&
PlaygroundC.reference.manipulators[i].sendEventBirth &&
PlaygroundC.reference.manipulators[i].Contains (playgroundParticles.playgroundCache.targetPosition[p], PlaygroundC.reference.manipulators[i].transform.position)) {
playgroundParticles.UpdateEventParticle(PlaygroundC.reference.manipulators[i].manipulatorEventParticle, p);
PlaygroundC.reference.manipulators[i].SendParticleEventBirth();
}
}
}
}
示例5: Rebirth
//.........这里部分代码省略.........
// Set initial values
playgroundParticles.playgroundCache.birthDelay[p] = 0f;
playgroundParticles.playgroundCache.life[p] = 0f;
playgroundParticles.playgroundCache.birth[p] = playgroundParticles.playgroundCache.death[p];
playgroundParticles.playgroundCache.death[p] += playgroundParticles.lifetime;
playgroundParticles.playgroundCache.rebirth[p] = playgroundParticles.source==SOURCEC.Script?true:(playgroundParticles.emit && playgroundParticles.playgroundCache.emission[p]);
playgroundParticles.playgroundCache.velocity[p] = Vector3.zero;
// Set new random size
if (playgroundParticles.applyRandomSizeOnRebirth)
playgroundParticles.playgroundCache.initialSize[p] = RandomRange(random, playgroundParticles.sizeMin, playgroundParticles.sizeMax);
// Initial velocity
if (!playgroundParticles.onlySourcePositioning) {
// Initial global velocity
if (playgroundParticles.applyInitialVelocity) {
if (playgroundParticles.applyRandomInitialVelocityOnRebirth)
playgroundParticles.playgroundCache.initialVelocity[p] = RandomRange(random, playgroundParticles.initialVelocityMin, playgroundParticles.initialVelocityMax);
playgroundParticles.playgroundCache.velocity[p] = playgroundParticles.playgroundCache.initialVelocity[p];
// Give this spawning particle its velocity shape
if (playgroundParticles.applyInitialVelocityShape)
playgroundParticles.playgroundCache.velocity[p] = Vector3.Scale(playgroundParticles.playgroundCache.velocity[p], playgroundParticles.initialVelocityShape.Evaluate((p*1f)/(playgroundParticles.particleCount*1f)));
}
// Initial local velocity
if (playgroundParticles.applyInitialLocalVelocity && playgroundParticles.source!=SOURCEC.Script) {
playgroundParticles.playgroundCache.initialLocalVelocity[p] = RandomRange(random, playgroundParticles.initialLocalVelocityMin, playgroundParticles.initialLocalVelocityMax);
playgroundParticles.playgroundCache.velocity[p] += playgroundParticles.playgroundCache.targetDirection[p];
// Give this spawning particle its local velocity shape
if (playgroundParticles.applyInitialVelocityShape)
playgroundParticles.playgroundCache.velocity[p] = Vector3.Scale(playgroundParticles.playgroundCache.velocity[p], playgroundParticles.initialVelocityShape.Evaluate((p*1f)/(playgroundParticles.particleCount*1f)));
}
// Initial stretch
if (playgroundParticles.renderModeStretch) {
if (playgroundParticles.playgroundCache.velocity[p]!=Vector3.zero)
playgroundParticles.particleCache[p].velocity = playgroundParticles.playgroundCache.velocity[p];
else
playgroundParticles.particleCache[p].velocity = playgroundParticles.stretchStartDirection;
} else
playgroundParticles.particleCache[p].velocity = Vector3.zero;
}
if (playgroundParticles.source==SOURCEC.Script) {
// Velocity for script mode
if (!playgroundParticles.onlySourcePositioning)
playgroundParticles.playgroundCache.velocity[p] += playgroundParticles.scriptedEmissionVelocity;
playgroundParticles.playgroundCache.targetPosition[p] = playgroundParticles.scriptedEmissionPosition;
}
if (playgroundParticles.playgroundCache.rebirth[p]) {
// Set new random rotation
if (playgroundParticles.playgroundCache.initialRotation.Length!=playgroundParticles.particleCount) return;
if (playgroundParticles.applyRandomRotationOnRebirth)
playgroundParticles.playgroundCache.initialRotation[p] = RandomRange(random, playgroundParticles.initialRotationMin, playgroundParticles.initialRotationMax);
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p];
playgroundParticles.particleCache[p].rotation = playgroundParticles.playgroundCache.rotation[p];
// Source Scattering
if (playgroundParticles.applySourceScatter && playgroundParticles.source!=SOURCEC.Script) {
if (playgroundParticles.playgroundCache.scatterPosition[p]==Vector3.zero || playgroundParticles.applyRandomScatterOnRebirth)
playgroundParticles.playgroundCache.scatterPosition[p] = RandomRange(random, playgroundParticles.sourceScatterMin, playgroundParticles.sourceScatterMax);
} else playgroundParticles.playgroundCache.scatterPosition[p] = Vector3.zero;
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.particleCache[p].position = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.playgroundCache.collisionParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
if (playgroundParticles.applyInitialColorOnRebirth) {
playgroundParticles.particleCache[p].color = playgroundParticles.playgroundCache.initialColor[p];
playgroundParticles.playgroundCache.color[p] = playgroundParticles.playgroundCache.initialColor[p];
}
} else playgroundParticles.particleCache[p].position = PlaygroundC.initialTargetPosition;
// Set color gradient id
if (playgroundParticles.colorSource==COLORSOURCEC.LifetimeColors && playgroundParticles.lifetimeColors.Count>0) {
playgroundParticles.lifetimeColorId++;playgroundParticles.lifetimeColorId=playgroundParticles.lifetimeColorId%playgroundParticles.lifetimeColors.Count;
playgroundParticles.playgroundCache.lifetimeColorId[p] = playgroundParticles.lifetimeColorId;
}
// Reset manipulators influence
playgroundParticles.playgroundCache.changedByProperty[p] = false;
playgroundParticles.playgroundCache.changedByPropertyColor[p] = false;
playgroundParticles.playgroundCache.changedByPropertyColorLerp[p] = false;
playgroundParticles.playgroundCache.changedByPropertyColorKeepAlpha[p] = false;
playgroundParticles.playgroundCache.changedByPropertySize[p] = false;
playgroundParticles.playgroundCache.changedByPropertyTarget[p] = false;
playgroundParticles.playgroundCache.changedByPropertyDeath[p] = false;
playgroundParticles.playgroundCache.propertyTarget[p] = 0;
playgroundParticles.playgroundCache.propertyId[p] = 0;
playgroundParticles.playgroundCache.propertyColorId[p] = 0;
// Send birth event
if (playgroundParticles.events.Count>0)
playgroundParticles.SendEvent(EVENTTYPEC.Birth, p);
}
示例6: Collisions
public static void Collisions (PlaygroundParticlesC playgroundParticles) {
// Particle collisions (must currently run on main-thread due to the Physics.Raycast dependency)
if (!playgroundParticles.onlySourcePositioning && playgroundParticles.collisionRadius>0) {
Ray ray = new Ray();
float distance;
bool is3d = playgroundParticles.collisionType==COLLISIONTYPEC.Physics3D;
RaycastHit hitInfo;
RaycastHit2D hitInfo2D;
bool hasEvents = playgroundParticles.events.Count>0;
Vector3 preCollisionVelocity;
// Prepare the infinite collision planes
if (playgroundParticles.collision && playgroundParticles.collisionRadius>0 && playgroundParticles.colliders.Count>0) {
for (int c = 0; c<playgroundParticles.colliders.Count; c++) {
playgroundParticles.colliders[c].UpdatePlane();
}
}
for (int p = 0; p<playgroundParticles.particleCount; p++) {
if (playgroundParticles.playgroundCache.life[p]==0 || playgroundParticles.playgroundCache.life[p]>=playgroundParticles.lifetime) continue;
// Playground Plane colliders (never exceed these)
for (int c = 0; c<playgroundParticles.colliders.Count; c++) {
if (playgroundParticles.colliders[c].enabled && playgroundParticles.colliders[c].transform && !playgroundParticles.colliders[c].plane.GetSide(playgroundParticles.playgroundCache.position[p])) {
// Set particle to location
ray.origin = playgroundParticles.playgroundCache.position[p];
ray.direction = playgroundParticles.colliders[c].plane.normal;
if (playgroundParticles.colliders[c].plane.Raycast(ray, out distance))
playgroundParticles.playgroundCache.position[p] = ray.GetPoint(distance);
// Store velocity before collision
preCollisionVelocity = playgroundParticles.playgroundCache.velocity[p];
// Reflect particle
playgroundParticles.playgroundCache.velocity[p] = Vector3.Reflect(playgroundParticles.playgroundCache.velocity[p], playgroundParticles.colliders[c].plane.normal+RandomVector3(playgroundParticles.internalRandom03, playgroundParticles.bounceRandomMin, playgroundParticles.bounceRandomMax))*playgroundParticles.bounciness;
// Apply lifetime loss
if (playgroundParticles.lifetimeLoss>0) {
playgroundParticles.playgroundCache.birth[p] -= playgroundParticles.playgroundCache.life[p]/(1f-playgroundParticles.lifetimeLoss);
playgroundParticles.playgroundCache.changedByPropertyDeath[p] = true;
}
// Send event
if (hasEvents)
playgroundParticles.SendEvent(EVENTTYPEC.Collision, p, preCollisionVelocity, playgroundParticles.colliders[c].transform);
}
}
// Colliders in scene
if (playgroundParticles.playgroundCache.velocity[p].magnitude>PlaygroundC.collisionSleepVelocity) {
// Collide by checking for potential passed collider in the direction of this particle's velocity from the previous frame
if (is3d) {
if (Physics.Raycast(
playgroundParticles.playgroundCache.collisionParticlePosition[p],
(playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.collisionParticlePosition[p]).normalized,
out hitInfo,
Vector3.Distance(playgroundParticles.playgroundCache.collisionParticlePosition[p], playgroundParticles.playgroundCache.position[p])+playgroundParticles.collisionRadius,
playgroundParticles.collisionMask))
{
// Set particle to location
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.collisionParticlePosition[p];
// Store velocity before collision
preCollisionVelocity = playgroundParticles.playgroundCache.velocity[p];
// Reflect particle
playgroundParticles.playgroundCache.velocity[p] = Vector3.Reflect(playgroundParticles.playgroundCache.velocity[p], hitInfo.normal+RandomVector3(playgroundParticles.internalRandom03, playgroundParticles.bounceRandomMin, playgroundParticles.bounceRandomMax))*playgroundParticles.bounciness;
// Apply lifetime loss
if (playgroundParticles.lifetimeLoss>0) {
playgroundParticles.playgroundCache.birth[p] -= playgroundParticles.playgroundCache.life[p]/(1f-playgroundParticles.lifetimeLoss);
playgroundParticles.playgroundCache.changedByPropertyDeath[p] = true;
}
// Add force to rigidbody
if (playgroundParticles.affectRigidbodies && hitInfo.rigidbody)
hitInfo.rigidbody.AddForceAtPosition(playgroundParticles.playgroundCache.velocity[p]*playgroundParticles.mass, playgroundParticles.playgroundCache.position[p]);
// Send event
if (hasEvents)
playgroundParticles.SendEvent(EVENTTYPEC.Collision, p, preCollisionVelocity, hitInfo.transform, hitInfo.collider);
}
} else {
hitInfo2D = Physics2D.Raycast(
playgroundParticles.playgroundCache.collisionParticlePosition[p],
(playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.collisionParticlePosition[p]).normalized,
Vector3.Distance(playgroundParticles.playgroundCache.collisionParticlePosition[p], playgroundParticles.playgroundCache.position[p])+playgroundParticles.collisionRadius,
playgroundParticles.collisionMask,
playgroundParticles.minCollisionDepth,
playgroundParticles.maxCollisionDepth
);
if (hitInfo2D.collider!=null) {
// Set particle to location
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.collisionParticlePosition[p];
//.........这里部分代码省略.........
示例7: ThreadedCalculations
//.........这里部分代码省略.........
// Only Source Positioning
// Set particle velocity to be able to stretch towards movement
if (playgroundParticles.renderModeStretch) {
if (playgroundParticles.applyLifetimeStretching)
playgroundParticles.particleCache[p].velocity = Vector3.Slerp (playgroundParticles.particleCache[p].velocity, playgroundParticles.playgroundCache.targetPosition[p]-playgroundParticles.playgroundCache.previousTargetPosition[p], t*playgroundParticles.stretchSpeed)*playgroundParticles.stretchLifetime.Evaluate(playgroundParticles.playgroundCache.life[p]/playgroundParticles.lifetime);
else
playgroundParticles.particleCache[p].velocity = Vector3.Slerp (playgroundParticles.particleCache[p].velocity, playgroundParticles.playgroundCache.targetPosition[p]-playgroundParticles.playgroundCache.previousTargetPosition[p], t*playgroundParticles.stretchSpeed);
}
playgroundParticles.playgroundCache.previousTargetPosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
if (playgroundParticles.source!=SOURCEC.Script)
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.targetPosition[p];
}
// Rotation
if (!playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.rotation[p] += playgroundParticles.playgroundCache.rotationSpeed[p]*t;
else {
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p]+SignedAngle(
up,
playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.previousParticlePosition[p],
playgroundParticles.rotationNormal
);
}
playgroundParticles.particleCache[p].rotation = playgroundParticles.playgroundCache.rotation[p];
// Set previous particle position
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.position[p];
// Send timed event
if (hasTimerEvent)
playgroundParticles.SendEvent(EVENTTYPEC.Time, p);
}
// Calculate lifetime
evaluatedLife = (PlaygroundC.globalTime-playgroundParticles.playgroundCache.birth[p])/playgroundParticles.lifetime;
// Lifetime
if (playgroundParticles.playgroundCache.life[p]<playgroundParticles.lifetime) {
playgroundParticles.playgroundCache.life[p] = playgroundParticles.lifetime*evaluatedLife;
playgroundParticles.particleCache[p].lifetime = Mathf.Clamp(playgroundParticles.lifetime - playgroundParticles.playgroundCache.life[p], .1f, playgroundParticles.lifetime);
} else {
// Loop exceeded
if (!playgroundParticles.loop && PlaygroundC.globalTime>playgroundParticles.simulationStarted+playgroundParticles.lifetime-.01f) {
playgroundParticles.loopExceeded = true;
if (playgroundParticles.disableOnDone && playgroundParticles.loopExceededOnParticle==p && evaluatedLife>2)
playgroundParticles.queueEmissionHalt = true;
if (playgroundParticles.loopExceededOnParticle==-1)
playgroundParticles.loopExceededOnParticle = p;
}
// Send death event
if (hasEvent) {
playgroundParticles.SendEvent(EVENTTYPEC.Death, p);
}
// New cycle begins
if (PlaygroundC.globalTime>=playgroundParticles.playgroundCache.birth[p]+playgroundParticles.playgroundCache.birthDelay[p] && !playgroundParticles.loopExceeded && playgroundParticles.source!=SOURCEC.Script) {
if (!playgroundParticles.playgroundCache.changedByPropertyDeath[p] || playgroundParticles.playgroundCache.changedByPropertyDeath[p] && PlaygroundC.globalTime>playgroundParticles.playgroundCache.death[p])
Rebirth(playgroundParticles, p, playgroundParticles.internalRandom02);
else {
示例8: ThreadedCalculations
//.........这里部分代码省略.........
playgroundParticles.playgroundCache.targetPosition[p]+
playgroundParticles.lifetimePositioning.Evaluate(normalizedLife*lifetimePositioningTimeScale, playgroundParticles.lifetimePositioningScale)*
playgroundParticles.lifetimePositioningPositionScale.Evaluate(normalizedLife*lifetimePositioningTimeScale);
}
}
}
} else if (playgroundParticles.source!=SOURCEC.Script) {
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.targetPosition[p];
}
playgroundParticles.playgroundCache.previousTargetPosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
}
// Rotation
if (!playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.rotation[p] += playgroundParticles.playgroundCache.rotationSpeed[p]*t;
else if (playgroundParticles.playgroundCache.life[p]!=0) {
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p]+SignedAngle(
up,
playgroundParticles.playgroundCache.position[p]-playgroundParticles.playgroundCache.previousParticlePosition[p],
playgroundParticles.rotationNormal
);
}
if (playgroundParticles.playgroundCache.life[p]>0)
playgroundParticles.particleCache[p].rotation = playgroundParticles.playgroundCache.rotation[p];
// Set previous particle position
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.position[p];
// Send timed event
if (playgroundParticles.hasTimerEvent)
playgroundParticles.SendEvent(EVENTTYPEC.Time, p);
} else {
playgroundParticles.playgroundCache.position[p] = PlaygroundC.initialTargetPosition;
playgroundParticles.particleCache[p].size = 0;
}
// Calculate lifetime
evaluatedLife = (PlaygroundC.globalTime-playgroundParticles.playgroundCache.birth[p])/(playgroundParticles.lifetime-playgroundParticles.playgroundCache.lifetimeSubtraction[p]);
// Lifetime
if (playgroundParticles.playgroundCache.life[p]<playgroundParticles.lifetime) {
playgroundParticles.playgroundCache.life[p] = (playgroundParticles.lifetime-playgroundParticles.playgroundCache.lifetimeSubtraction[p])*evaluatedLife;
playgroundParticles.particleCache[p].lifetime = Mathf.Clamp(playgroundParticles.lifetime - playgroundParticles.playgroundCache.life[p], .1f, playgroundParticles.lifetime-playgroundParticles.playgroundCache.lifetimeSubtraction[p]);
if (playgroundParticles.lifetimeValueMethod==VALUEMETHOD.RandomBetweenTwoValues && playgroundParticles.playgroundCache.life[p]>playgroundParticles.lifetime-playgroundParticles.playgroundCache.lifetimeSubtraction[p]) {
// Send death event for particles with lifetime subtraction
if (playgroundParticles.hasEvent && !playgroundParticles.playgroundCache.isNonBirthed[p])
SendDeathEvents(playgroundParticles, p);
playgroundParticles.playgroundCache.position[p] = PlaygroundC.initialTargetPosition;
playgroundParticles.particleCache[p].size = 0;
}
} else {
// Loop exceeded
if (!playgroundParticles.loop && PlaygroundC.globalTime>playgroundParticles.simulationStarted+playgroundParticles.lifetime-.01f) {
playgroundParticles.loopExceeded = true;
if (playgroundParticles.loopExceededOnParticle==p && evaluatedLife>2f) {
if (playgroundParticles.disableOnDone)
playgroundParticles.queueEmissionHalt = true;
playgroundParticles.threadHadNoActiveParticles = true;
示例9: Rebirth
//.........这里部分代码省略.........
if (playgroundParticles.playgroundCache.scatterPosition[p]==Vector3.zero || playgroundParticles.applyRandomScatterOnRebirth)
playgroundParticles.playgroundCache.scatterPosition[p] = RandomRange(random, playgroundParticles.sourceScatterMin, playgroundParticles.sourceScatterMax);
} else playgroundParticles.playgroundCache.scatterPosition[p] = Vector3.zero;
if (!playgroundParticles.onlyLifetimePositioning) {
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.particleCache[p].position = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
playgroundParticles.playgroundCache.collisionParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p];
} else if (!playgroundParticles.onlySourcePositioning) {
Vector3 evalLifetimePosition = playgroundParticles.lifetimePositioning.Evaluate(0f, playgroundParticles.lifetimePositioningScale);
if (playgroundParticles.lifetimePositioningUsesSourceDirection)
evalLifetimePosition = playgroundParticles.playgroundCache.targetDirection[p];
playgroundParticles.playgroundCache.position[p] = playgroundParticles.playgroundCache.targetPosition[p]+evalLifetimePosition;
playgroundParticles.particleCache[p].position = playgroundParticles.playgroundCache.targetPosition[p]+evalLifetimePosition;
playgroundParticles.playgroundCache.previousParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p]+evalLifetimePosition;
playgroundParticles.playgroundCache.collisionParticlePosition[p] = playgroundParticles.playgroundCache.targetPosition[p]+evalLifetimePosition;
}
if (playgroundParticles.applyInitialColorOnRebirth) {
playgroundParticles.particleCache[p].color = playgroundParticles.playgroundCache.initialColor[p];
playgroundParticles.playgroundCache.color[p] = playgroundParticles.playgroundCache.initialColor[p];
}
} else {
playgroundParticles.particleCache[p].position = PlaygroundC.initialTargetPosition;
}
// Set new random rotation
if (playgroundParticles.applyRandomRotationOnRebirth && !playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.initialRotation[p] = RandomRange(random, playgroundParticles.initialRotationMin, playgroundParticles.initialRotationMax);
if (!playgroundParticles.rotateTowardsDirection)
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p];
else {
Vector3 particleDir;
if (!playgroundParticles.onlySourcePositioning&&playgroundParticles.onlyLifetimePositioning)
particleDir = (playgroundParticles.playgroundCache.position[p]+playgroundParticles.lifetimePositioning.Evaluate(.01f, playgroundParticles.lifetimePositioningScale))-playgroundParticles.playgroundCache.position[p];
else
particleDir = playgroundParticles.playgroundCache.velocity[p];
playgroundParticles.playgroundCache.rotation[p] = playgroundParticles.playgroundCache.initialRotation[p]+SignedAngle(
Vector3.up,
particleDir,
playgroundParticles.rotationNormal
);
}
playgroundParticles.particleCache[p].rotation = playgroundParticles.playgroundCache.rotation[p];
// Set size
if (playgroundParticles.applyLifetimeSize) {
//playgroundParticles.playgroundCache.size[p] = playgroundParticles.playgroundCache.initialSize[p]*playgroundParticles.lifetimeSize.Evaluate(0f)*playgroundParticles.scale;
} else
playgroundParticles.playgroundCache.size[p] = playgroundParticles.playgroundCache.initialSize[p]*playgroundParticles.scale;
playgroundParticles.particleCache[p].size = p>=playgroundParticles.particleMask?playgroundParticles.playgroundCache.size[p]:0;
// Set color gradient id
if (playgroundParticles.colorSource==COLORSOURCEC.LifetimeColors && playgroundParticles.lifetimeColors.Count>0) {
playgroundParticles.lifetimeColorId++;playgroundParticles.lifetimeColorId=playgroundParticles.lifetimeColorId%playgroundParticles.lifetimeColors.Count;
playgroundParticles.playgroundCache.lifetimeColorId[p] = playgroundParticles.lifetimeColorId;
}
// Reset manipulators influence
playgroundParticles.playgroundCache.changedByProperty[p] = false;
playgroundParticles.playgroundCache.changedByPropertyColor[p] = false;
playgroundParticles.playgroundCache.changedByPropertyColorLerp[p] = false;
playgroundParticles.playgroundCache.changedByPropertyColorKeepAlpha[p] = false;
playgroundParticles.playgroundCache.changedByPropertySize[p] = false;
playgroundParticles.playgroundCache.changedByPropertyTarget[p] = false;
playgroundParticles.playgroundCache.changedByPropertyDeath[p] = false;
playgroundParticles.playgroundCache.propertyTarget[p] = 0;
playgroundParticles.playgroundCache.propertyId[p] = 0;
playgroundParticles.playgroundCache.propertyColorId[p] = 0;
playgroundParticles.playgroundCache.manipulatorId[p] = 0;
// Send birth event
if (playgroundParticles.events.Count>0 && playgroundParticles.playgroundCache.rebirth[p])
playgroundParticles.SendEvent(EVENTTYPEC.Birth, p);
if (playgroundParticles.hasEventManipulatorLocal) {
for (int i = 0; i<playgroundParticles.manipulators.Count; i++) {
if (playgroundParticles.manipulators[i].trackParticles &&
playgroundParticles.manipulators[i].sendEventBirth &&
playgroundParticles.manipulators[i].Contains (playgroundParticles.playgroundCache.targetPosition[p], playgroundParticles.manipulators[i].transform.position)) {
playgroundParticles.UpdateEventParticle(playgroundParticles.manipulators[i].manipulatorEventParticle, p);
playgroundParticles.manipulators[i].SendParticleEventBirth();
}
}
}
if (playgroundParticles.hasEventManipulatorGlobal) {
for (int i = 0; i<PlaygroundC.reference.manipulators.Count; i++) {
if (PlaygroundC.reference.manipulators[i].trackParticles &&
PlaygroundC.reference.manipulators[i].sendEventBirth &&
PlaygroundC.reference.manipulators[i].Contains (playgroundParticles.playgroundCache.targetPosition[p], PlaygroundC.reference.manipulators[i].transform.position)) {
playgroundParticles.UpdateEventParticle(PlaygroundC.reference.manipulators[i].manipulatorEventParticle, p);
PlaygroundC.reference.manipulators[i].SendParticleEventBirth();
}
}
}
}