Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 void AddFollower(PlaygroundFollower follower, int i)
 {
     if (follower == null)
     {
         return;
     }
     followers.Add(follower.Clone());
     followers[followers.Count - 1].enabled    = true;
     followers[followers.Count - 1].gameObject = referenceObjectsCache[cacheIndex].gameObject;
     followers[followers.Count - 1].gameObject.SetActive(true);
     followers[followers.Count - 1].transform          = referenceObjectsCache[cacheIndex].transform;
     followers[followers.Count - 1].trailRenderer      = referenceObjectsCache[cacheIndex].trailRenderer;
     followers[followers.Count - 1].particleId         = follower.particleId;
     followers[followers.Count - 1].transform.position = particles.playgroundCache.position[followers[followers.Count - 1].particleId];
     if (followers[followers.Count - 1].trailRenderer != null)
     {
         followers[followers.Count - 1].trailRenderer.time = trailTime;
     }
     if (sendEvents && followerEventBirth != null)
     {
         followerEventBirth(followers[followers.Count - 1]);
     }
     NextCacheIndex();
 }
Ejemplo n.º 3
0
		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);
			}
		}
Ejemplo n.º 4
0
		void AddFollower (PlaygroundFollower follower, int i) 
		{
			if (follower==null) return;
			followers.Add (follower.Clone());
			followers[followers.Count-1].enabled = true;
			followers[followers.Count-1].gameObject = referenceObjectsCache[cacheIndex].gameObject;
			followers[followers.Count-1].gameObject.SetActive(true);
			followers[followers.Count-1].transform = referenceObjectsCache[cacheIndex].transform;
			followers[followers.Count-1].trailRenderer = referenceObjectsCache[cacheIndex].trailRenderer;
			followers[followers.Count-1].particleId = follower.particleId;
			followers[followers.Count-1].transform.position = particles.playgroundCache.position[followers[followers.Count-1].particleId];
			if (followers[followers.Count-1].trailRenderer!=null)
				followers[followers.Count-1].trailRenderer.time = trailTime;
			if (sendEvents && followerEventBirth!=null)
				followerEventBirth(followers[followers.Count-1]);
			NextCacheIndex();
		}