Пример #1
0
    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());
    }
Пример #2
0
 private void Awake()
 {
     if (_instance != null)
     {
         return;
     }
     _instance = this;
 }
Пример #3
0
    public static string SaveToFile(CraftBlueprint bp)
    {
        string dir      = "crafts";
        string fileName = bp.craftName + ".bp";

        SaveLoadJSON.SaveObjToFile(bp, dir, fileName);
        return(SaveLoadJSON.GetFullPath(dir + "/" + fileName));
    }
Пример #4
0
    /// <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);
    }
Пример #5
0
    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();
                }
            }
        }
    }
Пример #6
0
    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));
    }