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);
        }
    }
 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;
     }
     NextCacheIndex();
 }
예제 #3
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);
		}
	}
예제 #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;
		NextCacheIndex();
	} 
예제 #5
0
	void OnFollowerDeath (PlaygroundFollower follower)
	{
		Debug.Log ("Follower "+follower.gameObject.name+" died at position "+follower.transform.position);
	}
예제 #6
0
	void OnFollowerBirth (PlaygroundFollower follower)
	{
		Debug.Log ("Follower "+follower.gameObject.name+" is now tracking the particle id: "+follower.particleId);
	}
예제 #7
0
 void OnFollowerDeath(PlaygroundFollower follower)
 {
     Debug.Log("Follower " + follower.gameObject.name + " died at position " + follower.transform.position);
 }
예제 #8
0
 void OnFollowerBirth(PlaygroundFollower follower)
 {
     Debug.Log("Follower " + follower.gameObject.name + " is now tracking the particle id: " + follower.particleId);
 }