コード例 #1
0
    void SaveRiver()
    {
        VectorPointData[] flatArray = new VectorPointData[NUM_BINS_X * NUM_BINS_Y];
        for (int x = 0; x < NUM_BINS_X; x++)
        {
            for (int y = 0; y < NUM_BINS_Y; y++)
            {
                VectorPointData vpD = new VectorPointData();
                vpD.position                  = VectorField[x][y].position;
                vpD.Vel                       = VectorField[x][y].Vel;
                vpD.Speed                     = VectorField[x][y].Speed;
                vpD.IndexX                    = VectorField[x][y].IndexX;
                vpD.IndexY                    = VectorField[x][y].IndexY;
                vpD.VisitCount                = VectorField[x][y].VisitCount;
                vpD.ParticleCount             = VectorField[x][y].ParticleCount;
                vpD.createParticleOn          = VectorField[x][y].createParticleOn;
                vpD.particleCreator           = VectorField[x][y].particleCreator;
                vpD.longTermCreator           = VectorField[x][y].longTermCreator;
                vpD.longTermOn                = VectorField[x][y].longTermOn;
                vpD.activeID                  = VectorField[x][y].activeID;
                flatArray[x * NUM_BINS_X + y] = vpD;
            }
        }
        VectorFieldInitializer myObject = new VectorFieldInitializer();

        myObject.FlatVectorField = flatArray;
        json = JsonUtility.ToJson(myObject);
        Debug.Log(json);

        //string filePath = Application.dataPath + gameDataProjectFilePath;
        string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName);

        File.WriteAllText(filePath, json);
    }
コード例 #2
0
    void LoadRiver()
    // From Unity Documentation
    {
        string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName);

        if (File.Exists(filePath))
        {
            // Read the json from the file into a string
            string dataAsJson = File.ReadAllText(filePath);
            // Pass the json to JsonUtility, and tell it to create a GameData object from it
            VectorFieldInitializer loadedData = JsonUtility.FromJson <VectorFieldInitializer>(dataAsJson);

            // Retrieve the allRoundData property of loadedData


            for (int x = 0; x < NUM_BINS_X; x++)
            {
                for (int y = 0; y < NUM_BINS_Y; y++)
                {
                    VectorPointData vpD = loadedData.FlatVectorField[x * NUM_BINS_X + y];
                    VectorField[x][y].position      = vpD.position;
                    VectorField[x][y].Vel           = vpD.Vel;
                    VectorField[x][y].Speed         = vpD.Speed;
                    VectorField[x][y].IndexX        = vpD.IndexX;
                    VectorField[x][y].IndexY        = vpD.IndexY;
                    VectorField[x][y].VisitCount    = vpD.VisitCount;
                    VectorField[x][y].ParticleCount = vpD.ParticleCount;
                    VectorField[x][y].activeID      = vpD.activeID;



                    VectorField[x][y].particleCreator = vpD.particleCreator;
                    VectorField[x][y].longTermCreator = vpD.longTermCreator;
                    VectorField[x][y].longTermOn      = vpD.longTermOn;
                    if (vpD.longTermCreator)
                    {
                        VectorField[x][y].createParticleOn = true;
                    }
                    //flatArray[x * NUM_BINS_X + y] = vpD;
                    //VectorField[x][y] = loadedData.FlatVectorField[x * NUM_BINS_X + y];
                }
            }
            //VectorField = loadedData;
        }
        else
        {
            Debug.LogError("Cannot load game data!");
        }
    }