2

I'm trying to create the plugin described in the title. But I cant seem to get it to work with unity. Following the instructions I created the real plugin and placed it in the WSA folder in the Plugins folder. Then I created a fake plugin for the editor to use. I'm getting a Internal compiler error.. Here is the code I have so far if it helps.

using System;
using System.IO;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PCLStorage;
namespace MyIO
{
    public static class Serializer
    {
        private static string fileText;
        public static string FileText
        {
            get { return fileText; }
            set
            {
                if (FileText == value) return;
                fileText = value;

            }
        }
        public static async Task WriteData(GameData data)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(GameData));
            IFolder rootFolder = FileSystem.Current.LocalStorage;

            IFolder folder = await rootFolder.CreateFolderAsync("ArabianHeroesSaveGames",CreationCollisionOption.OpenIfExists);
            IFile file = await folder.CreateFileAsync("SaveGame.dat",CreationCollisionOption.ReplaceExisting);
            await file.WriteAllTextAsync(SerializeObject<GameData>(data));

        }
        public static async Task<GameData> LoadData()
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder folder = await rootFolder.CreateFolderAsync("ArabianHeroesSaveGames", CreationCollisionOption.OpenIfExists);
            IFile file = await folder.GetFileAsync("SaveGame.dat");
            using (var stream = await file.OpenAsync(FileAccess.Read))
            {
                using (var reader = new StreamReader(stream))
                {
                    FileText = await reader.ReadToEndAsync();
                    return DeserializeObject<GameData>(FileText);
                }
            }

        }
        public static T DeserializeObject<T>(string s)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
            using (StringReader textReader = new StringReader(s))
            {
               return  (T)xmlSerializer.Deserialize(textReader);
            }
        }
        public static string SerializeObject<T>(this T toSerialize)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());

            using (StringWriter textWriter = new StringWriter())
            {
                xmlSerializer.Serialize(textWriter, toSerialize);
                return textWriter.ToString();
            }
        }
    }
}

the fake plugin has the same method names but they dont return the same type since the fake plugin has to be a .Net 3.5 project. I'm using the #if NETFX_CORE to call the different methods.

Uri Popov
  • 2,127
  • 2
  • 25
  • 43

0 Answers0