Пример #1
0
        public IEnumerator GetComponent_Passes()
        {
            var obj = new GameObject("test"
                                     , typeof(BoxCollider)
                                     , typeof(MeshFilter));

            var boxCollider = obj.GetComponent <BoxCollider>();
            var meshFilter  = obj.GetComponent <MeshFilter>();

            Assert.AreSame(boxCollider, GameObjectExtensions.GetComponent <BoxCollider>(obj));
            Assert.AreSame(boxCollider, GameObjectExtensions.GetComponent <BoxCollider>(obj.transform));
            Assert.AreSame(boxCollider, GameObjectExtensions.GetComponent <BoxCollider>(meshFilter));

            // Not Attach Component
            Assert.IsNull(GameObjectExtensions.GetComponent <AudioListener>(obj));

            // pass invalid target
            int    n = 0;
            string s = "";

            Assert.IsNull(GameObjectExtensions.GetComponent <BoxCollider>(null));
            Assert.IsNull(GameObjectExtensions.GetComponent <BoxCollider>(n));
            Assert.IsNull(GameObjectExtensions.GetComponent <BoxCollider>(s));


            yield break;
        }