当前位置: 首页>>代码示例>>C#>>正文


C# BinaryFormatter类代码示例

本文整理汇总了C#中BinaryFormatter的典型用法代码示例。如果您正苦于以下问题:C# BinaryFormatter类的具体用法?C# BinaryFormatter怎么用?C# BinaryFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BinaryFormatter类属于命名空间,在下文中一共展示了BinaryFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

    public GameObject Load(int codigo1, int codigo2)
    {
        saveAtual = GameObject.FindObjectOfType<SaveAtual>();
        if (File.Exists(Application.persistentDataPath+"/" + saveAtual.getSaveAtualId() + "" + codigo1 + "" +codigo2+ "MapaData.dat"))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file = File.Open(Application.persistentDataPath + "/" + saveAtual.getSaveAtualId() + "" + codigo1 + "" + codigo2 + "MapaData.dat",FileMode.Open);

            MapaData mapaData = (MapaData)bf.Deserialize(file);
            file.Close();
            this.largura.position = mapaData.largura.V3;
            this.altura.position = mapaData.altura.V3;
            this.comprado = mapaData.comprado;
            celulasLosango = new ArrayList();
            foreach (CelulaData celulas in mapaData.celulasLosango)
            {
                GameObject celula  = GameObject.Instantiate(LosangoBase) as GameObject;
                celula.transform.position = celulas.posicaoCelula.V3;
                celula.GetComponent<Celula>().recurso.setRecurso(celulas.Recurso, celulas.recursoLv);
                celula.GetComponent<Celula>().recurso.setTempoDecorrido(celulas.tempoDecorrido);
                celula.GetComponent<Celula>().recurso.compradoPeloJogador = celulas.compradoPeloJogador;
                celulasLosango.Add(celula);
                celula.transform.parent = this.gameObject.transform;
            }
            return this.gameObject;
        }
        return null;
    }
开发者ID:IuryMaiiaa,项目名称:Jogo-Empreendedorismo,代码行数:28,代码来源:Mapa.cs

示例2: Save

    public void Save(int score, int cubesDestroyed, int purpleCubes, int blueCubes, int redCubes, int yellowCubes, int greenCubes)
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
        PlayerData data = new PlayerData();

        if (score > data.highestScore)
        {
            data.highestScore = score;
            data.isHighScore = true;
        }
        else
            data.isHighScore = false;

        data.totalScore += score;
        data.cubesDestroyed += cubesDestroyed;
        data.lastScore = score;
        data.purpleCubes = purpleCubes;
        data.blueCubes = blueCubes;
        data.redCubes = redCubes;
        data.yellowCubes = yellowCubes;
        data.greenCubes = greenCubes;


        bf.Serialize(file, data);
        file.Close();
    }
开发者ID:nickmorell,项目名称:Cube,代码行数:27,代码来源:ApplicationManager.cs

示例3: 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");			
			}
		}
	}
开发者ID:james-sullivan,项目名称:StickeyBallGame,代码行数:29,代码来源:LevelSelectSaveLoad.cs

示例4: 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++;
                }
            }
        }
    }
开发者ID:jarena3,项目名称:Ool,代码行数:27,代码来源:LevelFactory.cs

示例5: LoadUserFriendsFromLocalMemory

    public User LoadUserFriendsFromLocalMemory()
    {
        BinaryFormatter bf = null;
        FileStream file = null;
        User user = new User();
        try{
            FilePath = Application.persistentDataPath + FRIENDS_LOCAL_FILE_NAME;
            Debug.Log("loadUserFromLocalMemory():FilePath " + FilePath);
            if(File.Exists(FilePath)){
                Debug.Log("Yes [email protected] " + FilePath);
                bf = new BinaryFormatter();
                file = File.Open(FilePath,FileMode.Open);
                user = (User)bf.Deserialize(file);
            }
        }

        catch (FileNotFoundException  ex)
        {
            Debug.Log("FileNotFoundException:ex " + ex.ToString());
        }
        catch (IOException ex)
        {
            Debug.Log("IOException:ex " + ex.ToString());
        }
        catch (Exception ex){
            Debug.Log("Exception:ex " + ex.ToString());
        }
        finally
        {
            if (file != null)
                file.Close();
        }
        return user;
    }
开发者ID:jmoraltu,项目名称:KatoizApp,代码行数:34,代码来源:UserDAO.cs

示例6: SaveToFile

 public static void SaveToFile(Level data, string fileName)
 {
     IFormatter formatter = new BinaryFormatter();
     Stream stream = new FileStream(string.Format("{0}.level", fileName), FileMode.Create, FileAccess.Write, FileShare.Write);
     formatter.Serialize(stream, data);
     stream.Close();
 }
开发者ID:alexkirwan29,项目名称:Cubes-Of-Wrath,代码行数:7,代码来源:LevelIO.cs

示例7: save

	/*
	 * Tries to write to a save file for the current player.
	 * In the future, this may need to consider a player
	 * name so we can have multiple save files.
	 */
	public void save() {
		//Debug.Log("Saving file to " + pathname);

		BinaryFormatter binForm = new BinaryFormatter ();

		FileStream saveFile;
		if (File.Exists (pathname)) {
			saveFile = File.Open (pathname, FileMode.Open);
		} else saveFile = File.Create (pathname);

		MetaPhoto saveData = new MetaPhoto ();
		saveData.balan = balanceValue;
		saveData.spaci = spacingValue;
		saveData.inter = interestingnessValue;
        saveData.containsFox = containsFox;
        saveData.containsOwl = containsOwl;
        saveData.containsDeer = containsDeer;
        saveData.containsPosingAnimal = containsPosingAnimal;
        saveData.takenWithTelephoto = takenWithTelephoto;
        saveData.takenWithWide = takenWithWide;
		saveData.takenWithFilter = takenWithFilter;
		saveData.comments = comments;

		binForm.Serialize (saveFile, saveData);
		saveFile.Close ();
	}
开发者ID:SamReha,项目名称:SnapshotGame,代码行数:31,代码来源:Photo.cs

示例8: serialize

    public void serialize()
    {
        height = GetComponent<Background>().height;
        width = GetComponent<Background>().width;
        start = GetComponent<Background>().start;
        end = GetComponent<Background>().end;

        dangerMap = GetComponent<DangerMap>().getDangerMap();
        var = GetComponent<DangerMap>().var;

        enemies = GetComponent<Enemies>().getEnemy();

        trace = GetComponent<Player>().getTrace();
        filteredTrace_a = GetComponent<Player>().get_filteredTrace_a();
        filteredTrace_b = GetComponent<Player>().get_filteredTrace_b();
        stepsize = GetComponent<Player>().stepsize;

        forecast_d = GetComponent<Forecast>().get_forecast_d();
        angle = GetComponent<Forecast>().angle;

        SerialObject obj = new SerialObject(width, height, start, end,
                                            dangerMap, var, enemies, trace,
                                            filteredTrace_a, filteredTrace_b, stepsize,
                                            forecast_d, angle);

        string file = dir + filePrefix + "_serial.xml";
        Stream stream = File.Open(file, FileMode.Create);

        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Serialize(stream, obj);
        stream.Close();
    }
开发者ID:hycis,项目名称:BehaviourLearning,代码行数:33,代码来源:Serialize.cs

示例9: DeserializeObject

    private static object DeserializeObject(byte[] bytes)
    {
        var BinaryFormatter = new BinaryFormatter();
        var MemoryStream = new MemoryStream(bytes);

        return BinaryFormatter.Deserialize(MemoryStream);
    }
开发者ID:EranYaacobi,项目名称:Centipede,代码行数:7,代码来源:RegisterCustomTypes.cs

示例10: SaveGameData

 //overwrites the file with a fresh save
 public void SaveGameData()
 {
     bf = new BinaryFormatter();
     fs = File.Create(Application.persistentDataPath + GAME_DATA_FILE);
     bf.Serialize(fs, gd);
     fs.Close();
 }
开发者ID:AdamBoyce,项目名称:UnitySaveLoadExample,代码行数:8,代码来源:SaveLoadBehaviour.cs

示例11: MenuSavePbObject

	public static void MenuSavePbObject()
	{
		pb_Object[] selection = pbUtil.GetComponents<pb_Object>(Selection.transforms);
		int len = selection.Length;

		if(len < 1) return;

		string path = "";

		if(len == 1)
			path = EditorUtility.SaveFilePanel("Save ProBuilder Object", "", selection[0].name, "pbo");// "Save ProBuilder Object to File.");
		else
			path = EditorUtility.SaveFolderPanel("Save ProBuilder Objects to Folder", "", "");

		foreach(pb_Object pb in selection)
		{
			//Creates a new pb_SerializableObject object.
			pb_SerializableObject obj = new pb_SerializableObject(pb);

			//Opens a file and serializes the object into it in binary format.
			Stream stream = File.Open( len == 1 ? path : path + pb.name + ".pbo", FileMode.Create);

			BinaryFormatter formatter = new BinaryFormatter();

			formatter.Serialize(stream, obj);
			
			stream.Close();			
		}
	}
开发者ID:Rikarie,项目名称:Kingdom,代码行数:29,代码来源:SaveLoadPbObjects.cs

示例12: Main

  public static void Main(String[] args) 
  {
    Console.WriteLine ("Fill MyList object with content\n");
    MyList l = new MyList();
    for (int x=0; x< 10; x++) 
    {
      Console.WriteLine (x);
      l.Add (x);
    } // end for
    Console.WriteLine("\nSerializing object graph to file {0}", FILENAME);
    Stream outFile = File.Open(FILENAME, FileMode.Create, FileAccess.ReadWrite);
    BinaryFormatter outFormat = new BinaryFormatter();
    outFormat.Serialize(outFile, l);
    outFile.Close();
    Console.WriteLine("Finished\n");

    Console.WriteLine("Deserializing object graph from file {0}", FILENAME);
    Stream inFile = File.Open(FILENAME, FileMode.Open, FileAccess.Read);
    BinaryFormatter inFormat = new BinaryFormatter();
    MyList templist = (MyList)inFormat.Deserialize(inFile);
    Console.WriteLine ("Finished\n");
    
    foreach (MyListItem mli in templist) 
    {
      Console.WriteLine ("List item number {0}, square root {1}", mli.Number, mli.Sqrt);
    } //foreach

    inFile.Close();
  } // end main
开发者ID:ArildF,项目名称:masters,代码行数:29,代码来源:simpleserialize.cs

示例13: LoadInventory

    public void LoadInventory()
    {
        if(File.Exists(Application.persistentDataPath + "Inventory.dat"))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file_loc = File.Open(Application.persistentDataPath + "Inventory.dat",FileMode.Open);

            Inventory_Item_Info Inven = (Inventory_Item_Info)bf.Deserialize(file_loc);

            file_loc.Close();
            print (Inven.AllItems.Count);

            for(int i = 0; i < Inven.AllItems.Count; ++i)
            {
                print ("item Loaded:" + i);
                if(LoadItem(Inven.AllItems[i]))
                {
                    Inventory.Inven.AddExisingItem(LoadItem(Inven.AllItems[i]));
                }
                else
                {

                }
            }
        }
    }
开发者ID:Frozen-Ewok,项目名称:IdleHero,代码行数:26,代码来源:Game_Info.cs

示例14: LoadHero

    public void LoadHero()
    {
        HeroScript = Hero_Data.Hero.GetComponent<Hero_Data>();
        if(File.Exists(Application.persistentDataPath + "HeroInfo.dat"))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file_loc = File.Open(Application.persistentDataPath + "HeroInfo.dat",FileMode.Open);

            Hero_Info Hero = (Hero_Info)bf.Deserialize(file_loc);

            file_loc.Close();

            HeroScript.m_dGold = Hero.m_dGold;
            HeroScript.m_fAttack_Speed = Hero.m_fAttack_Speed;
            HeroScript.m_fDamage = Hero.m_fDamage;
            HeroScript.m_fHealth = Hero.m_fHealth;
            HeroScript.m_fHealth_Regen = Hero.m_fHealth_Regen;
            HeroScript.m_fMana = Hero.m_fMana;
            HeroScript.m_fMana_Regen = Hero.m_fMana_Regen;
            HeroScript.m_fMax_Health = Hero.m_fMax_Health;
            HeroScript.m_fMax_Mana = Hero.m_fMax_Mana;
            HeroScript.m_iCurrnet_Exp = Hero.m_iCurrnet_Exp;
            HeroScript.m_iExp_To_Level = Hero.m_iExp_To_Level;
            HeroScript.m_iStatPoints = Hero.m_iStatPoints;
        }
        else
        {

        }
    }
开发者ID:Frozen-Ewok,项目名称:IdleHero,代码行数:30,代码来源:Game_Info.cs

示例15: Deserialize

    Messages Deserialize(byte[] bytes)
    {
        MemoryStream stream = new MemoryStream(bytes);
        BinaryFormatter b = new BinaryFormatter();

        return (Messages)b.Deserialize(stream);
    }
开发者ID:Boykooo,项目名称:Boom,代码行数:7,代码来源:ServerManager.cs


注:本文中的BinaryFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。