주녘공부일지

[더 챌린저스] 게임 내 데이터 관리 본문

GameEngine/Unity - Project

[더 챌린저스] 게임 내 데이터 관리

주녘 2023. 7. 19. 20:30
728x90

1. 제이슨 데이터 관리

- 제이슨 데이터를 빠르고 편리하게 사용하기 위해 파싱해서 딕셔너리로 사용

    public void Init()
    {
        SkillDict = LoadJson<SkillData, int, Skill>("SkillData").MakeDict();
        CharInfoDict = LoadJson<CharacterData, int, CharacterInfo>("CharacterData").MakeDict();
    }

    Loader LoadJson<Loader, Key, Value>(string path) where Loader : ILoader<Key, Value>
    { 
        TextAsset textAsset = Managers.Resource.Load<TextAsset>($"Data/{path}");
        return JsonUtility.FromJson<Loader>(textAsset.text);
    }
[Serializable]
public class Skill
{
    public int skillType; // ENUM_SKILL_TYPE (Key)
    public float damage;
    public float runTime;
    public float stunTime;
    public float risingPower;
    public float pushingPower;
    public int hitSoundType; // ENUM_SFX_TYPE (히트사운드)
}

public class SkillData : ILoader<int, Skill>
{
    public List<Skill> Skills = new List<Skill>();

    public Dictionary<int, Skill> MakeDict()
    {
        Dictionary<int, Skill> skillDict = new Dictionary<int, Skill>();
        foreach (Skill skill in Skills)
            skillDict.Add(skill.skillType, skill);
        return skillDict;
    }
}
{
    "Skills": [
        {
            "skillType": 1, 
            "damage": 2.0,
            "runTime": 0.2,
            "stunTime": 0.35,
            "risingPower": 0,
            "pushingPower": 2.5,
            "hitSoundType" : 301
        },
        {
            "skillType": 2,
            "damage": 2.0,
            "runTime": 0.2,
            "stunTime": 0.35,
            "risingPower": 0,
            "pushingPower": 2.5,
            "hitSoundType" : 302
        },
        
        ...
    ]
}

2. PlayerPrefs

유니티에서 제공해주는 데이터 관리 클래스로 유저가 게임 내에서 세팅한 정보를 저장, 불러오기하기 위해 사용

- 해당 클래스는 int, float, string 타입만 지원하기 때문에 동시에 사용되는 데이터의 일부만 저장, 불러오기를 할 수 없도록 데이터 클래스로 묶어서 사용함

ex) 키 설정 값, 볼륨 크기 및 뮤트 상태

[Serializable]
public class KeySettingData
{
    public List<KeySettingDataElement> keySettingDataList = new List<KeySettingDataElement>();
    public float opacity;
    
    public KeySettingData(List<KeySettingDataElement> _keySettingDataList, float _opacity)
    {
        keySettingDataList = _keySettingDataList;
        opacity = _opacity;
    }
}

[Serializable]
public class KeySettingDataElement
{
    public int key; // ENUM_KEYSETTING_NAME의 번호 (키 값)
    public float scaleSize;
    public float rectTrX;
    public float rectTrY;

    public KeySettingDataElement(int _key, float scaleSize, float _rectTrX, float _rectTrY)
    {
        this.key = _key;
        this.scaleSize = scaleSize;
        this.rectTrX = _rectTrX;
        this.rectTrY = _rectTrY;
    }
}

 

https://godgjwnsgur7.tistory.com/55

 

[더 챌린저스] 키 설정 시스템

1. 키 설정 시스템 - 인게임 내에서 유저에게 불편함을 줄 수 있는 입력 키들은 고정으로 위치 및 크기를 정해주기엔 개수가 너무 많다고 판단해서 유저가 위치, 크기, 투명도 등을 직접 변경하여

godgjwnsgur7.tistory.com

 

728x90