| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 | using UnityEngine;using System.Collections;using System.Collections.Generic;namespace ETFXPEL{public class ParticleEffectsLibrary : MonoBehaviour {	public static ParticleEffectsLibrary GlobalAccess;	void Awake () {		GlobalAccess = this;		currentActivePEList = new List<Transform> ();		TotalEffects = ParticleEffectPrefabs.Length;		CurrentParticleEffectNum = 1;		// Warn About Lengths of Arrays not matching		if (ParticleEffectSpawnOffsets.Length != TotalEffects) {			Debug.LogError ("ParticleEffectsLibrary-ParticleEffectSpawnOffset: Not all arrays match length, double check counts.");		}		if (ParticleEffectPrefabs.Length != TotalEffects) {			Debug.LogError ("ParticleEffectsLibrary-ParticleEffectPrefabs: Not all arrays match length, double check counts.");		}		// Setup Starting PE Name String		effectNameString = ParticleEffectPrefabs [CurrentParticleEffectIndex].name + " (" + CurrentParticleEffectNum.ToString() + " of " + TotalEffects.ToString() + ")";	}	// Stores total number of effects in arrays - NOTE: All Arrays must match length.	public int TotalEffects = 0;	public int CurrentParticleEffectIndex = 0;	public int CurrentParticleEffectNum = 0;//	public string[] ParticleEffectDisplayNames;	public Vector3[] ParticleEffectSpawnOffsets;	// How long until Particle Effect is Destroyed - 0 = never	public float[] ParticleEffectLifetimes;	public GameObject[] ParticleEffectPrefabs;	// Storing for deleting if looping particle effect	#pragma warning disable 414	private string effectNameString = "";	#pragma warning disable 414	private List<Transform> currentActivePEList;	void Start () {	}	public string GetCurrentPENameString() {		return ParticleEffectPrefabs [CurrentParticleEffectIndex].name + " (" + CurrentParticleEffectNum.ToString() + " of " + TotalEffects.ToString() + ")";	}	public void PreviousParticleEffect() {		// Destroy Looping Particle Effects		if (ParticleEffectLifetimes [CurrentParticleEffectIndex] == 0) {			if (currentActivePEList.Count > 0) {				for (int i = 0; i < currentActivePEList.Count; i++) {					if (currentActivePEList [i] != null) {						Destroy (currentActivePEList [i].gameObject);					}				}				currentActivePEList.Clear ();			}		}		// Select Previous Particle Effect		if (CurrentParticleEffectIndex > 0) {			CurrentParticleEffectIndex -= 1;		} else {			CurrentParticleEffectIndex = TotalEffects - 1;		}		CurrentParticleEffectNum = CurrentParticleEffectIndex + 1;		// Update PE Name String		effectNameString = ParticleEffectPrefabs [CurrentParticleEffectIndex].name + " (" + CurrentParticleEffectNum.ToString() + " of " + TotalEffects.ToString() + ")";	}	public void NextParticleEffect() {		// Destroy Looping Particle Effects		if (ParticleEffectLifetimes [CurrentParticleEffectIndex] == 0) {			if (currentActivePEList.Count > 0) {				for (int i = 0; i < currentActivePEList.Count; i++) {					if (currentActivePEList [i] != null) {						Destroy (currentActivePEList [i].gameObject);					}				}				currentActivePEList.Clear ();			}		}		// Select Next Particle Effect		if (CurrentParticleEffectIndex < TotalEffects - 1) {			CurrentParticleEffectIndex += 1;		} else {			CurrentParticleEffectIndex = 0;		}		CurrentParticleEffectNum = CurrentParticleEffectIndex + 1;		// Update PE Name String		effectNameString = ParticleEffectPrefabs [CurrentParticleEffectIndex].name + " (" + CurrentParticleEffectNum.ToString() + " of " + TotalEffects.ToString() + ")";	}	private Vector3 spawnPosition = Vector3.zero;	public void SpawnParticleEffect(Vector3 positionInWorldToSpawn) {		// Spawn Currently Selected Particle Effect		spawnPosition = positionInWorldToSpawn + ParticleEffectSpawnOffsets[CurrentParticleEffectIndex];		GameObject newParticleEffect = GameObject.Instantiate(ParticleEffectPrefabs[CurrentParticleEffectIndex], spawnPosition, ParticleEffectPrefabs[CurrentParticleEffectIndex].transform.rotation) as GameObject;		newParticleEffect.name = "PE_" + ParticleEffectPrefabs[CurrentParticleEffectIndex];		// Store Looping Particle Effects Systems		if (ParticleEffectLifetimes [CurrentParticleEffectIndex] == 0) {			currentActivePEList.Add (newParticleEffect.transform);		}		currentActivePEList.Add(newParticleEffect.transform);		// Destroy Particle Effect After Lifetime expired		if (ParticleEffectLifetimes [CurrentParticleEffectIndex] != 0) {			Destroy(newParticleEffect, ParticleEffectLifetimes[CurrentParticleEffectIndex]);		}	}}}
 |