コード例 #1
0
        public void TestPickupDTODeserialisation()
        {
            string pickupJSON = @" {
                ""pickups"": [
                    {
                        ""type"": ""Invulnerability"",
                        ""location"": {
                            ""x"": 1,
                            ""y"": 3
                        } 
                    },
                    {
                        ""type"": ""health"",
                        ""location"": {
                            ""x"": -2,
                            ""y"": 9
                        } 
                    }
                ]
            }";

            PickupsDTO pickupsDTO = JsonUtility.FromJson <PickupsDTO>(pickupJSON);

            Assert.AreEqual(2, pickupsDTO.pickups.Length);
            PickupDTO pickupDTO = pickupsDTO.pickups[0];

            Assert.AreEqual(new Location(1, 3), pickupDTO.location);
            Assert.AreEqual(PickupType.Invulnerability, pickupDTO.PickupType);
        }
コード例 #2
0
    public static GameObject GeneratePickup(PickupDTO pickupDTO)
    {
        string     resource     = "Prefabs/Pickups/pickup_" + pickupDTO.type;
        GameObject pickupPrefab = Resources.Load <GameObject>(resource);

        GameObject pickup = Object.Instantiate(
            pickupPrefab,
            new Vector3(pickupDTO.location.x, 0, pickupDTO.location.y),
            Quaternion.identity) as GameObject;

        pickup.transform.SetParent(GameObject.Find("Pickups").transform, false);

        pickup.name = "pickup_" + pickupDTO.type + "_" + pickupDTO.location.x + "_" + pickupDTO.location.y;

        return(pickup);
    }
コード例 #3
0
        public void TestPickupGeneratorByDTO()
        {
            PickupDTO pickupDTO      = new PickupDTO();
            Location  pickupLocation = new Location(10, 20);

            pickupDTO.location = pickupLocation;
            pickupDTO.type     = "health";

            GameObject generatedPickup = PickupGenerator.GeneratePickup(pickupDTO);

            Assert.AreEqual(pickupLocation.x, generatedPickup.transform.localPosition.x);
            Assert.AreEqual(0, generatedPickup.transform.localPosition.y);
            Assert.AreEqual(pickupLocation.y, generatedPickup.transform.localPosition.z);

            Assert.AreEqual(generatedPickup.transform.parent.name, "Pickups");
            Assert.AreEqual(generatedPickup.name, "pickup_health_10_20");

            Assert.AreEqual(generatedPickup.transform.localPosition.x, 10);
            Assert.AreEqual(generatedPickup.transform.localPosition.z, 20);
            Assert.AreEqual(generatedPickup.transform.localPosition.y, 0);

            Assert.AreEqual(generatedPickup.tag, "Pickup");
        }