Unity3d 显示指定目录下的所有粒子

这个是一直重复播放粒子的脚本

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;
                }
            }
            
        }

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值