public void TestInteractableDTODeserialisation() { string interactableJSON = @" { ""interactables"": [ { ""type"": ""Invulnerability"", ""location"": { ""x"": 1, ""y"": 3 } }, { ""type"": ""health"", ""location"": { ""x"": -2, ""y"": 9 } } ] }"; InteractablesDTO interactablesDTO = JsonUtility.FromJson <InteractablesDTO>(interactableJSON); Assert.AreEqual(2, interactablesDTO.interactables.Length); InteractableDTO interactableDTO = interactablesDTO.interactables[0]; Assert.AreEqual(new Location(1, 3), interactableDTO.location); Assert.AreEqual(InteractableType.Invulnerability, interactableDTO.InteractableType); }
public static GameObject GenerateInteractable(InteractableDTO interactableDTO) { string resource = "Prefabs/Interactables/interactable_" + interactableDTO.type; GameObject interactablePrefab = Resources.Load <GameObject>(resource); GameObject interactable = Object.Instantiate( interactablePrefab, new Vector3(interactableDTO.location.x, 0, interactableDTO.location.y), Quaternion.identity) as GameObject; interactable.transform.SetParent(GameObject.Find("Interactables").transform, false); interactable.name = "interactable_" + interactableDTO.type + "_" + interactableDTO.location.x + "_" + interactableDTO.location.y; return(interactable); }
public void TestInteractableGeneratorByDTO() { InteractableDTO interactableDTO = new InteractableDTO(); Location interactableLocation = new Location(10, 20); interactableDTO.location = interactableLocation; interactableDTO.type = "health"; GameObject generatedInteractable = InteractableGenerator.GenerateInteractable(interactableDTO); Assert.AreEqual(interactableLocation.x, generatedInteractable.transform.localPosition.x); Assert.AreEqual(0, generatedInteractable.transform.localPosition.y); Assert.AreEqual(interactableLocation.y, generatedInteractable.transform.localPosition.z); Assert.AreEqual(generatedInteractable.transform.parent.name, "Interactables"); Assert.AreEqual(generatedInteractable.name, "interactable_health_10_20"); Assert.AreEqual(generatedInteractable.transform.localPosition.x, 10); Assert.AreEqual(generatedInteractable.transform.localPosition.z, 20); Assert.AreEqual(generatedInteractable.transform.localPosition.y, 0); Assert.AreEqual(generatedInteractable.tag, "Interactable"); }