本文整理汇总了C#中BinaryFormatter.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFormatter.Deserialize方法的具体用法?C# BinaryFormatter.Deserialize怎么用?C# BinaryFormatter.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryFormatter
的用法示例。
在下文中一共展示了BinaryFormatter.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public static BHash Load(byte[] data)
{
var bhash = new BHash();
var mem = new MemoryStream(data);
var cvt = new BinaryFormatter();
bhash.FileSize = (long)cvt.Deserialize(mem);
bhash.Blocks = (List<byte[]>)cvt.Deserialize(mem);
return bhash;
}
示例2: FromByteArray
// public byte[] byteImg;
public static MessageData FromByteArray(byte[] input)
{
// Create a memory stream, and serialize.
MemoryStream stream = new MemoryStream(input);
// Create a binary formatter.
BinaryFormatter formatter = new BinaryFormatter();
MessageData data = new MessageData();
data.Chaine = (string)formatter.Deserialize(stream);
data.reel = (float)formatter.Deserialize(stream);
data.entier = (int)formatter.Deserialize(stream);
return data;
}
示例3: FromByteArray
public static MessageData FromByteArray(byte[] input)
{
MemoryStream stream = new MemoryStream(input);
BinaryFormatter formatter = new BinaryFormatter();
MessageData data = new MessageData();
data.type = (int)formatter.Deserialize(stream);
data.stringData = (string)formatter.Deserialize(stream);
if (data.stringData == "")
{
data.type = 999;
data.stringData = "No Command Included";
}
return data;
}
示例4: loadProgress
// Loads the progress the player made so far
public static void loadProgress()
{
if (File.Exists(Application.persistentDataPath + "/progress.sg"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/progress.sg", FileMode.Open);
int[] scores = (int[])bf.Deserialize(file);
score = scores[0];
darkEnergy = scores[1];
lightEnergy = scores[2];
if (scores[3] == -1)
{
isDark = true;
isLight = false;
}
else if (scores[3] == 1)
{
isDark = false;
isLight = true;
}
else
{
isDark = false;
isLight = false;
}
file.Close();
}
}
示例5: LoadButtonAssignment
// Button Assignment
public void LoadButtonAssignment()
{
// Check if the file exists before proceeding
if (File.Exists(Application.persistentDataPath + "/buttonAssignment.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/buttonAssignment.dat", FileMode.Open);
// Deserialize creates a generic object that we must cast as ButtonData
// This allows us to pull the data out of the file
ButtonData data = (ButtonData)bf.Deserialize(file);
// Close the file
file.Close();
left = data.GetButtonLeft();
right = data.GetButtonRight();
up = data.GetButtonUp();
down = data.GetButtonDown();
jump = data.GetButtonJump();
fire1 = data.GetButtonFire1();
fire2 = data.GetButtonFire2();
fire3 = data.GetButtonFire3();
quickFire = data.GetButtonQuickFire();
submit = data.GetButtonSubmit();
cancel = data.GetButtonCancel();
}
}
示例6: Load
public static bool Load(Chunk chunk)
{
string saveFile = SaveLocation(chunk.world.worldName);
saveFile += FileName(chunk.pos);
if (!File.Exists(saveFile))
return false;
try
{
IFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(saveFile, FileMode.Open);
Save save = (Save)formatter.Deserialize(stream);
//Once the blocks in the save are added they're marked as unmodified so
//as not to trigger a new save on unload unless new blocks are added.
for (int i =0; i< save.blocks.Length; i++)
{
Block placeBlock = save.blocks[i];
placeBlock.modified = false;
chunk.SetBlock(save.positions[i], placeBlock, false);
}
stream.Close();
}
catch (Exception ex)
{
Debug.LogError(ex);
}
return true;
}
示例7: Load
// Takes the data that is in the save file and gives it to GameControler
private void Load (){
// Only loads if there is a file to load from, and this is in the level menu scene
if (SceneManager.GetActiveScene().buildIndex == LEVEL_SELECT_SCENE_INDEX){
using(FileStream file = File.Open(Application.persistentDataPath + levelStateDataFileEndAddress,FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
LevelStateData data = (LevelStateData) bf.Deserialize(file);
LevelInfoHolder[] levelInfo;
if (data.LevelStatusArray.Length <= 0){ // If there isnt stored information on the level status array in the file, make a new default array
levelInfo = GameControler.GetDefaultLevelCompleteArray();
}
else {
// There is information on the file, so we want to pass it on to GameControler
levelInfo = data.LevelStatusArray;
}
// The save file is currently open so we can't and don't want to save
GameControler.SetLevelCompleteArrayWithoutSaving(levelInfo);
file.Close();
Debug.Log("Loaded");
}
}
}
示例8: LoadFile
/// <summary>
/// Loads last player position on the last current level
/// </summary>
public static PlayerData LoadFile()
{
PlayerData data = null;
if (File.Exists(Application.persistentDataPath + fileName))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + fileName, FileMode.Open);
try
{
data = (PlayerData) bf.Deserialize(file);
Debug.Log("Loaded");
}
catch (SerializationException e)
{
Debug.Log("Failed to serialize. Reason: " + e.Message);
throw;
}
finally
{
file.Close();
}
}
else
{
Debug.Log("No saved progress! File does not exist :(");
}
return data;
}
示例9: LoadLevel
public void LoadLevel(int levelNumber)
{
Debug.Log("loading");
var formatter = new BinaryFormatter();
FileStream stream = File.OpenRead(datapath + levelNumber + ".lvl");
var ballList = (BallInfo[]) formatter.Deserialize(stream);
stream.Close();
var bf = FindObjectOfType<BallFactory>();
var bfIterator = 1;
foreach (var ball in ballList)
{
if (bf != null)
{
if (ball.isBogus)
{
bf.Instantiate(ball, -1);
}
else
{
bf.Instantiate(ball, bfIterator);
bfIterator++;
}
}
}
}
示例10: Load
public void Load(string path)
{
if(File.Exists(Application.persistentDataPath + path))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + path, FileMode.Open);
//deserializing the file so we can get the values back
SaveData saveData = binaryFormatter.Deserialize(file) as SaveData;
//get all components
GameObject gameController = GameObject.FindGameObjectWithTag(Tags.GAMECONTROLLER);
_gameController = gameController.GetComponent<GameController>();
//setting all values
_gameController.level = saveData.level;
_gameController.lives = saveData.lives;
_gameController.checkpointPosition = saveData.checkpointPosition;
_gameController.score = saveData.score;
_gameController.goldCoins = saveData.goldCoins;
//closing the file after every value is set
file.Close();
if (OnGameLoaded != null)
OnGameLoaded();
}
else
{
if (OnNewGame != null)
OnNewGame();
//new game
}
SavePaths.currentPath = path;
}
示例11: LoadData
public static bool LoadData()
{
string path = Path.Combine(Application.persistentDataPath, filename);
if (File.Exists(path) == false)
{
Debug.Log("No Save Exists");
return false;
}
try
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(path, FileMode.Open);
Data data = bf.Deserialize(file) as Data;
Coins.total = data.coins;
CellHandler.turns = data.turns;
GameObject[,] cells = sCell.getCellArray(data.cells);
CellHandler.singleton.setParentForCells(cells);
CellValue.SwordTotal = data.SwordPower;
CellValue.MonsterTotal = data.MonsterPower;
file.Close();
Debug.Log("Game Loaded");
return true;
}
catch (Exception e)
{
Debug.Log(e.Message);
return false;
}
}
示例12: Load
//Basically the opposite of the save function. Deserialize the data and load the data from the file into the variables.
//The method is called every time you launch the game, however, unless the file exists, it will do nothing
public void Load()
{
print ("Loaded: " + Application.persistentDataPath + "/playerInfo.dat");
if (File.Exists (Application.persistentDataPath + "/playerInfo.dat")) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize (file);
file.Close ();
//All My Variables
health = data.health;
bg.Money = data.money;
bg.zombiesPerWave = data.zombiesLeft;
bg.waveNumber = data.waveNum;
bg.nextWaveButton.gameObject.SetActive (data.isShopping);
bg.house.SetActive (!data.isShopping);
transform.position = new Vector3 (data.posX, data.posY, data.posZ);
transform.Rotate (0, data.rotationY, 0);
GameObject.Find ("WaveText").GetComponent<Text> ().text = data.waveString;
rotateSpeed = data.rotateSpeed;
//Upgrades
bootsLevel = data.bootsLevel;
jumpLevel = data.jumpLevel;
//End Variables
}
}
示例13: Load
public static MinerSaveGame Load()
{
if (File.Exists(timeScaleFileName))
{
string text = File.ReadAllText(timeScaleFileName);
float timeScale = float.Parse(text.Trim());
Time.timeScale = timeScale;
}
if (File.Exists(saveGameFileName))
{
Debug.Log("Loading SaveGame...");
BinaryFormatter formatter = new BinaryFormatter();
FileStream fs = File.Open(saveGameFileName, FileMode.Open);
MinerSaveGame saveGame = (MinerSaveGame)formatter.Deserialize(fs);
fs.Close();
return saveGame;
}
else
{
Debug.Log("Creating new SaveGame...");
MinerSaveGame newGame = new MinerSaveGame();
newGame.minerData[0] = new MinerData(0);
newGame.minerData[1] = new MinerData(1);
newGame.minerData[2] = new MinerData(2);
return newGame;
}
}
示例14: FileButtonListener
public void FileButtonListener(string mapName, string directory, Button button)
{
//color part
if (activeButton == null) {
print ("Active button null");
activeButton = button;
}
else
{
activeButton.GetComponentInChildren<Text>().color = Color.black;
activeButton = button;
}
button.GetComponentInChildren<Text>().color = Color.green;
//color part
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open (directory+"/"+mapName, FileMode.Open);
mapFromSelectedFile = (GameManager.Map)bf.Deserialize (file);
file.Close ();
if (preview != null)Destroy (preview);
GameManager.instance.GetComponent<MapDrawer>().DrawTerrainPreview (mapFromSelectedFile, previewPositionHolder);
preview = GameManager.instance.GetComponent<MapDrawer>().previewHoldingGO;
GameManager.instance.currentMap = mapFromSelectedFile;
}
示例15: Load
public static object Load(string filePath)
{
Debug.Log ("Load:"+filePath);
if (!File.Exists(filePath)){
Debug.Log ("Can't find file:"+filePath);
return null;
}
FileStream fs = new FileStream(filePath, FileMode.Open);
object obj = null;
try
{
BinaryFormatter formatter = new BinaryFormatter();
obj = (object)formatter.Deserialize(fs);
}
catch (SerializationException e)
{
Debug.Log("Failed to deserialize. Reason: " + e.Message);
throw;
}
finally
{
fs.Close();
}
return obj;
}