예제 #1
0
    public void SaveLevel(string path, string folder)
    {
        Texture2D Save = new Texture2D(Level.GridManagers.GetLength(0) * 50, Level.GridManagers.GetLength(1) * 30, TextureFormat.RGBA32, false);

        for (int y = 0; y < Save.height; y++)
        {
            for (int x = 0; x < Save.width; x++)
            {
                Color32 color = new Color32();
                try
                {
                    BlockBase block = Level.GridManagers[Mathf.FloorToInt(x / 50), Mathf.FloorToInt(y / 30)].GridObject[x % 50, y % 30];
                    long      save  = block.Save();
                    byte[]    b     = BitConverter.GetBytes(save);
                    color.r = b[3];
                    color.g = b[2];
                    color.b = b[1];
                    color.a = b[0];
                }
                catch (NullReferenceException e)
                {
                    color.r = 255;
                    color.g = (byte)((int)_level.GridManagers[0, 0].Theme * 10);
                    color.b = 255;
                    color.a = 255;
                }
                finally
                {
                    Save.SetPixel(x, y, color);
                }
            }
        }
        Save.Apply();
        byte[] bytes = Save.EncodeToPNG();
        File.WriteAllBytes(Application.streamingAssetsPath + "/levels/" + folder + "/" + path, bytes);
        _level.ClearHistory();
        lt.LevelName = path;
    }