Giter Site home page Giter Site logo

unityparticlesystempreview's Introduction

Unity 粒子特效预览工具

原因

在使用 Unity 制作完成粒子特效预制后,保存到工程统一的特效目录里,待到需要使用的时候,再去选择相应的粒子特效预制。当特效预制越来越多后,就会越来越难以分辨哪个才是真正需要使用的,而 Unity 并没有提供像模型动作动画 AnimationClip 那样可以预览资源的功能,只能一个个拖动到场景里面去预览播放,非常的费时费劲。

目标

实现像模型动作动画那样可以直接在检视器里进行预览粒子。

解决

粒子特效预览最后要实现的效果跟模型动作动画预览类似,先将 FBX 模型换成粒子物体,然后再实现其在预览窗口里面可以进行播放。

首先实现预览窗口里面的三维空间,使用到的编辑器类 PreviewRenderUtility,它创建了一个隐藏的摄像机,cullingMask 设置为只要渲染的特定 Layer 层,渲染成目标纹理,然后绘制纹理到预览窗口里。接着,创建所要被渲染的物体。格子平面地板,指示方向箭头,还有粒子特效对象。

最后实现粒子的预览播放。粒子在编辑模式下的模拟播放有两种方式,一种直接调用 Simulate 方法,播放的效果跟实际运行播放的效果可能存在差别。另一种则是调用锁定粒子,再调用 Play 方法,效果会跟实际运行播放的效果一样,因为 Unity 内部会对锁定的粒子对象,进行真实计算。这里使用的是第二种方法,锁定粒子的方法并没有开放出来,所以得反射 ParticleSystemEditorUtils.lockedParticleSystem 方法。

对于粒子特效根节点就带有 Mesh 的话,就无法显示原本的 Mesh 预览窗口,所以在工具栏加个按钮,可以进行切换。

按钮 PS (Show particle system preview)可以在原先的预览窗口跟粒子特效预览窗口之间进行切换。

结语

Unity 编辑器提供了灵活的扩展方法,但是很多都是没有文档的,需要去研究它自身是如何使用的,才能方便移植扩展。粒子特效的模拟播放方式,在不选中粒子对象的情况下,又想让粒子可以播放,那么就只有锁定粒子这种方式。

源码

AssetStore 地址:https://www.assetstore.unity3d.com/cn/#!/content/73346

Github 地址:https://github.com/akof1314/UnityParticleSystemPreview

unityparticlesystempreview's People

Contributors

akof1314 avatar

Watchers

chuanbo song avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.