public void TestScoreDTODeserialisation() { string scoreLocationJSON = @" { ""scoreLocations"": [ { ""location"": { ""x"": -2, ""y"": -9 } }, { ""location"": { ""x"": -2, ""y"": 1 } }, { ""location"": { ""x"": -2, ""y"": 4 } } ] } "; ScoreLocationsDTO scoreLocationsDTO = JsonUtility.FromJson <ScoreLocationsDTO>(scoreLocationJSON); Assert.AreEqual(3, scoreLocationsDTO.scoreLocations.Length); ScoreLocationDTO scoreLocationDTO = scoreLocationsDTO.scoreLocations[0]; Assert.AreEqual(new Location(-2, -9), scoreLocationDTO.location); }
public static GameObject GenerateScore(ScoreLocationDTO scoreDTO, Transform parent) { // TODO: pass type from back-end. Hardcoded to bluedisk for now. string resource = "Prefabs/Scores/score_" + "bluedisk"; GameObject scorePrefab = Resources.Load <GameObject>(resource); GameObject score = Object.Instantiate( scorePrefab, new Vector3(scoreDTO.location.x, 0, scoreDTO.location.y), Quaternion.identity) as GameObject; score.transform.SetParent(parent, false); // TODO: make name dynamic to type passed too. score.name = "score_" + "bluedisk" + "_" + scoreDTO.location.x + "_" + scoreDTO.location.y; return(score); }
public void TestGenerateScoreFromDTO() { ScoreLocationDTO scoreDTO = new ScoreLocationDTO(); Location pickupLocation = new Location(10, 20); scoreDTO.location = pickupLocation; GameObject scoreParent = new GameObject(); GameObject generatedScore = ScoreGenerator.GenerateScore(scoreDTO, scoreParent.transform); Assert.AreEqual(pickupLocation.x, generatedScore.transform.localPosition.x); Assert.AreEqual(0, generatedScore.transform.localPosition.y); Assert.AreEqual(pickupLocation.y, generatedScore.transform.localPosition.z); Assert.AreEqual(scoreParent.transform, generatedScore.transform.parent); Assert.AreEqual("score_bluedisk_10_20", generatedScore.name); Assert.AreEqual(10, generatedScore.transform.localPosition.x); Assert.AreEqual(20, generatedScore.transform.localPosition.z); Assert.AreEqual(0, generatedScore.transform.localPosition.y); Assert.AreEqual("Score", generatedScore.tag); }