Сохранить дерево навыков - PullRequest
0 голосов
/ 09 июля 2020

У меня проблема с деревом навыков. Он уже готов, но я не могу сохранить его, для других сцен и т. Д. c. Я использую Binary Formatter для сохранения, но всякий раз, когда я прохожу сцену, он не продолжается.

коды ниже : https://pastebin.com/mcWAqw0x https://pastebin.com/VEt7eiiE

using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
using System ;
    
 
public class PlayerSkills
{
    public event EventHandler OnSkillPointsChanged ;
    public event EventHandler < OnSkillUnlockedEventArgs > OnSkillUnlocked ;
    public class OnSkillUnlockedEventArgs : EventArgs
    {
        public SkillType skillType ;
    }
 
    public enum SkillType
    {
        Nenhum,
        Soco,
        PunchC,
        PunchNC,
        Bola fogo,
        FireballC,
        FireballNc,
        Atordoar,
        StunC,
        StunNC,
        Def,
        DefC,
        DefNC,
        Pleh,
        PlehUp,
    }
 
   
    public list < SkillType > unlockedSkillTypeList ;
    public int skillPoints ;
   
   
    public PlayerSkills ( )
    {      
 
        unlockedSkillTypeList = new List < SkillType > ( ) ;
       
    }
 
    public void AddSkillPoints ( )
    {
        skillPoints ++;
        OnSkillPointsChanged ?. Invoke ( this , EventArgs . Empty ) ;
    }
 
    public int GetSkillPoints ( )
    {
        return skillPoints ;
    }
    public void UnlockSkill ( SkillType skillType )
    {
        if ( ! IsSkillUnlocked ( skillType ) )
        {
            unlockedSkillTypeList . Adicionar ( skillType ) ;
            OnSkillUnlocked ?. Invoke ( este , novo OnSkillUnlockedEventArgs { skillType = skillType } ) ;          
        }
     
    }
 
 
    public bool IsSkillUnlocked ( SkillType skillType )
    {
        return unlockedSkillTypeList . Contém ( skillType ) ;      
    }
    public SkillType GetSkillRequeriment ( SkillType skillType )
    {
        switch ( skillType ) {
            caso SkillType . PunchC : retorna SkillType . Soco ;
            caso SkillType . PunchNC : retorna SkillType . Soco ;              
            caso SkillType . FireballC : retorna SkillType . Bola de fogo ;    
            caso SkillType . FireballNc : retorna SkillType . Bola de fogo ;
            caso SkillType . StunC : retorna SkillType . Atordoar ;
            caso SkillType . StunNC : retorna SkillType . Atordoar ;
            caso SkillType . DefC : retorna SkillType . Def ;
            caso SkillType . DefNC : retorna SkillType . Def ;
            caso SkillType . PlehUp : retorna SkillType . Pleh ;
           
        }
        return SkillType . Nenhuma ;
       
    }
    public bool CanUnlock ( SkillType skillType )
    {
        SkillType skillRequiremente = GetSkillRequeriment ( skillType ) ;
 
        if ( skillRequiremente ! = SkillType . Nenhum )
        {
            if ( IsSkillUnlocked ( skillRequiremente ) )
            {          
                return true ;
            }
            else
            {
                retornar false;
            }
        }
        else
        {
            return true ;
        }
    }
 
   
    public bool TryUnlockSkill ( SkillType skillType )
    {
        if ( CanUnlock ( skillType ) )
        {
            if ( skillPoints > 0 )
            {
                skillPoints -;
                OnSkillPointsChanged ?. Invoke ( this , EventArgs . Empty ) ;
                UnlockSkill ( skillType ) ;
                return true ;
            }
            else
            {
                return false;
            }
           
           
        }
        else
        {
            return false;
        }
       
    }
 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...