Esempio n. 1
0
    public void SaveBuildInCategories()
    {
        if (_placedBlocks.Count == 0)
        {
            Debug.Log("No blocks have been placed down. No saving has occured.");
            return;
        }

        //Setup the dictionary for every possible type
        Dictionary <CarComponents.Type, List <BlockSave> > saveme = new Dictionary <CarComponents.Type, List <BlockSave> >();

        foreach (CarComponents.Type type in (CarComponents.Type[])System.Enum.GetValues(typeof(CarComponents.Type)))
        {
            saveme.Add(type, new List <BlockSave>());
        }

        //foreach block placed, check the type and put it in the correct slot
        foreach (GameObject block in _placedBlocks.Values)
        {
            CarComponent component = block.GetComponent <BlockProperties>().data;
            BlockSave    save      = new BlockSave(component.name, block.transform.position - buildOffset, block.transform.rotation);

            //add to saveme dict
            saveme[component.type].Add(save);
        }

        string json = JsonConvert.SerializeObject(saveme, Formatting.Indented);

        File.WriteAllText(Application.dataPath + @"\PlacedBlocksCatergories" + _player + ".txt", json);
    }
Esempio n. 2
0
    //Public

    public static void Create(BlockSave blocksave)
    {
        Vector3Int position = new Vector3Int(blocksave.x, blocksave.y, blocksave.z);
        Block      block    = Resources.Load <GameObject>("Blocks/" + blocksave.name).GetComponent <Block>();

        block.Use(position);
    }
Esempio n. 3
0
    public void Save()
    {
        BlockSave.SaveData(this);

        Block block = BlockManager.instance.BlockIdentity(transform);

        if (block != null)
        {
            block.Save();
        }
        if (this.tag == "ifBlock")
        {
            ifBar UnderBar = this.GetComponentInChildren <ifBar>();
            UnderBar.Save();
        }
        else if (this.tag == "whileBlock")
        {
            whileBar UnderBar = this.GetComponentInChildren <whileBar>();
            UnderBar.Save();
        }
    }