Unity3D 特效粒子数查找工具

http://blog.csdn.net/yangyy753

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

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

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[i]) as GameObject; //创建实例  
            if (objs[i] == null) continue; 
   ParticleSystemRenderer[] renderers = objs[i].GetComponentsInChildren<ParticleSystemRenderer>(true);  //获取特效实例下的所有ParticleRenderer组件  
   foreach (ParticleSystemRenderer render in renderers)  
   {  
                EffectParticle effect = new EffectParticle();  
                ParticleSystem emitter = render.particleSystem;   //获取ParticleEmitter组件  
                effect.name = objs[i].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;  
          
    }  
}  
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值