Ok, now this has puzzled me for a day or two, and I can't really figure it out. Here it goes.
Does anybody have any idea how the particle emitter is able to update in edit mode? I know about the
Move the object around, or click on different assets in the project hierarchy, and you will notice that the print statement appears in the console window only when you change something. I know this is desired behavior because you wouldn't want the editor updating everything part all the time if nothing is changing, of course.
Ok, now clear the console window and add a particle emitter. Select the particle emitter if it isn't already selected and take a look at the console window. You will notice that the print statement for our script is being continuously called. If the particle emitter was simply calling the Update method of all of the particles then it shouldn't trigger the Update method on our script, yet it does. So then what is the particle emitter doing?
The real question is...how can I get the same update behavior as the particle emitter while in edit mode of the editor (not play mode)? I know this may be sound awkward, but thanks for any suggestions, ideas, or comments in advanced.
asked Jan 20, 2012 at 08:42 PM
First i'd like to say that a particle emitter is not a script, it's a seperate component (not even a Behaviour, see the class hierarchy). Most of the built-in components are written in native code and just have an Mono / .NET interface for scripting. So if you want to achieve something similar it will work different than a particle emitter / camera / cloth / ...
If you want to implement an continous update in the editor you can use the `EditorApplication.update` -delegate. Keep in mind that all editor functions / classes (the whole UnityEditor namespace) is not available at runtime. So you have to use either conditional compilation to exclude this extra code from your build, or implement the functionality in a custom inspector. With a custom inspector it would only work while it's selected in the inspector.
answered Jan 21, 2012 at 01:55 AM