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)); }
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)); }
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)); }
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)); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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()); }
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()); }
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)); }
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)); } }
public void IfTheComponentHasNoGameObjectTransformWillBeNull() { TestComponent comp = new TestComponent(); Assert.That(comp.transform, Is.Null); }
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); }
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); }
public void ItWillBeTheSameAsTheTypeIfItIsNotAddedToAGameObject() { Component comp = new TestComponent(); Assert.That(comp.name, Is.EqualTo(comp.GetType().Name)); }
public void IfTheComponentHasNoGameObjectRigidbodyWillBeNull() { TestComponent comp = new TestComponent(); Assert.That(comp.rigidbody, Is.Null); }
public void WeCanFindTheFirstComponentOfAGivenType() { TestComponent comp = new TestComponent(); child.AddComponent(comp); UnityObject cmp = UnityObject.FindObjectOfType(typeof(TestComponent)); Assert.That(cmp, Is.Not.Null); }
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 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())); }
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)); }