Esempio n. 1
0
 /// <summary>
 /// Gets the type of event based on the passed in EVETTTYPEC.
 /// </summary>
 /// <returns>The event of type specified.</returns>
 /// <param name="eventType">The event type.</param>
 public PlaygroundEventC GetEventFromType(EVENTTYPEC eventType)
 {
     for (int i = 0; i < playgroundSystem.events.Count; i++)
     {
         if (playgroundSystem.events[i].eventType == eventType)
         {
             return(playgroundSystem.events[i]);
         }
     }
     return(null);
 }
        void SendEvent(EVENTTYPEC eventType, int p, Vector3 preEventVelocity, Transform collisionTransform, Collider collisionCollider, Collider2D collisionCollider2D)
        {
            Vector3 eventPosition = Vector3.zero;
            Vector3 eventVelocity = Vector3.zero;
            Color32 eventColor = Color.white;

            // Loop through available events
            for (int i = 0; i<events.Count; i++) {
                if (events[i].enabled && events[i].eventType==eventType) {

                    // Check thresholds
                    if (events[i].eventType==EVENTTYPEC.Collision)
                        if (events[i].collisionThreshold>preEventVelocity.sqrMagnitude)
                            return;

                    // Set event position
                    switch (events[i].eventInheritancePosition) {
                        case EVENTINHERITANCEC.User:
                        eventPosition = events[i].eventPosition;
                        break;
                        case EVENTINHERITANCEC.Particle:
                        eventPosition = eventType==EVENTTYPEC.Death?playgroundCache.previousParticlePosition[p]:playgroundCache.position[p];
                        break;
                        case EVENTINHERITANCEC.Source:
                        eventPosition = playgroundCache.targetPosition[p];
                        break;
                    }

                    // Set event velocity
                    switch (events[i].eventInheritanceVelocity) {
                        case EVENTINHERITANCEC.User:
                        eventVelocity = events[i].eventVelocity;
                        break;
                        case EVENTINHERITANCEC.Particle:
                        eventVelocity = playgroundCache.velocity[p];
                        break;
                        case EVENTINHERITANCEC.Source:
                        if (applyInitialLocalVelocity)
                            eventVelocity = playgroundCache.initialLocalVelocity[p];
                        if (applyInitialVelocity)
                            eventVelocity += playgroundCache.initialVelocity[p];
                        if (applyLifetimeVelocity)
                            eventVelocity += lifetimeVelocity.Evaluate(Mathf.Clamp01(playgroundCache.life[p]/lifetime), lifetimeVelocityScale);
                        if (applyInitialVelocityShape)
                            eventVelocity = Vector3.Scale(eventVelocity, initialVelocityShape.Evaluate((p*1f)/(particleCount*1f), initialVelocityShapeScale));
                        break;
                    }

                    // Apply multiplier
                    eventVelocity *= events[i].velocityMultiplier;

                    // Set event color
                    switch (events[i].eventInheritanceColor) {
                        case EVENTINHERITANCEC.User:
                        eventColor = events[i].eventColor;
                        break;
                        case EVENTINHERITANCEC.Particle:
                        eventColor = particleCache[p].color;
                        break;
                        case EVENTINHERITANCEC.Source:
                        eventColor = playgroundCache.initialColor[p];
                        break;
                    }

                    // Send the event to any Event Listeners
                    if (events[i].broadcastType==EVENTBROADCASTC.EventListeners || events[i].broadcastType==EVENTBROADCASTC.Both) {

                        UpdateEventParticle(eventParticle, p);
                        eventParticle.collisionCollider = collisionCollider;
                        eventParticle.collisionCollider2D = collisionCollider2D;
                        eventParticle.collisionTransform = collisionTransform;

                        events[i].SendParticleEvent(eventParticle);

                        // Send the event to the Playground Manager
                        if (events[i].sendToManager) {
                            switch (events[i].eventType) {
                                case EVENTTYPEC.Birth:
                                PlaygroundC.SendParticleEventBirth(eventParticle);
                                break;
                                case EVENTTYPEC.Death:
                                PlaygroundC.SendParticleEventDeath(eventParticle);
                                break;
                                case EVENTTYPEC.Collision:
                                PlaygroundC.SendParticleEventCollision(eventParticle);
                                break;
                                case EVENTTYPEC.Time:
                                PlaygroundC.SendParticleEventTime(eventParticle);
                                break;
                            }
                        }
                    }

                    // Send the event to target
                    if (events[i].initializedTarget && (events[i].broadcastType==EVENTBROADCASTC.Target || events[i].broadcastType==EVENTBROADCASTC.Both)) {
                        events[i].target.ThreadSafeEmit(eventPosition, eventVelocity, eventColor);
                    }
                }
            }
        }
 void SendEvent(EVENTTYPEC eventType, int p, Vector3 preEventVelocity, Transform collisionTransform, Collider2D collisionCollider2D)
 {
     SendEvent(eventType, p, preEventVelocity, collisionTransform, null, collisionCollider2D);
 }
 void SendEvent(EVENTTYPEC eventType, int p, Vector3 preEventVelocity)
 {
     SendEvent(eventType, p, preEventVelocity, null, null, null);
 }
 // Sends an event to Event- Targets and Listeners
 void SendEvent(EVENTTYPEC eventType, int p)
 {
     SendEvent(eventType, p, playgroundCache.velocity[p], null, null, null);
 }
		/// <summary>
		/// Gets the type of event based on the passed in EVETTTYPEC.
		/// </summary>
		/// <returns>The event of type specified.</returns>
		/// <param name="eventType">The event type.</param>
		public PlaygroundEventC GetEventFromType (EVENTTYPEC eventType)
		{
			for (int i = 0; i<playgroundSystem.events.Count; i++)
				if (playgroundSystem.events[i].eventType == eventType)
					return playgroundSystem.events[i];
			return null;
		}
		void SendEvent (EVENTTYPEC eventType, int p, Vector3 preEventVelocity, Transform collisionTransform, Collider collisionCollider, Collider2D collisionCollider2D) {
			Vector3 eventPosition = Vector3.zero;
			Vector3 eventVelocity = Vector3.zero;
			Color32 eventColor = Color.white;

			// Loop through available events
			for (int i = 0; i<events.Count; i++) {
				if (events[i].enabled && events[i].eventType==eventType) {

					// Check thresholds
					if (events[i].eventType==EVENTTYPEC.Collision)
						if (events[i].collisionThreshold>preEventVelocity.sqrMagnitude)
							return;
					
					// Set event position
					switch (events[i].eventInheritancePosition) {
						case EVENTINHERITANCEC.User:
						eventPosition = events[i].eventPosition;
						break;
						case EVENTINHERITANCEC.Particle:
						eventPosition = playgroundCache.position[p];
						break;
						case EVENTINHERITANCEC.Source:
						eventPosition = playgroundCache.targetPosition[p];
						break;
					}

					// Set event velocity
					switch (events[i].eventInheritanceVelocity) {
						case EVENTINHERITANCEC.User:
						eventVelocity = events[i].eventVelocity;
						break;
						case EVENTINHERITANCEC.Particle:
						eventVelocity = playgroundCache.velocity[p];
						break;
						case EVENTINHERITANCEC.Source:
						if (applyInitialLocalVelocity)
							eventVelocity = playgroundCache.initialLocalVelocity[p];
						if (applyInitialVelocity)
							eventVelocity += playgroundCache.initialVelocity[p];
						if (applyLifetimeVelocity)
							eventVelocity += lifetimeVelocity.Evaluate(Mathf.Clamp01(playgroundCache.life[p]/lifetime));
						if (applyInitialVelocityShape)
							eventVelocity = Vector3.Scale(eventVelocity, initialVelocityShape.Evaluate((p*1f)/(particleCount*1f)));
						break;
					}

					// Apply multiplier
					eventVelocity *= events[i].velocityMultiplier;

					// Set event color
					switch (events[i].eventInheritanceColor) {
						case EVENTINHERITANCEC.User:
						eventColor = events[i].eventColor;
						break;
						case EVENTINHERITANCEC.Particle:
						eventColor = particleCache[p].color;
						break;
						case EVENTINHERITANCEC.Source:
						eventColor = playgroundCache.initialColor[p];
						break;
					}

					// Send the event to any Event Listeners
					if (events[i].initializedEvent && (events[i].broadcastType==EVENTBROADCASTC.EventListeners || events[i].broadcastType==EVENTBROADCASTC.Both)) {

						eventParticle.particleId = p;
						eventParticle.birth = playgroundCache.birth[p];
						eventParticle.birthDelay = playgroundCache.birthDelay[p];
						eventParticle.changedByProperty = playgroundCache.changedByProperty[p];
						eventParticle.changedByPropertyColor = playgroundCache.changedByPropertyColor[p];
						eventParticle.changedByPropertyColorKeepAlpha = playgroundCache.changedByPropertyColorKeepAlpha[p];
						eventParticle.changedByPropertyColorLerp = playgroundCache.changedByPropertyColorLerp[p];
						eventParticle.changedByPropertyDeath = playgroundCache.changedByPropertyDeath[p];
						eventParticle.changedByPropertySize = playgroundCache.changedByPropertySize[p];
						eventParticle.changedByPropertyTarget = playgroundCache.changedByPropertyTarget[p];
						eventParticle.collisionParticlePosition = playgroundCache.collisionParticlePosition[p];
						eventParticle.color = particleCache[p].color;
						eventParticle.scriptedColor = playgroundCache.scriptedColor[p];
						eventParticle.death = playgroundCache.death[p];
						eventParticle.emission = playgroundCache.emission[p];
						eventParticle.initialColor = playgroundCache.initialColor[p];
						eventParticle.initialLocalVelocity = playgroundCache.initialLocalVelocity[p];
						eventParticle.initialRotation = playgroundCache.initialRotation[p];
						eventParticle.initialSize = playgroundCache.initialSize[p];
						eventParticle.initialVelocity = playgroundCache.initialVelocity[p];
						eventParticle.initialLocalVelocity = playgroundCache.initialLocalVelocity[p];
						eventParticle.life = playgroundCache.life[p];
						eventParticle.lifetimeColorId = playgroundCache.lifetimeColorId[p];
						eventParticle.lifetimeOffset = playgroundCache.lifetimeOffset[p];
						eventParticle.localSpaceMovementCompensation = playgroundCache.localSpaceMovementCompensation[p];
						eventParticle.position = playgroundCache.position[p];
						eventParticle.previousParticlePosition = playgroundCache.previousParticlePosition[p];
						eventParticle.previousTargetPosition = playgroundCache.previousTargetPosition[p];
						eventParticle.propertyColorId = playgroundCache.propertyColorId[p];
						eventParticle.propertyId = playgroundCache.propertyId[p];
						eventParticle.propertyTarget = playgroundCache.propertyTarget[p];
						eventParticle.rebirth = playgroundCache.rebirth[p];
						eventParticle.rotation = playgroundCache.rotation[p];
						eventParticle.rotationSpeed = playgroundCache.rotationSpeed[p];
						eventParticle.scatterPosition = playgroundCache.scatterPosition[p];
						eventParticle.size = playgroundCache.size[p];
						eventParticle.targetDirection = playgroundCache.targetDirection[p];
						eventParticle.targetPosition = playgroundCache.targetPosition[p];
						eventParticle.velocity = playgroundCache.velocity[p];
						eventParticle.collisionCollider = collisionCollider;
						eventParticle.collisionCollider2D = collisionCollider2D;
						eventParticle.collisionTransform = collisionTransform;
						eventParticle.isMasked = playgroundCache.isMasked[p];
						eventParticle.maskAlpha = playgroundCache.maskAlpha[p];

						events[i].SendParticleEvent(eventParticle);
					}

					// Send the event to target
					if (events[i].initializedTarget && (events[i].broadcastType==EVENTBROADCASTC.Target || events[i].broadcastType==EVENTBROADCASTC.Both)) {
						events[i].target.ThreadSafeEmit(eventPosition, eventVelocity, eventColor);
					}
				}
			}
		}