Texture2D.GetData方法的解决方法

pin*_*man 6 c# xna textures ios monogame

我正在使用Monogame将游戏从XNA转换为iOS.
在以下代码段的代码,smallDeform是一种Texture2D在其上予调用GetData方法.

smallDeform = Game.Content.Load<Texture2D>("Terrain/...");
smallDeform.GetData(smallDeformData, 0, smallDeform.Width * smallDeform.Height);
Run Code Online (Sandbox Code Playgroud)

我在使用Monogame时遇到了一些问题,因为iOS中的功能还没有实现,因为它返回了这个异常.

#if IOS 
   throw new NotImplementedException();
#elif ANDROID
Run Code Online (Sandbox Code Playgroud)

我尝试从Windows中序列化XML文件中的数据,以从iOS加载整个文件.序列化文件每个重量超过100MB,这是解析时无法接受的.

基本上,我正在寻找一种解决方法,以便在不使用该方法的情况下从纹理中获取数据(例如a uint[]Color[])GetData.

PS:我在Mac上,所以我不能使用Monogame SharpDX库.

提前致谢.

pin*_*man 1

我回答我自己的问题,如果有人遇到同样的问题。

按照craftworkgame的建议,我使用字节流保存数据,但由于缺少File类,我不得不使用 WinRT 函数:

private async void SaveColorArray(string filename, Color[] array)
{
    StorageFile sampleFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(filename + ".dat", CreationCollisionOption.ReplaceExisting);
    IRandomAccessStream writeStream = await sampleFile.OpenAsync(FileAccessMode.ReadWrite);
    IOutputStream outputSteam = writeStream.GetOutputStreamAt(0);
    DataWriter dataWriter = new DataWriter(outputSteam);
    for (int i = 0; i < array.Length; i++)
    {
        dataWriter.WriteByte(array[i].R);
        dataWriter.WriteByte(array[i].G);
        dataWriter.WriteByte(array[i].B);
        dataWriter.WriteByte(array[i].A);
    }

    await dataWriter.StoreAsync();
    await outputSteam.FlushAsync();
}

protected async Task<Color[]> LoadColorArray(string filename)
{
    StorageFile sampleFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(filename + ".dat", CreationCollisionOption.OpenIfExists);
    IRandomAccessStream readStream = await sampleFile.OpenAsync(FileAccessMode.Read);
    IInputStream inputSteam = readStream.GetInputStreamAt(0);
    DataReader dataReader = new DataReader(inputSteam);
    await dataReader.LoadAsync((uint)readStream.Size);

    Color[] levelArray = new Color[dataReader.UnconsumedBufferLength / 4];
    int i = 0;
    while (dataReader.UnconsumedBufferLength > 0)
    {
        byte[] colorArray = new byte[4];
        dataReader.ReadBytes(colorArray);
        levelArray[i++] = new Color(colorArray[0], colorArray[1], colorArray[2], colorArray[3]);
    }

    return levelArray;
}
Run Code Online (Sandbox Code Playgroud)