Exemplo n.º 1
0
    void ApplyPlayerData(PlayerSaveData playersave, CharacterSystem character)
    {
        if (character && character.inventory) {
            //Debug.Log ("Applying ");
            //Debug.Log ("with " + PlayerSaveDataText (playersave));

            character.inventory.SetItemsFromText (playersave.ItemData);
            character.inventory.UpdateOtherInventory (playersave.EquipData);
            if (character.inventory.Items.Count > playersave.FPSItemIndex)
                character.inventory.EquipItemByCollector (character.inventory.Items [playersave.FPSItemIndex]);
            string[] positionraw = playersave.Position.Split ("," [0]);
            if (positionraw.Length > 2) {
                Vector3 position = Vector3.zero;
                float.TryParse (positionraw [0], out position.x);
                float.TryParse (positionraw [1], out position.y);
                float.TryParse (positionraw [2], out position.z);
                character.transform.position = position;
            }

            character.HP = playersave.Health;
            CharacterLiving living = character.GetComponent<CharacterLiving> ();
            if (living) {
                living.Hungry = playersave.Food;
                living.Water = playersave.Water;
            }
            // if new save, all parameter must be set by default.
            if (playersave.Food <= 0 && playersave.Water <= 0 && playersave.Health <= 0) {
                character.HP = character.HPmax;
                if (living) {
                    living.Hungry = living.HungryMax;
                    living.Water = living.WaterMax;
                }
            }

            character.InitializeData ();
        }
    }