Merge branch 'dev' of https://github.com/2aurore/Gameton-06 into dev
This commit is contained in:
@@ -7,6 +7,8 @@ namespace TON
|
|||||||
public class CharacterBase : MonoBehaviour, IDamage
|
public class CharacterBase : MonoBehaviour, IDamage
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[SerializeField] //
|
||||||
|
private PlayerData playerData;
|
||||||
public float currentHP;
|
public float currentHP;
|
||||||
public float maxHP;
|
public float maxHP;
|
||||||
public float currentSP;
|
public float currentSP;
|
||||||
@@ -41,42 +43,28 @@ namespace TON
|
|||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
int playerIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
// int playerIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||||
PlayerData playerData = PlayerDataManager.Singleton.playersData[playerIndex];
|
PlayerDataManager.Singleton.SetCurrentUserData();
|
||||||
|
playerData = PlayerDataManager.Singleton.player;
|
||||||
|
|
||||||
currentHP = maxHP = playerData.hp;
|
currentHP = maxHP = playerData.hp;
|
||||||
currentSP = maxSP = playerData.mp;
|
currentSP = maxSP = playerData.mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int level = 1; // 현재 레벨
|
|
||||||
public int exp = 0; // 현재 경험치
|
|
||||||
public int expVariable = 10; // 경험치 변수 (조정 가능)
|
|
||||||
|
|
||||||
// 현재 레벨에서 다음 레벨까지 필요한 경험치 계산
|
|
||||||
private int GetRequiredExp(int currentLevel)
|
|
||||||
{
|
|
||||||
return (6 * currentLevel * currentLevel) + (currentLevel * expVariable);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 경험치 추가 및 레벨업 처리
|
// 경험치 추가 및 레벨업 처리
|
||||||
public void AddExp(int amount)
|
public void AddExp(int amount)
|
||||||
{
|
{
|
||||||
exp += amount; // 경험치 추가
|
bool leveledUp = PlayerDataManager.Singleton.UpdateExpericence(amount);
|
||||||
bool leveledUp = false; // 레벨업 여부 체크
|
|
||||||
|
|
||||||
while (exp >= GetRequiredExp(level)) // 경험치가 충분하면 반복해서 레벨업
|
|
||||||
{
|
|
||||||
exp -= GetRequiredExp(level); // 초과 경험치 유지
|
|
||||||
level++; // 레벨 증가
|
|
||||||
leveledUp = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leveledUp)
|
if (leveledUp)
|
||||||
{
|
{
|
||||||
// 경험치와 레벨 데이터를 파일에 업데이트 한다.
|
// TODO: 레벨업 시 처리할 내용 추가
|
||||||
Debug.Log($"레벨업! 현재 레벨: {level}, 남은 경험치: {exp}");
|
Debug.Log($"레벨업! ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 경험치와 변경된 데이터를 파일에 업데이트 한다.
|
||||||
|
PlayerDataManager.Singleton.UpdatePlayerData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixedUpdate()
|
public void FixedUpdate()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Assertions;
|
||||||
|
|
||||||
namespace TON
|
namespace TON
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,13 @@ namespace TON
|
|||||||
|
|
||||||
private void LoadHeartData()
|
private void LoadHeartData()
|
||||||
{
|
{
|
||||||
heartDatas = JSONLoader.LoadFromResources<List<HeartData>>("Heart");
|
if (heartDatas != null)
|
||||||
|
{
|
||||||
|
heartDatas.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONLoader.SaveJsonToPersistentData("heart");
|
||||||
|
heartDatas = JSONLoader.LoadJsonFromPersistentData<List<HeartData>>("Heart");
|
||||||
if (heartDatas == null)
|
if (heartDatas == null)
|
||||||
{
|
{
|
||||||
heartDatas = new List<HeartData>();
|
heartDatas = new List<HeartData>();
|
||||||
@@ -37,8 +44,9 @@ namespace TON
|
|||||||
{
|
{
|
||||||
HeartData heartData = new HeartData(characterId);
|
HeartData heartData = new HeartData(characterId);
|
||||||
heartDatas.Add(heartData);
|
heartDatas.Add(heartData);
|
||||||
JSONLoader.SaveToFile(heartDatas, "heart");
|
Assert.IsTrue(JSONLoader.SaveUpdatedJsonToPersistentData(heartDatas, "heart"));
|
||||||
Debug.Log($"heartData test:: {heartData.currentHearts}");
|
Debug.Log($"heartData test:: {heartData.currentHearts}");
|
||||||
|
LoadHeartData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCurrentUserHeart()
|
public void SetCurrentUserHeart()
|
||||||
@@ -68,7 +76,8 @@ namespace TON
|
|||||||
public void SaveHeartData()
|
public void SaveHeartData()
|
||||||
{
|
{
|
||||||
heartDatas[characterId] = currentHeartData;
|
heartDatas[characterId] = currentHeartData;
|
||||||
JSONLoader.SaveToFile(heartDatas, "heart");
|
Assert.IsTrue(JSONLoader.SaveUpdatedJsonToPersistentData(heartDatas, "heart"));
|
||||||
|
LoadHeartData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 게임이 다시 실행될때 마지막 하트 소모 시간과 현재 시간을 계산해서 하트 충전량을 반영
|
// 게임이 다시 실행될때 마지막 하트 소모 시간과 현재 시간을 계산해서 하트 충전량을 반영
|
||||||
|
|||||||
101
Gameton-06/Assets/Gameton/Scripts/Character/PlayerDataManager.cs
Normal file
101
Gameton-06/Assets/Gameton/Scripts/Character/PlayerDataManager.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Assertions;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
public class PlayerDataManager : SingletonBase<PlayerDataManager>
|
||||||
|
{
|
||||||
|
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
||||||
|
public List<PlayerData> playersData { get; private set; }
|
||||||
|
|
||||||
|
public PlayerData player { get; private set; }
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private int expVariable = 50; // 경험치 변수 (조정 가능)
|
||||||
|
[SerializeField]
|
||||||
|
private int attackGrowthFactor = 50; // 공격력 성장 변수 (조정 가능)
|
||||||
|
[SerializeField]
|
||||||
|
private int defensiveGrowthFactor = 200; // 방어력 성장 변수 (조정 가능)
|
||||||
|
|
||||||
|
|
||||||
|
public void Initalize()
|
||||||
|
{
|
||||||
|
LoadPlayerData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadPlayerData()
|
||||||
|
{
|
||||||
|
if (playersData != null)
|
||||||
|
{
|
||||||
|
playersData.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONLoader.SaveJsonToPersistentData("player");
|
||||||
|
playersData = JSONLoader.LoadJsonFromPersistentData<List<PlayerData>>("player");
|
||||||
|
if (playersData == null)
|
||||||
|
{
|
||||||
|
playersData = new List<PlayerData>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 공격력과 방어력 업데이트
|
||||||
|
private void UpdateStats(int currentLevel)
|
||||||
|
{
|
||||||
|
player.attackPower *= 1 + (currentLevel - 1) / attackGrowthFactor;
|
||||||
|
player.defensivePower *= 1 + (currentLevel - 1) / defensiveGrowthFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 현재 레벨에서 다음 레벨까지 필요한 경험치 계산
|
||||||
|
private int GetRequiredExp(int currentLevel)
|
||||||
|
{
|
||||||
|
return (6 * currentLevel * currentLevel) + (currentLevel * expVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateExpericence(int amount)
|
||||||
|
{
|
||||||
|
// 경험치 추가
|
||||||
|
player.experience += amount;
|
||||||
|
|
||||||
|
// 추가된 경험치로 인한 현재 경험치가 레벨업에 필요한 경험치보다 크거나 같다면 레벨업
|
||||||
|
int requireLevelUpExp = GetRequiredExp(player.level);
|
||||||
|
if (player.experience >= requireLevelUpExp)
|
||||||
|
{
|
||||||
|
// 레벨업 후 초과된 경험치를 반영하기 위해 다시 계산
|
||||||
|
player.experience -= requireLevelUpExp;
|
||||||
|
// 레벨업으로 인한 공격력/방어력 업데이트
|
||||||
|
UpdateStats(player.level);
|
||||||
|
// 레벨 증가
|
||||||
|
player.level++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePlayerData()
|
||||||
|
{
|
||||||
|
int index = playersData.FindIndex(x => x.id == player.id);
|
||||||
|
if (index > -1)
|
||||||
|
{
|
||||||
|
playersData[index] = player;
|
||||||
|
Assert.IsTrue(JSONLoader.SaveUpdatedJsonToPersistentData(playersData, "player"));
|
||||||
|
Initalize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCurrentUserData()
|
||||||
|
{
|
||||||
|
int characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
||||||
|
if (characterId > -1)
|
||||||
|
{
|
||||||
|
player = playersData[characterId];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("유효하지 않은 캐릭터 정보 입니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,11 +43,12 @@ namespace TON
|
|||||||
{
|
{
|
||||||
Main.Singleton.Initialize();
|
Main.Singleton.Initialize();
|
||||||
|
|
||||||
List<PlayerData> playersData = PlayerDataManager.Singleton.playersData;
|
// List<PlayerData> playersData = PlayerDataManager.Singleton.playersData;
|
||||||
|
PlayerDataManager.Singleton.Initalize();
|
||||||
PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
||||||
PlayerDataManager.Singleton.SetCurrentUserData();
|
PlayerDataManager.Singleton.SetCurrentUserData();
|
||||||
// HeartDataManager.Singleton.();
|
// HeartDataManager.Singleton.();
|
||||||
List<SkillData> skillDatas = SkillDataManager.Singleton.skillDatas;
|
// List<SkillData> skillDatas = SkillDataManager.Singleton.skillDatas;
|
||||||
SkillDataManager.Singleton.Initalize();
|
SkillDataManager.Singleton.Initalize();
|
||||||
|
|
||||||
// TODO : Custom Order After System Load
|
// TODO : Custom Order After System Load
|
||||||
|
|||||||
@@ -103,14 +103,13 @@ namespace TON
|
|||||||
|
|
||||||
string persistentPath = GetPersistentPath(fileName);
|
string persistentPath = GetPersistentPath(fileName);
|
||||||
|
|
||||||
#if UNITY_ANDROID
|
|
||||||
// 📌 Step 1: persistentDataPath에 파일이 있는지 체크
|
// 📌 Step 1: persistentDataPath에 파일이 있는지 체크
|
||||||
// Android에서는 파일이 이미 존재하면 덮어쓰지 않도록 함
|
// Android에서는 파일이 이미 존재하면 덮어쓰지 않도록 함
|
||||||
if (File.Exists(persistentPath))
|
if (File.Exists(persistentPath))
|
||||||
{
|
{
|
||||||
Debug.Log($"⚠ {fileName}.json 파일이 이미 존재합니다. 덮어쓰지 않습니다. ({persistentPath})");
|
Debug.Log($"⚠ {fileName}.json 파일이 이미 존재합니다. 덮어쓰지 않습니다. ({persistentPath})");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
// 📌 Step 2: Resources에서 JSON 불러오기
|
// 📌 Step 2: Resources에서 JSON 불러오기
|
||||||
string path = DATA_PATH + fileName; // Resources 폴더 내 경로
|
string path = DATA_PATH + fileName; // Resources 폴더 내 경로
|
||||||
TextAsset jsonFile = Resources.Load<TextAsset>(path);
|
TextAsset jsonFile = Resources.Load<TextAsset>(path);
|
||||||
@@ -118,7 +117,7 @@ namespace TON
|
|||||||
if (jsonFile != null)
|
if (jsonFile != null)
|
||||||
{
|
{
|
||||||
File.WriteAllText(persistentPath, jsonFile.text);
|
File.WriteAllText(persistentPath, jsonFile.text);
|
||||||
Debug.Log($"✅ JSON 저장 완료 (처음 저장됨): {persistentPath}");
|
Debug.Log($"✅ JSON 저장 완료: {persistentPath}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace TON
|
|
||||||
{
|
|
||||||
public class PlayerDataManager : SingletonBase<PlayerDataManager>
|
|
||||||
{
|
|
||||||
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
|
||||||
public List<PlayerData> playersData { get; private set; }
|
|
||||||
|
|
||||||
public PlayerData player { get; private set; }
|
|
||||||
|
|
||||||
protected override void Awake()
|
|
||||||
{
|
|
||||||
base.Awake();
|
|
||||||
LoadPlayerData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadPlayerData()
|
|
||||||
{
|
|
||||||
playersData = JSONLoader.LoadFromResources<List<PlayerData>>("Player");
|
|
||||||
if (playersData == null)
|
|
||||||
{
|
|
||||||
playersData = new List<PlayerData>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCurrentUserData()
|
|
||||||
{
|
|
||||||
int characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
|
||||||
if (characterId > -1)
|
|
||||||
{
|
|
||||||
player = playersData[characterId];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogError("유효하지 않은 캐릭터 정보 입니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user