當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。