UnityMol  0.9.6-875
UnityMol viewer / In developement
ParticleEffect.cs
Go to the documentation of this file.
1 
66 using UnityEngine;
67 using System.Collections;
68 
69 
70 public class ParticleEffect : MonoBehaviour
71 {
72  public Transform particleEffect;
73 
74  public Transform effectObject;
75 
76  public static float radiusFactor = 1.0f;
77 
78  private float radiusFactorold = 1.0f;
79 
80  public int atomcount;
81 // ArrayList atomLocationalist;
82  public Particle[] p ;
83 
84  public Particle[] pn ;
85 
86  public ParticleEmitter emitter;
87 
88 // public bool radiuschange=false;
89 
90  public void Start() {
91  }
92 
93 
94  public void SpawnEffect () {
95  // Instantiate the effect prefab.
96  effectObject = Instantiate(particleEffect, this.transform.position, this.transform.rotation) as Transform;
97 
98  // Parent the new effect to this script's transform.
99  effectObject.parent = this.gameObject.transform;
100 
101  // Get the particle emitter from the new effect object.
102  emitter = effectObject.GetComponent<ParticleEmitter>();
103 
104  // Make sure autodestruct is on so that dead particles systems get destroyed.
105  ParticleAnimator animator = emitter.transform.GetComponent<ParticleAnimator>();
106  if (animator != null)
107  animator.autodestruct = true;
108 
109  // Generate the particles.
110  emitter.Emit(atomcount);
111  pn=new Particle[p.Length];
112  for(int i=0;i<p.Length;i++)
113  {
114  pn[i].size=p[i].size*radiusFactor*2;
115  pn[i].position=p[i].position;
116  pn[i].color=p[i].color;
117  pn[i].energy=p[i].energy;
118  }
119 // pn=p;
120  emitter.particles = pn;
122  }
123 
124  void Update() {
125  if ((p != null) && !UI.UIData.isParticlesInitialized && (UI.UIData.atomtype == UI.UIData.AtomType.particleball) )
126  {
127  SpawnEffect();
128  }
129 
130  // Spin the entire particle effect.
131 // this.transform.Rotate(this.transform.up * Time.deltaTime * (-turnSpeed), Space.World);
132  if(radiusFactorold!=radiusFactor)
133  {
134  if(emitter)
135  {
136  for(int i=0;i<p.Length;i++)
137  pn[i].size=p[i].size*radiusFactor*2;
138  emitter.particles = pn;
139  }
140  radiusFactorold=radiusFactor;
141  }
142  }
143 
144 
145 
146 
147 
148  // Kill all current spawns of the effect.
149  public void killCurrentEffects() {
150 
151  // Loop thru the particle emitter children of this object.
152  // Each one is a particle effect system we want to destroy.
153  ParticleEmitter[] emitters = this.transform.GetComponentsInChildren<ParticleEmitter>();
154  foreach (ParticleEmitter emitter in emitters)
155  {
156  Debug.Log("resetEffect killing: " + emitter.name);
157  // Make sure autodestruct is on.
158  ParticleAnimator animator = emitter.transform.GetComponent<ParticleAnimator>();
159  if (animator != null)
160  animator.autodestruct = true;
161  // Now loop thru the particles and set their energies to a small number. The effect will
162  // subsequently autodestruct. I originally tried setting the energy to zero, but in that
163  // case they did *not* autodestruct.
164  // I originally tried simply doing a Destroy on the emitter, but got threatening runtime messages.
165  Particle[] p = emitter.particles;
166  for (int i=0; i < p.Length; i++)
167  {
168  p[i].energy = 0.1f;
169  }
170  emitter.particles = p;
171  emitter.ClearParticles();
172  }
173  this.gameObject.transform.DetachChildren();
174 // GameObject Particleclone=GameObject.Find("particle(Clone)");
175 // GameObject Particleclone=GameObject.Find("particlein1(Clone)");
176 
177 // Destroy(Particleclone);
178  GameObject[] Particleclone;
179  Particleclone = GameObject.FindGameObjectsWithTag("particlein1");
180  for(int j=0;j<Particleclone.Length;j++)
181  {
182  Destroy(Particleclone[j]);
183  }
184  GameObject[] Particlemanager;
185  Particlemanager = GameObject.FindGameObjectsWithTag("ParticleManager");
186  for(int k=0;k<Particlemanager.Length;k++)
187  {
188  Destroy(Particlemanager[k]);
189  }
190 
191  }
192 }
Particle[] p
ParticleEmitter emitter
Transform particleEffect
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static bool isParticlesInitialized
Definition: UIData.cs:101
static float radiusFactor
static AtomType atomtype
Definition: UIData.cs:139
Transform effectObject
Definition: GUIDisplay.cs:66
Particle[] pn
void killCurrentEffects()