public void ItWillBeSetToBeAPrefabIfTheGameObjectIsAPRefab()
 {
     GameObject go = new GameObject() { isPrefab = true };
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.isPrefab, Is.EqualTo(go.isPrefab));
 }
 public void ItWillHaveTheGameObjectSet()
 {
     GameObject go = new GameObject();
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.gameObject, Is.SameAs(go));
 }
Ejemplo n.º 3
0
 public void ItWillBeTheSameAsTheGameObjectName()
 {
     GameObject go = new GameObject() { name = "My fab component" };
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.name, Is.EqualTo(go.name));
 }
Ejemplo n.º 4
0
 public void WeCanFindAComponentInTheSameObject()
 {
     TestComponent comp = new TestComponent();
     root.AddComponent(comp);
     TestComponent[] components = root.GetComponents<TestComponent>();
     Assert.That(components, Is.Not.Null);
     Assert.That(components, Contains.Item(comp));
 }
Ejemplo n.º 5
0
 public void WeCanFindAComponentInTheSameObjectNonGeneric()
 {
     TestComponent comp = new TestComponent();
     root.AddComponent(comp);
     Component[] components = root.GetComponents(typeof(TestComponent));
     Assert.That(components, Is.Not.Null);
     Assert.That(components, Contains.Item(comp));
 }
Ejemplo n.º 6
0
 public void ItWillBeAwokenWhenAddedToTheGameObject()
 {
     bool isAwoken = false;
     GameObject go = new GameObject();
     TestComponent comp = new TestComponent() { onAwake = () => isAwoken = true };
     go.AddComponent(comp);
     Assert.That(isAwoken, Is.True);
 }
Ejemplo n.º 7
0
        public void InstantiatingAPrefabWillMakeNonPrefabObjects()
        {
            GameObject obj = new GameObject() { isPrefab = true };
            TestComponent comp = new TestComponent();
            obj.AddComponent(comp);

            TestComponent instance = GameObject.Instantiate(comp) as TestComponent;
            Assert.That(instance.isPrefab, Is.False);
            Assert.That(instance.gameObject.isPrefab, Is.False);
        }
Ejemplo n.º 8
0
        public void InstantiatingAComponentInAwakeWillAwakeThemImmidiately()
        {
            int awakeCalls = 0;
            GameObject objPrefab = new GameObject(true);
            TestComponent compPrefab = new TestComponent() { onAwake = () => { awakeCalls++; } };
            objPrefab.AddComponent(compPrefab);
            Assert.That(awakeCalls, Is.EqualTo(1));

            TestComponent inst = (TestComponent)UnityObject.Instantiate(compPrefab);
            Assert.That(awakeCalls, Is.EqualTo(2));
        }
Ejemplo n.º 9
0
        public void OnAComponentItsGameObjectWillBeMarkedNotToBeDestroyedOnLevelLoad()
        {
            TestHierarchy h = new TestHierarchy();
            TestComponent tc = new TestComponent();
            h.childOfChild.AddComponent(tc);

            Assert.That(Application.dontDestroyOnLoad, !Contains.Item(h.childOfChild));
            UnityObject.DontDestroyOnLoad(tc);

            Assert.That(Application.dontDestroyOnLoad, Contains.Item(h.childOfChild));
        }
Ejemplo n.º 10
0
        public void TheIdMapWillNotContainPrefabs()
        {
            GameObject go = new GameObject(true);
            TestComponent cmp = new TestComponent();
            go.AddComponent(cmp);

            Dictionary<int, UnityObject> ids = new Dictionary<int, UnityObject>();
            go.SetNewId(ids);

            Assert.That(ids.Count, Is.EqualTo(0));
        }
Ejemplo n.º 11
0
        public void PrefabsWillNotGetNewIds()
        {
            GameObject go = new GameObject(true);
            TestComponent cmp = new TestComponent();
            go.AddComponent(cmp);

            int oldId = go.GetInstanceID();
            int oldCmpId = cmp.GetInstanceID();
            go.SetNewId(new Dictionary<int, UnityObject>());

            Assert.That(go.GetInstanceID(), Is.EqualTo(oldId));
            Assert.That(cmp.GetInstanceID(), Is.EqualTo(oldCmpId));
        }
Ejemplo n.º 12
0
 public void WeCanFindAllComponentsInTheParentHierarchy()
 {
     TestComponent comp = new TestComponent();
     TestComponent comp1 = new TestComponent();
     TestComponent comp2 = new TestComponent();
     root.AddComponent(comp);
     child.AddComponent(comp1);
     child.AddComponent(comp2);
     TestComponent[] components = childOfChild.GetComponentsInParents<TestComponent>();
     Assert.That(components, Is.Not.Null);
     Assert.That(components, Contains.Item(comp));
     Assert.That(components, Contains.Item(comp1));
     Assert.That(components, Contains.Item(comp2));
 }
Ejemplo n.º 13
0
        public void AnInstantiatedComponentWillHaveACloneOfTheGameObjectAsWell()
        {
            GameObject obj = new GameObject() { name = "MyObject", active = true, layer = 10, tag = "Mytag" };
            TestComponent comp = new TestComponent();
            obj.AddComponent(comp);

            TestComponent comp1 = Component.Instantiate(comp) as TestComponent;
            Assert.That(comp1, Is.Not.Null);
            Assert.That(comp1.gameObject, Is.Not.Null);
            Assert.That(comp1.gameObject, Is.Not.EqualTo(obj));
            Assert.That(comp1.gameObject.name, Is.EqualTo(obj.name + "(Clone)"));
            Assert.That(comp1.gameObject.active, Is.True);
            Assert.That(comp1.gameObject.layer, Is.EqualTo(obj.layer));
            Assert.That(comp1.gameObject.tag, Is.EqualTo(obj.tag));
        }
Ejemplo n.º 14
0
        public void Setup()
        {
            Assert.Inconclusive("We need to separate the Application from the Game in order to do this!");
            GameObject go = new GameObject();
            component = new TestComponent();
            go.AddComponent(component);

            GameObject child = new GameObject();
            childComponent = new TestComponent();
            child.AddComponent(childComponent);
            child.transform.parent = go.transform;

            GameObject prefab = new GameObject();
            prefabComponent = new TestComponent();
            prefab.AddComponent(prefabComponent);

            app = new Application(new Game());
        }
Ejemplo n.º 15
0
        public void WeWillSetTheIdOnTheComponentsOfAGameObject()
        {
            GameObject obj = new GameObject();
            TestComponent comp = new TestComponent();
            obj.AddComponent(comp);
            int id = comp.GetInstanceID();
            obj.SetNewId(new Dictionary<int, UnityObject>());

            Assert.That(comp.GetInstanceID(), Is.Not.EqualTo(id));
        }
 public void SetUp()
 {
     go = new GameObject();
     comp = go.AddComponent(new TestComponent());
 }
Ejemplo n.º 17
0
        public void WeWillInstantiateTheCorrectComponent()
        {
            GameObject obj = new GameObject();
            TestComponent comp = new TestComponent();
            TestComponent comp1 = new TestComponent() { Tag = "This" };
            obj.AddComponent(comp);
            obj.AddComponent(comp1);

            TestComponent inst = Component.Instantiate(comp1) as TestComponent;
            Assert.That(inst.Tag, Is.EqualTo(comp1.Tag));
        }
Ejemplo n.º 18
0
        public void WeWillCloneComponentsOnChildObjects()
        {
            GameObject obj = new GameObject();
            Transform trans = obj.transform;
            GameObject child = new GameObject() { name = "MyObject", active = true, layer = 10, tag = "Mytag" };
            Transform trans1 = child.transform;
            trans1.parent = trans;
            TestComponent comp = new TestComponent();
            child.AddComponent(comp);

            GameObject clone = GameObject.Instantiate(obj) as GameObject;

            foreach (GameObject cloneChild in clone.transform)
            {
                TestComponent childComp = cloneChild.GetComponent<TestComponent>();
                Assert.That(childComp, Is.Not.Null);
                Assert.That(childComp, Is.Not.SameAs(comp));
                Assert.That(childComp.gameObject, Is.SameAs(cloneChild));
            }
        }
Ejemplo n.º 19
0
        public void IfTheComponentHasNoGameObjectTransformWillBeNull()
        {
            TestComponent comp = new TestComponent();

            Assert.That(comp.transform, Is.Null);
        }
Ejemplo n.º 20
0
        public void Setup()
        {
            Assert.Inconclusive("This will only work when loading with the intermediate serializer, so we need to do a test like that.");
            h = new TestHierarchy();
            rootComponent = new TestComponent();
            h.root.AddComponent(rootComponent);

            childComponent = new TestComponent();
            h.child.AddComponent(childComponent);

            childOfChildComponent = new TestComponent();
            h.childOfChild.AddComponent(childOfChildComponent);
        }
Ejemplo n.º 21
0
        public void IfAComponentIsCreatedDuringAwakeItWillStillBeAwoken()
        {
            bool awakeCalled = false;
            TestComponent newComponent = null;
            rootComponent.onAwake = () => { newComponent = new TestComponent() { onAwake = () => { awakeCalled = true; } }; };

            Assert.That(awakeCalled, Is.False);
            Assert.That(newComponent, Is.Not.Null);
            Assert.That(awakeCalled, Is.False);
            Assert.That(awakeCalled, Is.True);
        }
Ejemplo n.º 22
0
 public void ItWillBeTheSameAsTheTypeIfItIsNotAddedToAGameObject()
 {
     Component comp = new TestComponent();
     Assert.That(comp.name, Is.EqualTo(comp.GetType().Name));
 }
Ejemplo n.º 23
0
        public void IfTheComponentHasNoGameObjectRigidbodyWillBeNull()
        {
            TestComponent comp = new TestComponent();

            Assert.That(comp.rigidbody, Is.Null);
        }
Ejemplo n.º 24
0
        public void WeCanFindTheFirstComponentOfAGivenType()
        {
            TestComponent comp = new TestComponent();
            child.AddComponent(comp);

            UnityObject cmp = UnityObject.FindObjectOfType(typeof(TestComponent));
            Assert.That(cmp, Is.Not.Null);
        }
Ejemplo n.º 25
0
 public void SetUp()
 {
     go   = new GameObject();
     comp = go.AddComponent(new TestComponent());
 }
Ejemplo n.º 26
0
        public void WeWillCloneAParentHierarchyByComponent()
        {
            TestHierarchy h = new TestHierarchy();

            TestComponent comp = new TestComponent();
            h.childOfChild.AddComponent(comp);

            TestComponent clone = GameObject.Instantiate(comp) as TestComponent;
            Assert.That(clone, Is.Not.Null);
            Assert.That(clone.transform.parent, Is.Not.Null);
            Assert.That(clone.transform.parent.transform.parent, Is.Not.Null);
            Assert.That(clone.transform.parent.transform.parent.transform.parent, Is.Null);
        }
 public void IfTheComponentHasNoGameObjectColliderWillBeNull()
 {
     TestComponent comp = new TestComponent();
     Assert.That(comp.collider, Is.Null);
 }
 public void IfTheComponentHasNoGameObjectRigidbodyWillBeNull()
 {
     TestComponent comp = new TestComponent();
     Assert.That(comp.rigidbody, Is.Null);
 }
 public void IfTheComponentHasNoGameObjectTransformWillBeNull()
 {
     TestComponent comp = new TestComponent();
     Assert.That(comp.transform, Is.Null);
 }
Ejemplo n.º 30
0
        public void ItWillBeTheSameAsTheTypeIfItIsNotAddedToAGameObject()
        {
            Component comp = new TestComponent();

            Assert.That(comp.name, Is.EqualTo(comp.GetType().Name));
        }
Ejemplo n.º 31
0
        public void IfTheComponentHasNoGameObjectColliderWillBeNull()
        {
            TestComponent comp = new TestComponent();

            Assert.That(comp.collider, Is.Null);
        }
Ejemplo n.º 32
0
        public void WeCanInstantiateAComponent()
        {
            GameObject obj = new GameObject();
            TestComponent comp = new TestComponent();
            obj.AddComponent(comp);

            TestComponent comp1 = Component.Instantiate(comp) as TestComponent;
            Assert.That(comp1, Is.Not.Null);
            Assert.That(comp1, Is.Not.SameAs(comp));
            Assert.That(comp1.GetInstanceID(), Is.Not.EqualTo(comp.GetInstanceID()));
            Assert.That(comp1.gameObject, Is.Not.SameAs(obj));
            Assert.That(comp1.gameObject.GetInstanceID(), Is.Not.EqualTo(comp.gameObject.GetInstanceID()));
        }
Ejemplo n.º 33
0
        public void WeCanGetAllComponentsOnTheCurrentScene()
        {
            TestComponent comp = new TestComponent();
            TestComponent comp1 = new TestComponent();
            TestComponent comp2 = new TestComponent();
            root.AddComponent(comp);
            child.AddComponent(comp1);
            childOfChild.AddComponent(comp2);

            UnityObject[] components = UnityObject.FindObjectsOfType(typeof(TestComponent));
            Assert.That(components, Is.Not.Null);
            Assert.That(components.Length, Is.EqualTo(3));
            Assert.That(components, Contains.Item(comp));
            Assert.That(components, Contains.Item(comp1));
            Assert.That(components, Contains.Item(comp2));
        }