Exemple #1
0
        public virtual void Save(PlayerSaveData saveData)
        {
            _variables.SaveTo(saveData.PlayerTraits, VariableDefinition.Saved);

            saveData.Name = Name;
            Trainer.Traits.SaveTo(saveData.TrainerTraits, VariableDefinition.Saved);

            foreach (var creature in Trainer.Roster)
            {
                saveData.Creatures.Add(Creature.Save(creature.Creature));
            }

            foreach (var item in Trainer.Inventory.Items)
            {
                saveData.Items.Add(new ItemSaveData {
                    ItemPath = item.Item.Path, Count = item.Count
                });
            }
        }
Exemple #2
0
        public virtual void Load(PlayerSaveData saveData)
        {
            SetupVariables(saveData.PlayerTraits);

            // If the save data has creatures or items, anything set on the actual Player needs to be cleared so it
            // isn't duplicated on every save. This means if a new creature or item is added to the Player in the
            // editor existing saves will not include it.
            if (saveData.Creatures.Count > 0)
            {
                Trainer.Roster.Clear();
            }
            if (saveData.Items.Count > 0)
            {
                Trainer.Inventory.Items.Clear();
            }
            if (!string.IsNullOrEmpty(saveData.Name))
            {
                Name = saveData.Name;
            }

            Trainer.Traits.LoadFrom(saveData.TrainerTraits, VariableDefinition.Saved);

            foreach (var creatureData in saveData.Creatures)
            {
                var creature = Creature.Create(creatureData, Trainer);

                if (creature != null)
                {
                    Trainer.Roster.AddCreature(creature);
                }
                else
                {
                    Debug.LogWarningFormat(_missingSpeciesWarning, creatureData.SpeciesPath);
                }
            }

            foreach (var itemData in saveData.Items)
            {
                var item = Resources.Load <Item>(itemData.ItemPath);
                Trainer.Inventory.Add(item, itemData.Count);
            }
        }