这个功能并不是很实用,不过美术同学有这样的需求,那么就花了一点时间研究了下。
我们没有使用Unity的引擎,但是做特效的同学找了一批Unity的粒子特效,希望导出成png序列帧的形式,然后我们的游戏来使用。这个就相当于拿Unity做了特效编辑器的工作。这个并不是很“邪门”,因为用幻影粒子,或者3dmax,差不多也是这个思路,只不过那些软件提供了正规的导出功能,而Unity则没有。
先上代码
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class ParticleExporter : MonoBehaviour
{
// Default folder name where you want the animations to be output
public string folder = "PNG_Animations";
// Framerate at which you want to play the animation
public int frameRate = 25; // export frame rate 导出帧率,设置Time.captureFramerate会忽略真实时间,直接使用此帧率
public float frameCount = 100; // export frame count 导出帧的数目,100帧则相当于导出5秒钟的光效时间。由于导出每一帧的时间很长,所以导出时间会远远长于直观的光效播放时间
public int screenWidth = 960; // not use 暂时没用,希望可以直接设置屏幕的大小(即光效画布的大小)
public int screenHeight = 640;
public Vector3 cameraPosition = Vector3.zero;
public Vector3 cameraRotation = Vector3.zero;
private string realFolder = ""; // real folder where the output files will be
private float originaltimescaleTime; // track the original time scale so we can freeze the animation between frames
private float currentTime = 0;
private bool over = false;
private int currentIndex = 0;
private Cam