这个是一直重复播放粒子的脚本
using UnityEngine;
public class ParticleAlwayPlay : MonoBehaviour
{
private ParticleSystem[] arr;
// Use this for initialization
void Start ()
{
arr = gameObject.GetComponentsInChildren<ParticleSystem>();
InvokeRepeating("repeat", 1f, 1f);
}
void repeat()
{
foreach (var item in arr)
{
if (item.isStopped)
{
item.Play();
}
}
}
}
这个加载显示所有粒子的
using System.IO;
using UnityEngine;
public class ParticleAllShow : MonoBehaviour {
//要显示的路径
public string fullPath = "Assets/Resources/effect";
public int widthInterval = 5;
public int hightInterval =5;
public Vector3 OrignoalPos=Vector3.zero;
// Use this for initialization
void Start()
{
//获取指定路径下面的所有资源文件
if (Directory.Exists(fullPath))
{
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
foreach (var info in files)
{
string filePath = info.FullName;
if (filePath.EndsWith(".prefab"))
{
// Debug.Log(filePath);//\Assets\Resources\effect\building\Altar_touch.prefab
string resourcesPath = filePath.Split(new string[] {"Resources\\"}, System.StringSplitOptions.None)[1];
//去掉后缀
resourcesPath = resourcesPath.Substring(0, resourcesPath.LastIndexOf("."));
// Debug.Log(resourcesPath);//effect\skill\release\wlxb_ycattack
//把资源加载到内存中 ,不要加后缀名,和Resources, 如:路径"Resources/effect/building/Altar.prefab",那么写成"effect/building/Altar"
GameObject prefab = (GameObject)Resources.Load(resourcesPath);
if (prefab)
{
//用加载得到的资源对象,实例化游戏对象,实现游戏物体的动态加载
GameObject obj = GameObject.Instantiate(prefab, OrignoalPos,Quaternion.identity) as GameObject;
if (obj)
{
obj.name = info.Name;
obj.AddComponent<ParticleAlwayPlay>();
}
}
OrignoalPos.x += widthInterval;
OrignoalPos.z += hightInterval;
}
}
}
}
}