public void Save_Button()
 {
     try
     {
         SaveScript.SaveData(PlayerDataTransfer.LoadPlayerData());
         StartCoroutine(SaveSuccessRoutine());
     }
     catch (System.Exception)
     {
         Debug.Log("save error");
     }
 }
Esempio n. 2
0
    private void InitializePlayer()
    {
        playerUnit = Instantiate(playerPrefab, playerBattleStation.position, playerBattleStation.rotation).GetComponent <PlayerUnit>();

        playerUnit.GetComponent <PlayerUnit>().OnLevelUp += OnPlayerLevelUp;

        var playerData = PlayerDataTransfer.LoadPlayerData();

        playerUnit.unitName         = playerData.unitName;
        playerUnit.unitLevel        = playerData.unitLevel;
        playerUnit.unitPower        = playerData.unitPower;
        playerUnit.unitDex          = playerData.unitSpeed;
        playerUnit.maxHP            = playerData.maxHP;
        playerUnit.currentHP        = playerData.maxHP;
        playerUnit.unitIntelligence = playerData.unitIntelligence;
        //playerUnit.currentMP = 0;
        playerUnit.currentExp           = playerData.currentExp;
        playerUnit.expToLevel           = playerData.expToLevel;
        playerUnit.totalGold            = playerData.totalGold;
        playerUnit.availableStatPoints  = playerData.availableStatPoints;
        playerUnit.availableSkillPoints = playerData.availableSkillPoints;

        playerUnit.knownSkills    = playerData.knownSkills;
        playerUnit.equippedSkills = playerData.equippedSkills;

        for (int i = 0; i < playerUnit.equippedSkills.Count; i++)
        {
            skillButtons[i].SetActive(true);
            Button skillButton = skillButtons[i].GetComponent <Button>();
            var    buttonText  = skillButton.GetComponentInChildren <Text>();
            if (buttonText != null)
            {
                buttonText.text = playerUnit.equippedSkills[i].SkillName;
            }
        }

        playerHUD.SetHP(playerUnit.currentHP);
        playerHUD.SetMP(playerUnit.CurrentMP);
        playerHUD.SetXp(playerUnit.currentExp);
    }