Thursday, April 2, 2015

Unity here is how I save triple array using playerpref

Let say you have an array you want to save into Unity using playerpref, and you have a triple array of 50 x 50 x 50 = size of 125,000


public int[,,] map;

    void Start()
    {
        map = new int[50, 50, 50];
        
    }


/////////////////////////////////////
Below is how I do it
///////////////////////////////////

public void savegame()
    {
        for (int y = 0y < 50y++)
        {
            
            for (int x = 0x < 50x++)
            {
                for (int z = 0z < 50z++)
                {
                    if(map[x,y,z]!=0)
                    {

                        PlayerPrefs.SetInt ("mymap"+x+"E"+y+"E"+z+"E",map[x,y,z]);
                        Debug.Log ("saving " + "mymap"+x+"E"+y+"E"+z+"E");
                    }
                }
            }
        }
    }

    void loadgame()
    {
        for (int y = 0y < 50y++)
        {
            
            for (int x = 0x < 50x++)
            {
                for (int z = 0z < 50z++)
                {

                    map[x,y,z]=PlayerPrefs.GetInt ("mymap"+x+"E"+y+"E"+z+"E");
                        
                }
            }
        }

   }

No comments:

Post a Comment