void SetPrefixJSON(string name) { ClassJSON classJSON = new ClassJSON() { className = name }; AddToJSON(classJSON); }
public void LoadLevel(string jsonFilePath) { string[] lines = File.ReadAllLines(jsonFilePath); for (int i = 0; i < lines.Length; i++) { ClassJSON classJSON = JsonUtility.FromJson <ClassJSON>(lines[i++]); switch (classJSON.className) { case "ObjectInfo": ObjectInfo info = JsonUtility.FromJson <ObjectInfo>(lines[i]); GameObject clone = Instantiate(SandboxObjectPlacer.instance.FindPrefab(info.prefab), info.position, Quaternion.Euler(info.rotation)); clone.name = info.prefab; clone.transform.localScale = info.scale; clone.AddComponent <ObjectData>().prefab = SandboxObjectPlacer.instance.FindPrefab(info.prefab); clone.GetComponent <ObjectData>().toolName = info.toolName; clone.AddComponent <BulldozerObject>(); if (!string.IsNullOrEmpty(info.isCube)) { SetCube(clone, info.isCube); } else if (info.platformInfo.speed != -1) { info.platformInfo.platformGameObject = clone; SetPlatform(info.platformInfo); } if (!GameManager.instance.sandboxObjects.Contains(clone)) { GameManager.instance.sandboxObjects.Add(clone); } clone.GetComponent <UndoSystem_SandboxObjects>().placedOnStart = true; break; case "Rule": Rule rule = JsonUtility.FromJson <Rule>(lines[i]); SetInitTools(rule.toolName, rule.toolAmount); if (!string.IsNullOrEmpty(rule.neededToWin)) { PointSystem.instance.pointsToWin = int.Parse(rule.neededToWin); } break; } } if (!playingADownloadedLevel) { LevelNameText.text = GetCreatedLevel(levelId).name; } else { LevelNameText.text = GetDownloadedLevel(GameManager.instance.levelEditorLevelPath + "\\LevelInfo.json").name; } GameManager.instance.Save(); }