Exemple #1
0
        /// <summary>
        ///     Save the RpgCharacter to file. The file will be named based off the character's name and GUID
        /// </summary>
        public static void SaveCharacter(RpgCharacterData character)
        {
            if (character == null)
            {
                Debug.LogError("Cannot save a null RpgCharacter!");
                return;
            }

            RpgCharacterPacket packet   = character.ExportSerializationPacket();
            string             savePath = RpgCharacterSerializer.GetFullPath(character.Name, character.Id.ToString());

            RpgCharacterSerializer.WriteToXml(packet, savePath);
        }
Exemple #2
0
        /// <summary>
        ///     Load an RpgCharacter from file, given its name and it ID (GUID as string).
        ///     It is the developer's responsibility to somehow save the GUID of the player before saving the character.
        ///     Saving the GUID can be done in PlayerPrefs or use the SaveSlot system provided in this project
        /// </summary>
        /// <param name="characterName">Character name.</param>
        /// <param name="characterId">Character GUID as a string.</param>
        public static RpgCharacterData LoadCharacter(string characterName, string characterId)
        {
            if (string.IsNullOrEmpty(characterName))
            {
                Debug.LogError("Cannot load an RpgCharacter with a blank name!");
                return(null);
            }
            if (string.IsNullOrEmpty(characterId))
            {
                Debug.LogError("Cannot load an RpgCharacter with a blank GUID!");
                return(null);
            }


            string             loadPath  = RpgCharacterSerializer.GetFullPath(characterName, characterId);
            RpgCharacterPacket packet    = RpgCharacterSerializer.ReadFromXml(loadPath);
            RpgCharacterData   character = new RpgCharacterData(packet);

            Debug.Assert(character != null, "RpgCharacter of name \"" + characterName + "\" failed to load!");

            return(character);
        }