码迷,mamicode.com
首页 > 其他好文 > 详细

Unity3D TestTool Part _1

时间:2014-09-17 21:48:12      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   for   

  一直想看看Unity3d官方推出的UnityTestTools的测试插件,今天有空尝试了一下。

 一、Quick Start

  1、 create a plane position which transform position is vector3 (0,0,0),attach a script name it hero.Content next:  

    public float Health = 100f;

    void OnCollisionEnter(Collision collision)
    {
        Health -= 10f;
        Destroy(collision.gameObject);
    }

  2、create a gameobject which transform position is vector3 (0,10,0), attach a script name it Spawn,Context next:

// Use this for initialization
	void Start () {
        InvokeRepeating("CreateRigidbody", 0f, 2f);
	}

    void CreateRigidbody() {
        GameObject tmp = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //不加位置默认(0,0,0)
        tmp.transform.position = transform.position;
        tmp.AddComponent<Rigidbody>();
        
    }

  3. Attach Assertin Component Script,set like next

  bubuko.com,布布扣

     4.Now,Run you sence. When you hero‘s Health below 50 , there is a AssertionException: FloatComparer assertion failed.

   从上述看,这个解决了一些我们在Unity主线程调用函数的时候的一些逻辑判断。这样我们就不用在自己嵌入代码了。缺点就是如果场景太多,这些Component我们又不想要了,就有点麻烦了。

二、Integration Test Runner

  1.Click Unity Test Tools -> Integration Test Runner. Click  Symbol ‘+‘ to create TestRunner.

      bubuko.com,布布扣

  2.Let‘s do something. Create a Plane.you will find the plane auto be the child of New Test. Then Create a cube then attach component rigidbody.

  3.Last, you can attach  Call Testing Script ,Set Config like that .The config is means when the cube collide the plane ,the test runner suscess.

  bubuko.com,布布扣

   4.可以测试在Unity主线程调用的一些函数。

 

 

Unity3D TestTool Part _1

标签:des   style   blog   http   color   io   os   ar   for   

原文地址:http://www.cnblogs.com/chongxin/p/3978079.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!