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 WeCanDoItWithJustItsType() { GameObject go = new GameObject(); Component comp = go.AddComponent(typeof(TestComponent)); Assert.That(comp, Is.Not.Null); Assert.That(comp.gameObject, Is.SameAs(go)); }
public void ItWillHaveTheGameObjectSet() { GameObject go = new GameObject(); Component comp = new TestComponent(); go.AddComponent(comp); Assert.That(comp.gameObject, Is.SameAs(go)); }
public void SetUp() { var gameObject = new GameObject(); _rigidBody = new RigidBody(); gameObject.AddComponent(_rigidBody); gameObject.AddComponent(new Transform()); }
/** ToolbeltManager will call .SendMessage("MsgShowGhost", true/false) * */ void MsgShowGhost(bool show) { if (this._viewpointGhost == null) { GameObject vg = GameObject.CreatePrimitive(PrimitiveType.Sphere); vg.transform.parent = this.gameObject.transform; vg.renderer.material.shader = Shader.Find ("Transparent/Diffuse"); vg.renderer.material.SetColor("", new Color(1.0f, 1.0f, 1.0f, 0.5f)); this._viewpointGhost = vg; } if (this._avieCylinder == null) { GameObject ac = new GameObject("Ghost Cylinder"); ac.AddComponent<MeshRenderer>(); ac.renderer.material.shader = Shader.Find("Transparent/Diffuse"); ac.renderer.material.SetColor( "_Emission", new Color(1.0f, 1.0f, 1.0f, 0.2f) ); icScreenSpaceCyli cyliScript = ac.AddComponent<icScreenSpaceCyli>(); cyliScript.parentToCamera = false; cyliScript.screenSpacePosition.z = 5.0f; cyliScript.screenSpaceScale.x = 1.0f; cyliScript.screenSpaceScale.y = 1.0f; cyliScript.tessellationPerCircle = 60; cyliScript.tessellationPerY = 3; ac.transform.parent = this.gameObject.transform; this._avieCylinder = ac; } this._viewpointGhost.renderer.enabled = show; this._avieCylinder.renderer.enabled = show; }
public Bullet CreateBullet() { GameObject obj = new GameObject("Bullet"); Transform transform = obj.AddComponent<Transform>(); RigidBody body = obj.AddComponent<RigidBody>(); SpriteRenderer sprite = obj.AddComponent<SpriteRenderer>(); Bullet bullet = obj.AddComponent<Bullet>(); Material spriteMaterial = this.spriteMaterial.Res ?? Material.SolidWhite.Res; Vector2 spriteSize = spriteMaterial.MainTexture.IsAvailable ? spriteMaterial.MainTexture.Res.Size : new Vector2(5, 5); float spriteRadius = MathF.Max(spriteSize.X, spriteSize.Y) * 0.25f; body.ClearShapes(); CircleShapeInfo circleShape = new CircleShapeInfo(spriteRadius, Vector2.Zero, 1.0f); circleShape.IsSensor = true; body.AddShape(circleShape); body.CollisionCategory = CollisionCategory.Cat3; body.CollidesWith &= ~CollisionCategory.Cat3; sprite.SharedMaterial = this.spriteMaterial; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, spriteSize.X * 0.5f, spriteSize.Y * 0.5f); bullet.InitFrom(this); return bullet; }
public void BuildGameObject(Vector2 position) { GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "BoxPreassurePlate", 1f)); gameObject.Transform.Position = position; gameObject.AddComponent(new BoxPreassurePlate(gameObject, Color.White, name)); gameObject.AddComponent(new Collider(gameObject)); this.gameObject = gameObject; }
public void BuildGameObject(Vector2 position) { GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "MoveableBox", 0.9f)); gameObject.Transform.Position = position; gameObject.AddComponent(new MoveableBox(gameObject)); gameObject.AddComponent(new Collider(gameObject)); this.gameObject = gameObject; }
public void BuildGameObject(Vector2 position) { GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "DoorOne", 1f)); gameObject.Transform.Position = new Vector2(410, 150); gameObject.AddComponent(new Door(gameObject, name)); gameObject.AddComponent(new Collider(gameObject)); this.gameObject = gameObject; }
public void BuildGameObject(Vector2 position, string name) { this.name = name; GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "DoorOne", 0.1f)); gameObject.Transform.Position = position; gameObject.AddComponent(new Door(gameObject, name)); gameObject.AddComponent(new Collider(gameObject)); this.gameObject = gameObject; }
public void BuildGameObject(Vector2 position) { GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "Gave", 1f)); gameObject.Transform.Position = position; gameObject.AddComponent(new Collider(gameObject)); gameObject.AddComponent(new Gift()); this.gameObject = gameObject; }
public void BuildGameObject(Vector2 position, string name) { this.name = name; GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "PreassurePlate", 0.1f)); gameObject.Transform.Position = position; gameObject.AddComponent(new PreassurePlate(gameObject, Color.White, name)); gameObject.AddComponent(new Collider(gameObject)); this.gameObject = gameObject; }
[Test] public void CreateEmptyBody() { // Create a new RigidBody GameObject obj = new GameObject("Object"); obj.AddComponent<Transform>(); RigidBody body = obj.AddComponent<RigidBody>(); // Expect the body to be empty Assert.IsTrue(body.Shapes == null || !body.Shapes.Any()); Assert.IsTrue(body.Joints == null || !body.Joints.Any()); }
public void WeWillFindTheCorrectSubType() { GameObject go = new GameObject(); go.AddComponent(typeof(TestComponent)); go.AddComponent(typeof(MyTestComponent)); UnityObject obj = Application.FindObjectOfType(typeof(MyTestComponent)); Assert.That(obj, Is.Not.Null); Assert.That(obj, Is.TypeOf<MyTestComponent>()); }
public void BuildGameObject(Vector2 position) { GameObject gameObject = new GameObject(); gameObject.AddComponent(new SpriteRenderer(gameObject, "PlayerSheet", 1f)); gameObject.Transform.Position = new Vector2(50, 50); gameObject.AddComponent(new Animator(gameObject)); gameObject.AddComponent(new Player(gameObject)); gameObject.AddComponent(new Collider(gameObject)); this.gameObject = gameObject; }
public void LevelBorderBuild() { for (int i = 0; i < 16; i++) { GameObject gameObject = new GameObject(); int newx = 50 * i; gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f)); gameObject.Transform.Position = new Vector2(-6 + newx, -6); gameObject.AddComponent(new Collider(gameObject)); _levelOneObjects.Add(gameObject); } for (int i = 0; i < 9; i++) { GameObject gameObject = new GameObject(); int newy = 50 * i; gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f)); gameObject.Transform.Position = new Vector2(-6, -6 + newy); gameObject.AddComponent(new Collider(gameObject)); _levelOneObjects.Add(gameObject); } for (int i = 0; i < 9; i++) { GameObject gameObject = new GameObject(); int newy = 50 * i; gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f)); gameObject.Transform.Position = new Vector2(750, -6 + newy); gameObject.AddComponent(new Collider(gameObject)); _levelOneObjects.Add(gameObject); } for (int i = 0; i < 16; i++) { GameObject gameObject = new GameObject(); int newx = 50 * i; gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f)); gameObject.Transform.Position = new Vector2(newx, 444); gameObject.AddComponent(new Collider(gameObject)); _levelOneObjects.Add(gameObject); } }
/* * base class for button * * */ protected static GameObject MakeBase(Material m,Font ft ,string tx, int fs) { GameObject b = new GameObject(); MeshRenderer mr = b.AddComponent<MeshRenderer>(); mr.material = m; TextMesh txm = b.AddComponent<TextMesh>(); txm.font = ft; txm.fontSize = fs*ButtonFactory.fontScale; txm.text = tx; b.AddComponent<BoxCollider2D>(); return b; }
void Start() { this.playersNumber = (int) Mathf.Clamp((float)this.playersNumber, 1F, 4F); for (int i = 0; i < this.playersNumber; i++) { GameObject player = new GameObject("Player_" + (i + 1)); player.SetActive(false); player.transform.localScale = new Vector3(2F, 2F, 1F); InputHandler inputHandler = player.AddComponent<InputHandler>(); inputHandler.playerNumber = i + 1; PlayerSelection selection = player.AddComponent<PlayerSelection>(); selection.character = this.character; player.SetActive(true); } }
public void TheIdMapWillContainAMapOfAllComponents() { Dictionary<int, UnityObject> ids = new Dictionary<int, UnityObject>(); GameObject go = new GameObject(); go.AddComponent(typeof(TestComponent)); go.AddComponent(typeof(TestComponent)); go.SetNewId(ids); Assert.That(ids.Count, Is.EqualTo(4)); foreach (var item in go.GetComponents(typeof(Component))) { Assert.That(ids.ContainsValue(item), Is.True); } }
/* * base class for button * * */ protected static GameObject MakeBase(Material m,Font ft ,string tx, int fs, TextAnchor txmach = TextAnchor.UpperLeft) { GameObject b = new GameObject(); MeshRenderer mr = b.AddComponent<MeshRenderer>(); mr.material = m; TextMesh txm = b.AddComponent<TextMesh>(); txm.font = ft; txm.anchor = txmach; txm.fontSize = fs*ButtonFactory.fontScale; b.transform.localScale = b.transform.localScale / ButtonFactory.fontScale; txm.text = tx; b.name = tx; b.AddComponent<BoxCollider2D>(); return b; }
public void BuildTerrainChunks() { m_terrainChunks = new TerrainChunkObject[WORLD_CHUNK_SIZE, WORLD_CHUNK_SIZE]; m_globalheightMap = new TerrainHeightMap(WORLD_CHUNK_SIZE * TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE); m_chunkHeigtmaps = new TerrainHeightMap[WORLD_CHUNK_SIZE, WORLD_CHUNK_SIZE]; for (int x = 0; x < WORLD_CHUNK_SIZE; x++) { for (int y = 0; y < WORLD_CHUNK_SIZE; y++) { GameObject terrainObject = new GameObject("Terrain - " + x + ", " + y); MeshBuilder.GeneratePerlinMap(x, y, m_globalheightMap, new float[] { 1.25f, 3f, 10f, 25, 0.5f }, //scale new float[] { 1f, 4.15f, 0f, 0, 0f}, //additions new float[] { 28, 5f, 2f, 0.5f, 55f }, //strength new decimal[] { 0.55m, 1m, 0.25m, 0.2m, 55m }); //limits) m_chunkHeigtmaps[x, y] = new TerrainHeightMap(TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE); m_terrainChunks[x, y] = terrainObject.AddComponent<TerrainChunkObject>(); } } for (int x = 0; x < WORLD_CHUNK_SIZE; x++) { for (int y = 0; y < WORLD_CHUNK_SIZE; y++) { m_chunkHeigtmaps[x, y].SetHeightMap(m_globalheightMap.GetPortion(x * TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE, y * TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE, TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE), m_globalheightMap.highestFloat, m_globalheightMap.lowestFloat, m_globalheightMap.totalStrength); m_terrainChunks[x, y].Build(x, y, m_chunkHeigtmaps[x, y]); } } }
public void CanSetComponentExecutionOrder() { var updateOrder = new List<int>(); DualityApp.AppData = new DualityAppData(); Scene.SetComponentExecutionOrder(typeof(ComponentTwo), typeof(ComponentThree), typeof(ComponentOne)); var gameObject = new GameObject(); gameObject.AddComponent(new ComponentOne(updateOrder)); gameObject.AddComponent(new ComponentTwo(updateOrder)); gameObject.AddComponent(new ComponentThree(updateOrder)); Scene.Current.AddObject(gameObject); Scene.Current.Update(); Assert.True(updateOrder.SequenceEqual(new[] { 2, 3, 1 })); }
[Test] public void CopyModifyShapes() { int radiusA = MathF.Rnd.Next(); int radiusB = MathF.Rnd.Next(); // Create two bodies GameObject objA = new GameObject("ObjectA"); GameObject objB = new GameObject("ObjectB", objA); objA.AddComponent<Transform>(); objB.AddComponent<Transform>(); RigidBody bodyA = objA.AddComponent<RigidBody>(); RigidBody bodyB = objB.AddComponent<RigidBody>(); // Add a similar shape to both bodyA.AddShape(new CircleShapeInfo(radiusA, Vector2.Zero, 1.0f)); bodyB.AddShape(new CircleShapeInfo(radiusB, Vector2.Zero, 1.0f)); // Check if each body carries its designated shape Assert.IsTrue(bodyA.Shapes != null && (bodyA.Shapes.First() as CircleShapeInfo).Radius == radiusA); Assert.IsTrue(bodyB.Shapes != null && (bodyB.Shapes.First() as CircleShapeInfo).Radius == radiusB); // Copy the first over to the second bodyA.CopyTo(bodyB); // Are they both equal now? Assert.AreNotSame(bodyA.Shapes, bodyB.Shapes); Assert.AreNotSame(bodyA.Shapes.First(), bodyB.Shapes.First()); Assert.IsTrue(bodyA.Shapes != null && (bodyA.Shapes.First() as CircleShapeInfo).Radius == radiusA); Assert.IsTrue(bodyB.Shapes != null && (bodyB.Shapes.First() as CircleShapeInfo).Radius == radiusA); }
public void ArraysOfReferencesWillCreateANewArrayAndReplaceReference() { GameObject obj = new GameObject(); ReferencingComponent cmp = new ReferencingComponent(); obj.AddComponent(cmp); cmp.componentArray = new Component[] { obj.AddComponent<TestComponent>(), obj.AddComponent<TestComponent>(), obj.AddComponent<TestComponent>() }; GameObject clone = (GameObject)GameObject.Instantiate(obj); ReferencingComponent clonedCmp = clone.GetComponent<ReferencingComponent>(); Assert.That(clonedCmp.componentArray, Is.Not.SameAs(cmp.componentArray)); for (int i = 0; i < clonedCmp.componentArray.Length; i++) { Assert.That(clonedCmp.componentArray[i], Is.Not.Null); Assert.That(clonedCmp.componentArray[i], Is.Not.SameAs(cmp.componentArray[i])); } }
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 CanRegisterMultipleComponentsOnTheSameGameObjectForTargettedDelivery() { var gameObject = new GameObject(); var testComponent = new TestComponent(); var testComponent2 = new TestComponent2(); gameObject.AddComponent(testComponent); gameObject.AddComponent(testComponent2); Scene.Current.AddObject(gameObject); gameObject.SendMessage(new TestGameMessage(), gameObject); Assert.True(testComponent.MessageHandled); Assert.True(testComponent2.MessageHandled); }
private static Component RegisterInactiveObject() { var gameObject = new GameObject {Active = false}; var component = gameObject.AddComponent<TestComponent>(); Scene.Current.RegisterObj(gameObject); return component; }
public void WeCanRemoveComponentsByResettingTheApplication() { GameObject go = new GameObject(); TestComponent comp = go.AddComponent<TestComponent>(); Application.Reset(); Assert.That(Application.Find(comp.GetInstanceID()), Is.Null); }
public void WeCanFindTheNewComponentById() { GameObject go = new GameObject(); TestComponent comp = go.AddComponent<TestComponent>(); Assert.That(Application.Find(comp.GetInstanceID()), Is.Not.Null); Assert.That(Application.Find(comp.GetInstanceID()), Is.SameAs(comp)); }
private static GameObject CreateUIObject(string name, GameObject parent) { GameObject child = new GameObject(name); child.AddComponent<RectTransform>(); DefaultControls.SetParentAndAlign(child, parent); return child; }