public void UpdateButtons() { List <GameObject> childrenToDestroy = new List <GameObject>(); foreach (Transform t in ButtonParent) { childrenToDestroy.Add(t.gameObject); } while (childrenToDestroy.Count > 0) { Destroy(childrenToDestroy[0]); childrenToDestroy.RemoveAt(0); } string[] savedCrafts = SaveLoadJSON.SearchForFiles("crafts", "*.bp"); foreach (string s in savedCrafts) { GameObject button = Instantiate(ButtonPrefab, ButtonParent); button.name = s; button.GetComponentInChildren <Text>().text = s; } CreateNewButton = Instantiate(CreateNewButtonPrefab, ButtonParent).transform; //Button for creating a new craft Button CreateNewButtonComp = CreateNewButton.GetComponentInChildren <Button>(); CreateNewButtonComp.onClick.AddListener(() => CraftEditor.instance.CreateNewCraft()); CreateNewButtonComp.onClick.AddListener(() => CloseMenu()); }
private void Awake() { if (_instance != null) { return; } _instance = this; }
public static string SaveToFile(CraftBlueprint bp) { string dir = "crafts"; string fileName = bp.craftName + ".bp"; SaveLoadJSON.SaveObjToFile(bp, dir, fileName); return(SaveLoadJSON.GetFullPath(dir + "/" + fileName)); }
/// <param name="pathIsRelative">is the path relative to Application.persistentDataPath/saved/</param> public static CraftBlueprint LoadFromFile(string path, bool pathIsRelative) { CraftBlueprint bp = SaveLoadJSON.LoadObjFromFile <CraftBlueprint>(path, pathIsRelative); if (bp != null) { Debug.Log("Loaded Blueprint of '" + bp.craftName + "' from file at " + path); } return(bp); }
void LoadCube() { //load class ClassToSave load = SaveLoadJSON.Load(worldConfig.name); if (load != null) { //foreach cell for (int i = 0; i < load.coordinates.Count; i++) { //if was destroyed, load a destroyed cell if (load.isAlive[i] == false) { Cells[load.coordinates[i]].LoadDestroyedCell(); } } } }
public void SaveWorld() { //only if can save world if (canSaveWorld == false) { return; } //create a list with every cell List <Cell> cellsToSave = new List <Cell>(); foreach (Cell cell in world.Cells.Values) { cellsToSave.Add(cell); } //save SaveLoadJSON.Save(world.worldConfig.name, new ClassToSave(cellsToSave)); }