zoukankan      html  css  js  c++  java
  • Unity3D 查找Update函数体为空的类

    如果是大项目,有很多Update空跑还是多少有些效率损耗,那我们就把他们都找出来。

    先引用Mono.Cecil

    //代码

    using UnityEngine;
    using UnityEditor;
    using System.Collections;
    using System.IO;
    using System.Collections.Generic;
    using System.Text;
    
    //处理UILabel
    public class EmptyUpdateCleaner
    {
    
    	[MenuItem("Tools/Log Empty Update")]
    	public static void Test()
    	{
    		string log = "";
    		var module = Mono.Cecil.ModuleDefinition.ReadModule(Application.dataPath+ "/../Temp/UnityVS_bin/Debug/Assembly-CSharp.dll");
    		foreach (var type in module.Types)
    		{
    			if (null==type.BaseType)
    			{
    				continue;
    			}
    
    			if (!type.BaseType.Name.Contains("MonoBehaviour"))
    			{
    				continue;
    			}
    
    			foreach (var method in type.Methods)
    			{
    				if (method.Name.Equals("Update"))
    				{
    					if (method.Body.Instructions.Count <= 2)
    					{
    						log += type.Name + "."+method.Name + "
    ";						
    					}
    				}
    				else if (method.Name.Equals("LateUpdate"))
    				{
    					if (method.Body.Instructions.Count <= 2)
    					{
    						log += type.Name + "." + method.Name + "
    ";
    					}
    				}
    				else if (method.Name.Equals("FixedUpdate"))
    				{
    					if (method.Body.Instructions.Count <= 2)
    					{
    						log += type.Name + "." + method.Name + "
    ";
    					}
    				}
    			}
    		}
    		Debug.Log(log);
    	}
    
    	
    	
    }
    

      

  • 相关阅读:
    css顺序
    修改input默认样式
    H5 新特性之全局属性 三
    h5 全局新属性 四
    H5 新特性之全局属性一
    [心得]VS2008免编译立即生效的方法
    让vs2008支持jQuery的智能提示!
    Winson.Framework 3.3 发布!!
    通过反射自动填充实体
    Winson.SqlPager 2.5 发布!
  • 原文地址:https://www.cnblogs.com/mrblue/p/5530370.html
Copyright © 2011-2022 走看看