why
After the particle effect prefabrication is completed with Unity, it is saved in the unified special effect directory of the project. When it is needed, it is necessary to select the corresponding particle effect prefabrication. As more and more special effects are prefabricated, it becomes more and more difficult to distinguish which one is really needed. Unity does not provide the function of previewing resources like AnimationClip, but can only drag one by one into the scene to preview and play, which is very time-consuming and laborious.
The target
Implementation like model action animation can preview particles directly in the inspector.
To solve
The final effect of the particle effects preview is similar to that of the model action preview. First, change the FBX model into a particle object, and then make it play in the preview window.The first implementation of the preview window inside the 3D space, using the editor class PreviewRenderUtility, it creates a hidden camera, cullingMask set as long as the specific Layer of the render, render into the target texture, and then draw the texture into the preview window. Next, create the object to be rendered. Lattice floor, directional arrows, and particle effect objects.Finally realize the particle preview playback. There are two methods for simulation of particles in edit mode. One is to call the Simulate method directly. The effect of simulation may be different from that of actual operation. The other option is to call the lock particle and then call the Play method, which will have the same effect as actually running the Play, because Unity will actually evaluate the locked particle object. Used here is the second approach, lock particle method does not open, so have to reflect ParticleSystemEditorUtils lockedParticleSystem method.If the particle root node has a Mesh, the original Mesh preview window will not be displayed, so add a button in the toolbar to switch it. The PS (Show Particle System Preview) button toggles between the original preview window and the particle effects preview window.
conclusion
The Unity editor provides flexible extension methods, but many of them are undocumented and require research into how it is used in order to easily port extensions. Particle effects simulation playback mode, in the case of not selecting the particle object, but also want to make the particle can play, so the only way to lock the particle.
The source code
AssetStore address: www.assetstore.unity3d.com/cn/#! / conte… Github address: github.com/akof1314/Un…