コード例 #1
0
    public static Character GetCharacter(string characterName)
    {
        var character = JsonUtility.FromJson <Character>(PlayerPrefs.GetString(characterName, Constants.PpSerializeDefault));

        character.Weapons = new List <Weapon>();
        character.Weapons.Add(JsonUtility.FromJson <Weapon>(PlayerPrefs.GetString(characterName + Constants.PpWeapon1, Constants.PpSerializeDefault)));
        character.Weapons.Add(JsonUtility.FromJson <Weapon>(PlayerPrefs.GetString(characterName + Constants.PpWeapon2, Constants.PpSerializeDefault)));
        character.Skills = new List <Skill>();
        character.Skills.Add(SkillsData.GetSkillFromName(PlayerPrefs.GetString(characterName + Constants.PpSkill1, Constants.PpSerializeDefault)));
        character.Skills.Add(SkillsData.GetSkillFromName(PlayerPrefs.GetString(characterName + Constants.PpSkill2, Constants.PpSerializeDefault)));
        character.Inventory = new List <InventoryItem>();
        for (int i = 0; i < character.InventoryPlace; ++i)
        {
            var serialized = PlayerPrefs.GetString(characterName + Constants.PpInventoryItem + i, Constants.PpSerializeDefault);
            if (string.IsNullOrEmpty(serialized))
            {
                continue;
            }
            var typeId = PlayerPrefs.GetInt(characterName + Constants.PpInventoryItem + i + "Type");
            if (typeId == InventoryItemType.Weapon.GetHashCode())
            {
                character.Inventory.Add(JsonUtility.FromJson <Weapon>(serialized));
            }
            else if (typeId == InventoryItemType.Skill.GetHashCode())
            {
                character.Inventory.Add(SkillsData.GetSkillFromName(serialized));
            }
            else
            {
                character.Inventory.Add(ItemsData.GetItemFromName(serialized));
            }
        }
        return(character);
    }