查看: 519|回复: 0
打印 上一主题 下一主题

[其他] 特效发射粒子数查找工具(转载加修改版)

[复制链接]
may    

8830

主题

80

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52304
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-6-28 02:36:53 |只看该作者 |倒序浏览
[url=]http://blog.csdn.net/yangyy753[/url]

原帖分享了这个工具,就不在这里重复赘述了,但是是针对老粒子特效的,并且中间有一些错误,稍微改动了下,并且添加了修改粒子数的新功能,不需要的可以去掉。

适用新粒子系统,新粒子系统中只能获得设置的最大粒子数和当前粒子数,无法获得实际运行中的最大粒子数。虽然可以运行时取得,但是并不是我们想要的方法,有好方法的可以分享下。

using UnityEngine;  
using System.Collections;  
using UnityEditor;  
using System.Collections.Generic;  
  
public class EffectEmitChecker : EditorWindow  
{  
    float ThumbnailWidth = 40;  
    float ThumbnailHeight = 40;  
    GUIStyle style = new GUIStyle();  
    Vector2 vec2 = new Vector2(0, 0);  
    List<EffectParticle> listEffect = new List<EffectParticle>();   //缓存特效信息  
  
    [MenuItem("Effect/Effect Emit Checker")]  
    static void MainTask()  
    {  
  EffectEmitChecker window = GetWindow<EffectEmitChecker>();  
        window.LoadEffect();   //加载特效  
  window.Show();  
    }  
  
    void OnGUI()  
    {  
        ListEffect();  
    }  
  
    void LoadEffect()  
    {  
  GameObject[] objs = (GameObject[])Resources.LoadAll<GameObject>("Effects");  //读取所有特效文件,可以根据情况改变地址
        for (int i = 0; i < objs.Length; i++)  
        {  
            //GameObject go = PrefabUtility.InstantiatePrefab(objs) as GameObject; //创建实例  
            if (objs == null) continue;
   ParticleSystemRenderer[] renderers = objs.GetComponentsInChildren<ParticleSystemRenderer>(true);  //获取特效实例下的所有ParticleRenderer组件  
   foreach (ParticleSystemRenderer render in renderers)  
   {  
                EffectParticle effect = new EffectParticle();  
                ParticleSystem emitter = render.particleSystem;   //获取ParticleEmitter组件  
                effect.name = objs.name;  
                effect.material = render.sharedMaterial;  
                if (emitter != null)  
    {  
                    effect.maxEmission = emitter.maxParticles;   //最大发射粒子数赋值  
               }  
    effect.prefab = emitter.gameObject;  
    listEffect.Add(effect);  
            }  
           // DestroyImmediate(go);   //销毁实例  
        }
        listEffect.Sort((x, y) => { return y.maxEmission.CompareTo(x.maxEmission); });  //从大到小排序  
        style.normal.textColor = Color.red;  
        style.fixedWidth = 120;  
    }  
  
    void ListEffect()  
    {  
        vec2 = EditorGUILayout.BeginScrollView(vec2);  
        foreach (EffectParticle effectParticle in listEffect)  
        {  
            if (effectParticle != null)  
            {  
                GUILayout.BeginHorizontal();  
  
                Material mat = effectParticle.material;  
                if (mat != null)  
                {  
                    //根据材质找到相应的纹理显示  
                    Texture texture = mat.mainTexture;  
                    if (texture != null)  
                        GUILayout.Box(texture, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));  
                    else  
                        GUILayout.Box("N/A", GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));  
  
                    GUILayout.Label("Shader:" + mat.shader.name, GUILayout.Width(140)); //Shader名称  
  
                    //特效主颜色显示  
                    if (mat.HasProperty("_Color"))  
                        EditorGUILayout.ColorField(mat.color, GUILayout.Width(50));  
                    else if (mat.HasProperty("_TintColor"))  
                        EditorGUILayout.ColorField(mat.GetColor("_TintColor"), GUILayout.Width(50));  
                    else  
                        GUILayout.Box("N/A", GUILayout.Width(50));  
                }  
  
                //发射粒子数判断  
                float emission = effectParticle.maxEmission;  
                if (emission < 50)  
                    GUILayout.Label("MaxEmission:" + emission.ToString(), GUILayout.Width(120));  
                else  
    {GUILayout.Label("MaxEmission:" + emission.ToString(), style);
     //字体标红  
     //effectParticle.prefab.GetComponent<ParticleSystemRenderer>().particleSystem.maxParticles =50; //将大于50的修改为50(慎用,会导致粒子效果改变)
      
    }
  
                //特效名称,并可定位到相应文件  
                if (GUILayout.Button(effectParticle.name))  
                    Selection.activeObject = effectParticle.prefab;  
  
                //文件所在路径节点  
             //   GUILayout.TextField("Node:" + effectParticle.prefab.hierarcyPath);  
  
                GUILayout.EndHorizontal();  
           }  
        }  
        EditorGUILayout.EndScrollView();  
    }  
  
    //特效信息实体类  
    class EffectParticle  
   {  
        public string name;  
        public Material material;  
        public float maxEmission;  
        public GameObject prefab;  
        public bool bScaleWithTransform;  
        public EffectParticle()  
        {  
            maxEmission = 0;  
         
    }  
}  
}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-4 19:44 , Processed in 0.083834 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部