示例#1
0
    void Load()
    {
        try
        {
            PlayerData data = EasySerializer.DeserializeObjectFromFile(Application.persistentDataPath + "/data.dat") as PlayerData;
            if (data != null)
            {
                levelArray = data.levelArray;
                LevelsDone();
                OpenNext();
            }
            else
            {
                levelArray = new LevelState[20];

                for (int i = 0; i < levelArray.Length; i++)
                {
                    levelArray[i] = LevelState.NOT_OPEN;
                }
                Save();
                LevelsDone();
                OpenNext();
            }
        }
        catch (Exception e)
        {
            Debug.Log("ERROR in Load: " + e);
        }
    }
    //called by the editor script
    public void ResetForm()
    {
        branch = BinaryTree.GenerateBranch(length);
        //Debug.Log("Branches : " + BinaryTree.branchesCount);
        if (sim == null)
        {
            sim = new Simulation();
        }
        sim.clear();
        leafCount = 0;
        Particle2D start = sim.makeParticle(branch.Position);

        start.makeFixed();
        CopyBranchTopology(start, branch, ref sim);
        sim.getParticle(1).makeFixed();
        sim.RecalculateConvergenceGroupID();
        sim.ShuffleSprings();
        sim.ShuffleAngles();
        //if (Application.isEditor) OnDrawGizmosUpdate();
        Debug.Log("Serialize branch to bytes");
        serializedBranch = EasySerializer.SerializeObjectToBytes(branch);

        if (OnResetForm != null)
        {
            OnResetForm();                           //invokde the event
        }
        else
        {
            //Debug.Log("No one register OnResetForm");
        }
    }
示例#3
0
    public static object DeserializeObjectFromFile(string filePath)
    {
        if (!File.Exists(filePath))
        {
            return(null);
        }


        EasySerializer.SetEnvironmentVariables();

        Stream stream = null;

        try {
            stream = File.Open(filePath, FileMode.Open);
        }

        catch {
            return(null);
        }

        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Binder = new VersionDeserializationBinder();
        object o = formatter.Deserialize(stream);

        stream.Close();

        return(o);
    }
示例#4
0
    public void SaveNew()
    {
        PlayerHighscores highscores = new PlayerHighscores();

        print("SavingNew");
        EasySerializer.SerializeObjectToFile(highscores, SAVE_PATH);
    }
示例#5
0
 void Save()
 {
     {
         try
         {
             PlayerData oldData = EasySerializer.DeserializeObjectFromFile(Application.persistentDataPath + "/data.dat") as PlayerData;
             if (oldData != null)
             {
                 oldData.levelArray = levelArray;
                 EasySerializer.SerializeObjectToFile(oldData, Application.persistentDataPath + "/data.dat");
                 print("GOT DATA, saving old");
             }
             else
             {
                 PlayerData data = new PlayerData();
                 data.levelArray = levelArray;
                 EasySerializer.SerializeObjectToFile(data, Application.persistentDataPath + "/data.dat");
             }
         }
         catch (Exception e)
         {
             Debug.Log("ERROR in Save: " + e);
         }
     }
 }
 void Awake()
 {
     //Debug.Log("Re construct branch from serialized bytes");
     if (serializedBranch != null)
     {
         branch = EasySerializer.DeserializeObjectFromBytes(serializedBranch) as BinaryTree;
     }
 }
示例#7
0
    public static object DeserializeObjectFromBytes(byte[] data)
    {
        EasySerializer.SetEnvironmentVariables();

        MemoryStream stream = new MemoryStream(data);

        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Binder = new VersionDeserializationBinder();
        return(formatter.Deserialize(stream));
    }
    public void ResetScoreAt(int level)
    {
        level--;
        var lostHighscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as LostHighscores;

        if (lostHighscores == null)
        {
            return;
        }
        lostHighscores.highscores [level] = long.MaxValue;
        EasySerializer.SerializeObjectToFile(lostHighscores, SAVE_PATH);
    }
示例#9
0
    // Use this for initialization
    void Awake()
    {
        SAVE_PATH = Application.persistentDataPath + "/data_highscore.dat";
        PlayerHighscores highscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as PlayerHighscores;

        if (highscores != null)
        {
        }
        else
        {
            SaveNew();
        }
    }
    public NotUploadedHighscores()
    {
        SAVE_PATH = Application.persistentDataPath + "/data_losthighscore.dat";
        LostHighscores lostHighscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as LostHighscores;

        if (lostHighscores != null)
        {
        }
        else
        {
            SaveNew();
        }
    }
示例#11
0
    public static byte[] SerializeObjectToBytes(object serializableObject)
    {
        EasySerializer.SetEnvironmentVariables();

        MemoryStream stream = new MemoryStream();

        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Binder = new VersionDeserializationBinder();
        formatter.Serialize(stream, serializableObject);

        return(stream.GetBuffer());
    }
示例#12
0
    public static void SerializeObjectToFile(object serializableObject, string filePath)
    {
        EasySerializer.SetEnvironmentVariables();

        Stream stream = File.Open(filePath, FileMode.Create);

        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Binder = new VersionDeserializationBinder();
        formatter.Serialize(stream, serializableObject);

        stream.Close();
    }
    public void ResetLostHighscore()
    {
        var lostHighscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as LostHighscores;

        if (lostHighscores == null)
        {
            return;
        }
        for (int i = 0; i < lostHighscores.highscores.Length; i++)
        {
            lostHighscores.highscores [i] = long.MaxValue;
        }
        EasySerializer.SerializeObjectToFile(lostHighscores, SAVE_PATH);
    }
示例#14
0
    public float LoadHighscoreAtLevel(int level)
    {
        level--;
        PlayerHighscores highscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as PlayerHighscores;

        if (highscores != null)
        {
            return(highscores.highscores [level]);
        }
        else
        {
            SaveNew();
        }
        return(float.MaxValue);
    }
示例#15
0
    public void SaveHighScoreAtLevel(int level, float time)
    {
        level--;
        PlayerHighscores highscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as PlayerHighscores;

        if (highscores != null)
        {
            if (highscores.highscores [level] > time)
            {
                highscores.highscores [level] = time;
                EasySerializer.SerializeObjectToFile(highscores, SAVE_PATH);
            }
        }
        else
        {
            SaveNew();
        }
    }
示例#16
0
    public static void SerializeObjectToFile(object serializableObject, string filePath)
    {
        EasySerializer.SetEnvironmentVariables();
        Stream stream = null;

        try {
            stream = File.Open(filePath, FileMode.Create);
        } catch (FileNotFoundException e) {
            e.ToString();
            return;
        }
        BinaryFormatter formatter = new BinaryFormatter();

        formatter.Binder = new VersionDeserializationBinder();
        formatter.Serialize(stream, serializableObject);

        stream.Close();
    }
    public void SaveHighScoreAtLevel(int level, long time)
    {
        level--;
        var lostHighscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as LostHighscores;

        if (lostHighscores != null)
        {
            if (lostHighscores.highscores [level] > time)
            {
                lostHighscores.highscores [level] = time;
                EasySerializer.SerializeObjectToFile(lostHighscores, SAVE_PATH);
            }
            else
            {
            }
        }
        else
        {
            SaveNew();
        }
    }
    public void SaveNew()
    {
        LostHighscores lostHighscores = new LostHighscores();

        EasySerializer.SerializeObjectToFile(lostHighscores, SAVE_PATH);
    }
    public long[] GetLostHighscores()
    {
        LostHighscores lostHighscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as LostHighscores;

        return(lostHighscores.highscores);
    }
示例#20
0
    public float[] LoadHighscores()
    {
        PlayerHighscores highscores = EasySerializer.DeserializeObjectFromFile(SAVE_PATH) as PlayerHighscores;

        return(highscores.highscores);
    }