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

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

[复制链接]
may    

8830

主题

81

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52352
精华
343

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

跳转到指定楼层
楼主
发表于 2015-11-22 08:24:13 |只看该作者 |倒序浏览

[url=]http://blog.csdn.net/yangyy753[/url]

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

适用新粒子系统,新粒子系统中只能获得设置的最大粒子数和当前粒子数,无法获得实际运行中的最大粒子数。虽然可以运行时取得,但是并不是我们想要的方法,有好方法的可以分享下。
  1. using UnityEngine;  
  2. using System.Collections;  
  3. using UnityEditor;  
  4. using System.Collections.Generic;  
  5.   
  6. public class EffectEmitChecker : EditorWindow  
  7. {  
  8.     float ThumbnailWidth = 40;  
  9.     float ThumbnailHeight = 40;  
  10.     GUIStyle style = new GUIStyle();  
  11.     Vector2 vec2 = new Vector2(0, 0);  
  12.     List<EffectParticle> listEffect = new List<EffectParticle>();   //缓存特效信息  
  13.   
  14.     [MenuItem("Effect/Effect Emit Checker")]  
  15.     static void MainTask()  
  16.     {  
  17.   EffectEmitChecker window = GetWindow<EffectEmitChecker>();  
  18.         window.LoadEffect();   //加载特效  
  19.   window.Show();  
  20.     }  
  21.   
  22.     void OnGUI()  
  23.     {  
  24.         ListEffect();  
  25.     }  
  26.   
  27.     void LoadEffect()  
  28.     {  
  29.   GameObject[] objs = (GameObject[])Resources.LoadAll<GameObject>("Effects");  //读取所有特效文件,可以根据情况改变地址
  30.         for (int i = 0; i < objs.Length; i++)  
  31.         {  
  32.             //GameObject go = PrefabUtility.InstantiatePrefab(objs[i]) as GameObject; //创建实例  
  33.             if (objs[i] == null) continue;
  34.    ParticleSystemRenderer[] renderers = objs[i].GetComponentsInChildren<ParticleSystemRenderer>(true);  //获取特效实例下的所有ParticleRenderer组件  
  35.    foreach (ParticleSystemRenderer render in renderers)  
  36.    {  
  37.                 EffectParticle effect = new EffectParticle();  
  38.                 ParticleSystem emitter = render.particleSystem;   //获取ParticleEmitter组件  
  39.                 effect.name = objs[i].name;  
  40.                 effect.material = render.sharedMaterial;  
  41.                 if (emitter != null)  
  42.     {  
  43.                     effect.maxEmission = emitter.maxParticles;   //最大发射粒子数赋值  
  44.                }  
  45.     effect.prefab = emitter.gameObject;  
  46.     listEffect.Add(effect);  
  47.             }  
  48.            // DestroyImmediate(go);   //销毁实例  
  49.         }
  50.         listEffect.Sort((x, y) => { return y.maxEmission.CompareTo(x.maxEmission); });  //从大到小排序  
  51.         style.normal.textColor = Color.red;  
  52.         style.fixedWidth = 120;  
  53.     }  
  54.   
  55.     void ListEffect()  
  56.     {  
  57.         vec2 = EditorGUILayout.BeginScrollView(vec2);  
  58.         foreach (EffectParticle effectParticle in listEffect)  
  59.         {  
  60.             if (effectParticle != null)  
  61.             {  
  62.                 GUILayout.BeginHorizontal();  
  63.   
  64.                 Material mat = effectParticle.material;  
  65.                 if (mat != null)  
  66.                 {  
  67.                     //根据材质找到相应的纹理显示  
  68.                     Texture texture = mat.mainTexture;  
  69.                     if (texture != null)  
  70.                         GUILayout.Box(texture, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));  
  71.                     else  
  72.                         GUILayout.Box("N/A", GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));  
  73.   
  74.                     GUILayout.Label("Shader:" + mat.shader.name, GUILayout.Width(140)); //Shader名称  
  75.   
  76.                     //特效主颜色显示  
  77.                     if (mat.HasProperty("_Color"))  
  78.                         EditorGUILayout.ColorField(mat.color, GUILayout.Width(50));  
  79.                     else if (mat.HasProperty("_TintColor"))  
  80.                         EditorGUILayout.ColorField(mat.GetColor("_TintColor"), GUILayout.Width(50));  
  81.                     else  
  82.                         GUILayout.Box("N/A", GUILayout.Width(50));  
  83.                 }  
  84.   
  85.                 //发射粒子数判断  
  86.                 float emission = effectParticle.maxEmission;  
  87.                 if (emission < 50)  
  88.                     GUILayout.Label("MaxEmission:" + emission.ToString(), GUILayout.Width(120));  
  89.                 else  
  90.     {GUILayout.Label("MaxEmission:" + emission.ToString(), style);
  91.      //字体标红  
  92.      //effectParticle.prefab.GetComponent<ParticleSystemRenderer>().particleSystem.maxParticles =50; //将大于50的修改为50(慎用,会导致粒子效果改变)
  93.       
  94.     }
  95.   
  96.                 //特效名称,并可定位到相应文件  
  97.                 if (GUILayout.Button(effectParticle.name))  
  98.                     Selection.activeObject = effectParticle.prefab;  
  99.   
  100.                 //文件所在路径节点  
  101.              //   GUILayout.TextField("Node:" + effectParticle.prefab.hierarcyPath);  
  102.   
  103.                 GUILayout.EndHorizontal();  
  104.            }  
  105.         }  
  106.         EditorGUILayout.EndScrollView();  
  107.     }  
  108.   
  109.     //特效信息实体类  
  110.     class EffectParticle  
  111.    {  
  112.         public string name;  
  113.         public Material material;  
  114.         public float maxEmission;  
  115.         public GameObject prefab;  
  116.         public bool bScaleWithTransform;  
  117.         public EffectParticle()  
  118.         {  
  119.             maxEmission = 0;  
  120.          
  121.     }  
  122. }  
  123. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

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

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-8-5 20:37 , Processed in 0.083537 second(s), 29 queries .

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

© 2008-2019 Narkii Inc.

回顶部