示例#1
0
        /**
         * <summary>De-serializes a RememberData class.</summary>
         * <param name = "dataString">The RememberData class, serialized as a string</param>
         * <returns>The de-serialized RememberData class</return>
         */
        public static T LoadScriptData <T> (string dataString) where T : RememberData
        {
            iFileFormatHandler fileFormatHandler = SaveSystem.FileFormatHandler;

            if (dataString.StartsWith(fileFormatHandler.GetSaveMethod()))
            {
                dataString = dataString.Remove(0, fileFormatHandler.GetSaveMethod().ToCharArray().Length);
            }

            return(fileFormatHandler.LoadScriptData <T> (dataString));
        }
示例#2
0
        /**
         * <summary>Deserializes a string into an OptionsData class.</summary>
         * <param name = "dataString">The OptionsData, serialized as a string</param>
         * <returns>The de-serialized OptionsData class</returns>
         */
        public static OptionsData DeserializeOptionsData(string dataString)
        {
            iFileFormatHandler fileFormatHandler = SaveSystem.FileFormatHandler;

            if (dataString.StartsWith(fileFormatHandler.GetSaveMethod()))
            {
                dataString = dataString.Remove(0, fileFormatHandler.GetSaveMethod().ToCharArray().Length);
            }
            else
            {
                if (dataString.StartsWith("XML") || dataString.StartsWith("Json") || dataString.StartsWith("Binary"))
                {
                    // Switched method, so make new
                    return(new OptionsData());
                }
            }
            return((OptionsData)DeserializeObject <OptionsData> (dataString));
        }
示例#3
0
        /**
         * <summary>Serializes an object, either by XML, Binary or Json, depending on the game's iFileFormatHandler.</summary>
         * <param name = "dataObject">The object to serialize</param>
         * <param name = "addMethodName">If True, the name of the serialization method (XML, Binary or Json) will be appended to the start of the serialized string. This is useful when the same file is read later by a different serialization method.</param>
         * <returns>The object, serialized to a string</returns>
         */
        public static string SerializeObject <T> (object dataObject, bool addMethodName = false)
        {
            iFileFormatHandler fileFormatHandler = SaveSystem.FileFormatHandler;
            string             serializedString  = SaveSystem.FileFormatHandler.SerializeObject <T> (dataObject);

            if (serializedString != "" && addMethodName)
            {
                serializedString = fileFormatHandler.GetSaveMethod() + serializedString;
            }

            return(serializedString);
        }