非常好用的Unity测试工具


下载地址


在使用Unity开发时,有些时候想要测试MonoBehaviour中的一些方法,但是又不想去单独写用例调用它,(想根据自己的需要在任何你觉得舒服的时候调用它)


这个时候就可以使用这个工具,首先需要 FunctionCallerAttribute.cs  和AbstractFunctionCallerEditor.cs ,AbstractFunctionCallerEditor.cs是支持MonoBehaviour编辑器的

一些代码,不用在意那些细节。bstractFunctionCallerEditor.cs就是关联你的方法和按钮的类,一看便知~


使用过程:

1、编写一个对应monoBehaviour的editor类这个类不是继承于Editor 而是AbstractFunctionCallerEditor ,下例:


[CustomEditor(typeof(LightManager))]
public class LightManagerEditor : AbstractFunctionCallerEditor
{

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
    }
}

2、在你需要测试的方法的上一行加上一句话:

[FunctionCallerAttribute("TurnOffTheLight")]
    public void TurnOffTheLight(){}

此时在编辑器中就会发现一个按钮:

这样在任何需要的时候都可以调用这个方法了~


8月 13日

发布了43 篇原创文章 · 获赞 2 · 访问量 6万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章