您的位置:首页 > 移动开发 > Unity3D

Unity3D 查找Update函数体为空的类

2016-05-26 11:23 495 查看
如果是大项目,有很多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 + "\n";
}
}
else if (method.Name.Equals("LateUpdate"))
{
if (method.Body.Instructions.Count <= 2)
{
log += type.Name + "." + method.Name + "\n";
}
}
else if (method.Name.Equals("FixedUpdate"))
{
if (method.Body.Instructions.Count <= 2)
{
log += type.Name + "." + method.Name + "\n";
}
}
}
}
Debug.Log(log);
}

}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: