SaveSystem.LoadData C# (CSharp) Method

LoadData() public static method

public static LoadData ( ) : UserData
return UserData
        public static UserData LoadData()
        {
            if (File.Exists(path))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                FileStream stream = new FileStream(path, FileMode.Open);
                UserData data = formatter.Deserialize(stream) as UserData;
                stream.Close();
                return data;
            }
            else
            {
                Debug.LogError("Save file not found in " + path);
                return null;
            }
        }

Usage Example

Ejemplo n.º 1
0
    public void LoadGame()
    {
        var jsonFormatData = saveSystem.LoadData();

        if (String.IsNullOrEmpty(jsonFormatData))
        {
            return;
        }
        SaveDataSerialization saveData = JsonUtility.FromJson <SaveDataSerialization>(jsonFormatData);

        structureManager.ClearMap();
        foreach (var structureData in saveData.structuresData)
        {
            Vector3Int position = Vector3Int.RoundToInt(structureData.position.GetValue());
            if (structureData.buildingType == CellType.Road)
            {
                roadManager.PlaceRoad(position);
                roadManager.FinishPlacingRoad();
            }
            else
            {
                structureManager.PlaceLoadedStructure(position, structureData.buildingPrefabindex, structureData.buildingType);
            }
        }
    }
All Usage Examples Of SaveSystem::LoadData