void Start () {

		// Get the event from your particle system
		playgroundEvent = PlaygroundC.GetEvent (0, particles);

		// Subscribe to the event
		AddEventListener();

		// Cache components of this GameObject (helps performance on low-end devices)
		thisTransform = transform;
		thisCollider = GetComponent<Collider>();
		thisRenderer = GetComponent<Renderer>();

		// Create materials to show if the event listener is active or not
		if (activeMaterial==null) {
			activeMaterial = new Material(Shader.Find ("Diffuse"));
			activeMaterial.color = Color.white;
		}
		if (inactiveMaterial==null) {
			inactiveMaterial = new Material(Shader.Find ("Diffuse"));
			inactiveMaterial.color = Color.black;
		}

		thisRenderer.sharedMaterial = activeMaterial;
	}
	void Start () {

		// Get the first event
		playgroundEvent = PlaygroundC.GetEvent(0, particles);

		// Add listener
		AddListener();
	}
	void Start () {

		if (particles==null) return;

		// Get the first event
		playgroundEvent = PlaygroundC.GetEvent(0, particles);

		// Add listener
		AddListener();
	}
	// Use this for initialization
	void Start () {

		// Events run on a second thread, only use thread-safe methods within the Event Delegate (no GetTransform)
		thisTransform = transform;

		// Get the event from your particle system
		playgroundEvent = PlaygroundC.GetEvent (0, particles);
		
		// Subscribe to the event
		AddEventListener();
	}
		void Start () 
		{
			if (referenceObject == null || particles == null)
				return;

			// Create and setup the birth event
			birthEvent = PlaygroundC.CreateEvent(particles);
			birthEvent.broadcastType = EVENTBROADCASTC.EventListeners;
			birthEvent.eventType = EVENTTYPEC.Birth;

			// Create and setup the death event
			deathEvent = PlaygroundC.CreateEvent(particles);
			deathEvent.broadcastType = EVENTBROADCASTC.EventListeners;
			deathEvent.eventType = EVENTTYPEC.Death;

			// Hook up the event listeners to the delegates
			birthEvent.particleEvent += OnParticleDidBirth;
			deathEvent.particleEvent += OnParticleDidDie;

			// Create a parent for all followers (for Hierarchy convenience)
			followerParent = new GameObject("Followers").transform;
			followerParent.parent = transform;

			// Get the trail renderer (if available) and its time
			referenceTrailRenderer = referenceObject.GetComponent<TrailRenderer>();
			if (referenceTrailRenderer!=null)
				trailTime = referenceTrailRenderer.time;

			// Set an extra amount of followers if required (a trail's time will exceed a particle's)
			int extra = followerLifetime<=0? 
				Mathf.CeilToInt(Mathf.Abs (particles.lifetime-trailTime)+(trailTime-particles.lifetime))+2 : 
					Mathf.CeilToInt(Mathf.Abs (particles.lifetime-followerLifetime)+(followerLifetime-particles.lifetime))+2 ;
			if (particles.lifetime<=1f) extra++;

			// Create the follower cache (this will be iterated through and reused whenever a particle rebirths)
			referenceObjectsCache = new PlaygroundFollower[cacheSize>0? cacheSize : particles.particleCount+Mathf.CeilToInt(particles.particleCount*extra)];
			for (int i = 0; i<referenceObjectsCache.Length; i++) {
				GameObject clone = (GameObject)Instantiate(referenceObject);
				referenceObjectsCache[i] = new PlaygroundFollower(clone.transform, clone, clone.GetComponent<TrailRenderer>(), 0, 0);
				referenceObjectsCache[i].transform.parent = followerParent;
				if (referenceObjectsCache[i].trailRenderer!=null)
					referenceObjectsCache[i].trailRenderer.time = 0;
				referenceObjectsCache[i].gameObject.SetActive(false);
			}
		}
Example #6
0
	void Awake () {

		// Create and setup the birth event
		birthEvent = PlaygroundC.CreateEvent(particles);
		birthEvent.broadcastType = EVENTBROADCASTC.EventListeners;
		birthEvent.eventType = EVENTTYPEC.Birth;

		// Create and setup the death event
		deathEvent = PlaygroundC.CreateEvent(particles);
		deathEvent.broadcastType = EVENTBROADCASTC.EventListeners;
		deathEvent.eventType = EVENTTYPEC.Death;

		// Hook up the event listeners to the delegates
		birthEvent.particleEvent += OnParticleDidBirth;
		deathEvent.particleEvent += OnParticleDidDie;

		// Setup the followers
		followerParent = new GameObject("Followers").transform;
		followerParent.parent = transform;
		referenceTrailRenderer = referenceObject.GetComponent<TrailRenderer>();
		if (referenceTrailRenderer!=null)
			trailTime = referenceTrailRenderer.time;

		int extra = followerLifetime<=0? 
			Mathf.CeilToInt(Mathf.Abs (particles.lifetime-trailTime)+(trailTime-particles.lifetime))+2 : 
				Mathf.CeilToInt(Mathf.Abs (particles.lifetime-followerLifetime)+(followerLifetime-particles.lifetime))+2 ;
		if (particles.lifetime<=1f) extra++;
		referenceObjectsCache = new PlaygroundFollower[cacheSize>0? cacheSize : particles.particleCount+Mathf.CeilToInt(particles.particleCount*extra)];
		for (int i = 0; i<referenceObjectsCache.Length; i++) {
			GameObject clone = (GameObject)Instantiate(referenceObject);
			referenceObjectsCache[i] = new PlaygroundFollower(clone.transform, clone, clone.GetComponent<TrailRenderer>(), 0, 0);
			referenceObjectsCache[i].transform.parent = followerParent;
			if (referenceObjectsCache[i].trailRenderer!=null)
				referenceObjectsCache[i].trailRenderer.time = 0;
			referenceObjectsCache[i].gameObject.SetActive(false);
		}
	}
Example #7
0
		/// <summary>
		/// Creates an event into passed particle system.
		/// </summary>
		/// <returns>The event.</returns>
		/// <param name="playgroundParticles">Particle Playground system.</param>
		public static PlaygroundEventC CreateEvent (PlaygroundParticlesC playgroundParticles) {
			if (playgroundParticles==null) return null;
			PlaygroundEventC playgroundEvent = new PlaygroundEventC();
			if (playgroundParticles.events==null)
				playgroundParticles.events = new List<PlaygroundEventC>();
			playgroundParticles.events.Add (playgroundEvent);
			return playgroundEvent;
		}
Example #8
0
		/// <summary>
		/// Return a copy of this PlaygroundEventC.
		/// </summary>
		public PlaygroundEventC Clone () {
			PlaygroundEventC playgroundEvent = new PlaygroundEventC();
			playgroundEvent.enabled = enabled;
			playgroundEvent.target = target;
			playgroundEvent.eventType = eventType;
			playgroundEvent.eventInheritancePosition = eventInheritancePosition;
			playgroundEvent.eventInheritanceVelocity = eventInheritanceVelocity;
			playgroundEvent.eventInheritanceColor = eventInheritanceColor;
			playgroundEvent.eventPosition = eventPosition;
			playgroundEvent.eventVelocity = eventVelocity;
			playgroundEvent.eventColor = eventColor;
			playgroundEvent.eventTime = eventTime;
			playgroundEvent.collisionThreshold = collisionThreshold;
			playgroundEvent.velocityMultiplier = velocityMultiplier;
			playgroundEvent.particleEvent = particleEvent;
			playgroundEvent.broadcastType = broadcastType;
			return playgroundEvent;
		}
		/// <summary>
		/// Removes the required events to track particles.
		/// </summary>
		public void RemoveRequiredEvents ()
		{
			if (playgroundSystem != null)
			{
				if (birthEvent != null)
				{
					birthEvent.particleEvent -= OnParticleBirthEvent;
					birthEvent = null;
				}
				if (deathEvent != null)
				{
					deathEvent.particleEvent -= OnParticleDeathEvent;
					deathEvent = null;
				}
				if (collisionEvent != null)
				{
					collisionEvent.particleEvent -= OnParticleCollisionEvent;
					collisionEvent = null;
				}
			}
		}
		/// <summary>
		/// Adds the required particle events to track particles.
		/// </summary>
		public void AddRequiredParticleEvents ()
		{
			if (playgroundSystem != null)
			{
				// Hookup events
				birthEvent = GetEventFromType(EVENTTYPEC.Birth);
				if (birthEvent == null)
				{
					birthEvent = PlaygroundC.CreateEvent(playgroundSystem);
					birthEvent.broadcastType = EVENTBROADCASTC.EventListeners;
					birthEvent.eventType = EVENTTYPEC.Birth;
				}
				birthEvent.particleEvent += OnParticleBirthEvent;
				
				deathEvent = GetEventFromType(EVENTTYPEC.Death);
				if (deathEvent == null)
				{
					deathEvent = PlaygroundC.CreateEvent(playgroundSystem);
					deathEvent.broadcastType = EVENTBROADCASTC.EventListeners;
					deathEvent.eventType = EVENTTYPEC.Death;
				}
				deathEvent.particleEvent += OnParticleDeathEvent;
				
				collisionEvent = GetEventFromType(EVENTTYPEC.Collision);
				if (collisionEvent == null)
				{
					collisionEvent = PlaygroundC.CreateEvent(playgroundSystem);
					collisionEvent.broadcastType = EVENTBROADCASTC.EventListeners;
					collisionEvent.eventType = EVENTTYPEC.Collision;
				}
				collisionEvent.particleEvent += OnParticleCollisionEvent;
			}
		}
Example #11
0
 // Use this for initialization
 void Start()
 {
     playgroundEvent = PlaygroundC.GetEvent(0, PlaygroundC.GetParticles(0));
     playgroundEvent.particleEvent += OnEvent;
 }
	public void RenderEventSettings (PlaygroundEventC thisEvent, SerializedProperty serializedEvent) {
		thisEvent.enabled = EditorGUILayout.ToggleLeft("Enabled", thisEvent.enabled);
		GUI.enabled = thisEvent.enabled;

		// Event Broadcast Type
		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("broadcastType"), new GUIContent("Broadcast Type", "Set to broadcast to a Target and/or Event Listeners."));

		// Target
		if (thisEvent.broadcastType!=EVENTBROADCASTC.EventListeners) {
			PlaygroundParticlesC currentTarget = thisEvent.target;
			thisEvent.target = EditorGUILayout.ObjectField("Target", thisEvent.target, typeof(PlaygroundParticlesC), true) as PlaygroundParticlesC;
			if (currentTarget!=thisEvent.target && thisEvent.target!=null) {

				// Assign new target
				if (thisEvent.target == playgroundParticlesScriptReference) {
					thisEvent.target = null;
					triedToAssignSelfTarget = true;
					triedToAssignSnapshot = false;
				} else if (thisEvent.target.isSnapshot) {
					thisEvent.target = null;
					triedToAssignSnapshot = true;
					triedToAssignSelfTarget = false;
				} else {
					triedToAssignSelfTarget = false;
					triedToAssignSnapshot = false;
					if (thisEvent.target.source!=SOURCEC.Script && EditorUtility.DisplayDialog("Switch to Script Mode?", "The event target of "+thisEvent.target.name+" is running in "+thisEvent.target.source.ToString()+" mode. All events must be received by Script Mode.", "Switch", "Cancel"))
						thisEvent.target.source = SOURCEC.Script;
				}
			}
			if (triedToAssignSelfTarget)
				EditorGUILayout.HelpBox("A particle system cannot send events to itself. Please choose another particle system in your Scene.", MessageType.Warning);
			else if (triedToAssignSnapshot)
				EditorGUILayout.HelpBox("A particle system cannot send events to a snapshot. Please choose another particle system in your Scene.", MessageType.Warning);
		}

		EditorGUILayout.Separator();

		// Type
		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventType"), new GUIContent("Type", "The type of event."));

		// Type: Collision
		if (thisEvent.eventType==EVENTTYPEC.Collision) {
			if (!playgroundParticlesScriptReference.collision)
				EditorGUILayout.HelpBox("You must enable collision on this particle system to send collision events.", MessageType.Info);
			thisEvent.collisionThreshold = EditorGUILayout.FloatField ("Collision Threshold", thisEvent.collisionThreshold);
		}

		// Type: Time
		if (thisEvent.eventType == EVENTTYPEC.Time)
			thisEvent.eventTime = EditorGUILayout.FloatField ("Time", thisEvent.eventTime);

		EditorGUILayout.Separator();

		// Settings with inheritance options
		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventInheritancePosition"), new GUIContent("Position", "The inheritance for position."));
		if (thisEvent.eventInheritancePosition == EVENTINHERITANCEC.User) {
			EditorGUI.indentLevel++;
			thisEvent.eventPosition = EditorGUILayout.Vector3Field (" ", thisEvent.eventPosition);
			EditorGUI.indentLevel--;
		}

		EditorGUILayout.Separator();

		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventInheritanceVelocity"), new GUIContent("Velocity", "The inheritance for velocity."));
		if (thisEvent.eventInheritanceVelocity == EVENTINHERITANCEC.User)
			thisEvent.eventVelocity = EditorGUILayout.Vector3Field (" ", thisEvent.eventVelocity);
		thisEvent.velocityMultiplier = EditorGUILayout.FloatField("Velocity Multiplier", thisEvent.velocityMultiplier);

		EditorGUILayout.Separator();

		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventInheritanceColor"), new GUIContent("Color", "The inheritance for color."));
		if (thisEvent.eventInheritanceColor == EVENTINHERITANCEC.User) {
			EditorGUI.indentLevel++;
			thisEvent.eventColor = EditorGUILayout.ColorField(" ", thisEvent.eventColor);
			EditorGUI.indentLevel--;
		}

		GUI.enabled = true;
	}
 /// <summary>
 /// Creates an event into passed particle system.
 /// </summary>
 /// <returns>The event.</returns>
 /// <param name="playgroundParticles">Playground particles.</param>
 public static PlaygroundEventC CreateEvent(PlaygroundParticlesC playgroundParticles)
 {
     PlaygroundEventC playgroundEvent = new PlaygroundEventC();
     playgroundParticles.events.Add (playgroundEvent);
     return playgroundEvent;
 }
	public void RenderEventSettings (PlaygroundEventC thisEvent, SerializedProperty serializedEvent) {
		thisEvent.enabled = EditorGUILayout.ToggleLeft(playgroundLanguage.enabled, thisEvent.enabled);
		GUI.enabled = thisEvent.enabled;

		// Event Broadcast Type
		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("broadcastType"), new GUIContent(playgroundLanguage.broadcastType, playgroundLanguage.broadcastTypeDescription));

		// Target
		if (thisEvent.broadcastType!=EVENTBROADCASTC.EventListeners) {
			PlaygroundParticlesC currentTarget = thisEvent.target;
			thisEvent.target = EditorGUILayout.ObjectField(playgroundLanguage.target, thisEvent.target, typeof(PlaygroundParticlesC), true) as PlaygroundParticlesC;
			if (currentTarget!=thisEvent.target && thisEvent.target!=null) {

				// Assign new target
				if (thisEvent.target == playgroundParticlesScriptReference) {
					thisEvent.target = null;
					triedToAssignSelfTarget = true;
					triedToAssignSnapshot = false;
				} else if (thisEvent.target.isSnapshot) {
					thisEvent.target = null;
					triedToAssignSnapshot = true;
					triedToAssignSelfTarget = false;
				} else {
					triedToAssignSelfTarget = false;
					triedToAssignSnapshot = false;
					if (thisEvent.target.source!=SOURCEC.Script && EditorUtility.DisplayDialog(playgroundLanguage.switchToScriptMode, playgroundLanguage.switchToScriptModeText1+thisEvent.target.name+" "+playgroundLanguage.switchToScriptModeText2+" "+thisEvent.target.source.ToString()+" "+playgroundLanguage.switchToScriptModeText3, playgroundLanguage.switchText, playgroundLanguage.cancel))
						thisEvent.target.source = SOURCEC.Script;
				}
			}
			if (triedToAssignSelfTarget)
				EditorGUILayout.HelpBox(playgroundLanguage.particleSystemEventAssignErrorSelf, MessageType.Warning);
			else if (triedToAssignSnapshot)
				EditorGUILayout.HelpBox(playgroundLanguage.particleSystemEventAssignErrorSnapshot, MessageType.Warning);
		}

		if (thisEvent.broadcastType!=EVENTBROADCASTC.Target) {
			thisEvent.sendToManager = EditorGUILayout.Toggle(playgroundLanguage.sendToManager, thisEvent.sendToManager);
		}

		EditorGUILayout.Separator();

		// Type
		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventType"), new GUIContent(playgroundLanguage.type, playgroundLanguage.typeOfEvent));

		// Type: Collision
		if (thisEvent.eventType==EVENTTYPEC.Collision) {
			if (!playgroundParticlesScriptReference.collision)
				EditorGUILayout.HelpBox(playgroundLanguage.enableCollisionToSendEvents, MessageType.Info);
			thisEvent.collisionThreshold = EditorGUILayout.FloatField (playgroundLanguage.collisionThreshold, thisEvent.collisionThreshold);
		}

		// Type: Time
		if (thisEvent.eventType == EVENTTYPEC.Time)
			thisEvent.eventTime = EditorGUILayout.FloatField (playgroundLanguage.time, thisEvent.eventTime);

		EditorGUILayout.Separator();

		// Settings with inheritance options
		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventInheritancePosition"), new GUIContent(playgroundLanguage.position, playgroundLanguage.inheritancePosition));
		if (thisEvent.eventInheritancePosition == EVENTINHERITANCEC.User) {
			EditorGUI.indentLevel++;
			thisEvent.eventPosition = EditorGUILayout.Vector3Field (" ", thisEvent.eventPosition);
			EditorGUI.indentLevel--;
		}

		EditorGUILayout.Separator();

		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventInheritanceVelocity"), new GUIContent(playgroundLanguage.velocity, playgroundLanguage.inheritanceVelocity));
		if (thisEvent.eventInheritanceVelocity == EVENTINHERITANCEC.User)
			thisEvent.eventVelocity = EditorGUILayout.Vector3Field (" ", thisEvent.eventVelocity);
		thisEvent.velocityMultiplier = EditorGUILayout.FloatField(playgroundLanguage.velocityMultiplier, thisEvent.velocityMultiplier);

		EditorGUILayout.Separator();

		EditorGUILayout.PropertyField(serializedEvent.FindPropertyRelative("eventInheritanceColor"), new GUIContent(playgroundLanguage.color, playgroundLanguage.inheritanceColor));
		if (thisEvent.eventInheritanceColor == EVENTINHERITANCEC.User) {
			EditorGUI.indentLevel++;
			thisEvent.eventColor = EditorGUILayout.ColorField(" ", thisEvent.eventColor);
			EditorGUI.indentLevel--;
		}

		GUI.enabled = true;
	}