feat: 캐릭터 스펙 정보 서버에 저장하도록 변경
This commit is contained in:
@@ -58,8 +58,6 @@ namespace TON
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
// int playerIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||
PlayerDataManager.Singleton.SetCurrentUserData();
|
||||
playerData = PlayerDataManager.Singleton.player;
|
||||
|
||||
currentHP = maxHP = playerData.hp;
|
||||
@@ -257,7 +255,7 @@ namespace TON
|
||||
// 스킬 포인트가 부족하다면 스킬을 수행하지 못함
|
||||
if (currentSP < skillBase.SkillData.mpConsumption) return;
|
||||
|
||||
// 스킬 매니저에서 스킬을 쏠 수 있는지 여부를 판단
|
||||
// 스킬 매니저에서 스킬을 쏠 수 있는지 여부를 판단
|
||||
bool canExecute = SkillDataManager.Singleton.CanExecuteSkill(skillId);
|
||||
if (canExecute)
|
||||
{
|
||||
@@ -268,7 +266,7 @@ namespace TON
|
||||
// 스킬 애니메이터 실행
|
||||
animator.Play("Skill Attack");
|
||||
|
||||
// 스킬 매니저에 스킬 발사 요청
|
||||
// 스킬 매니저에 스킬 발사 요청
|
||||
SkillDataManager.Singleton.ExecuteSkill(skillId, firePoint, lastDirection);
|
||||
|
||||
// RecoverSP 가 이미 진행중인 경우 이중으로 코루틴을 실행하지 않도록 함함
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace TON
|
||||
|
||||
public void SetCurrentUserHeart()
|
||||
{
|
||||
characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
||||
characterId = 0;
|
||||
if (characterId > -1 && heartDatas.Count > 0)
|
||||
{
|
||||
currentHeartData = heartDatas[characterId];
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -8,7 +9,6 @@ namespace TON
|
||||
public class PlayerDataManager : SingletonBase<PlayerDataManager>
|
||||
{
|
||||
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
||||
public List<PlayerData> playersData { get; private set; }
|
||||
public PlayerData player { get; private set; }
|
||||
public int goldAmount { get; private set; }
|
||||
public int fishAmount { get; private set; }
|
||||
@@ -20,11 +20,13 @@ namespace TON
|
||||
[SerializeField] private int expVariable = 50; // 경험치 변수 (조정 가능)
|
||||
[SerializeField] private float attackGrowthFactor = 50f; // 공격력 성장 변수 (조정 가능)
|
||||
|
||||
private BackendPlayerDataManager playerDataManager;
|
||||
private BackendCashDataManager cashDataManager;
|
||||
private BackendItemDataManager itemDataManager;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
playerDataManager = new BackendPlayerDataManager();
|
||||
cashDataManager = new BackendCashDataManager();
|
||||
itemDataManager = new BackendItemDataManager();
|
||||
}
|
||||
@@ -38,17 +40,11 @@ namespace TON
|
||||
|
||||
private void LoadPlayerData()
|
||||
{
|
||||
if (playersData != null)
|
||||
// * 사용자 정보 서버에서 조회
|
||||
playerDataManager.LoadMyPlayerData(player =>
|
||||
{
|
||||
playersData.Clear();
|
||||
}
|
||||
|
||||
JSONLoader.SaveJsonToPersistentData("player");
|
||||
playersData = JSONLoader.LoadJsonFromPersistentData<List<PlayerData>>("player");
|
||||
if (playersData == null)
|
||||
{
|
||||
playersData = new List<PlayerData>();
|
||||
}
|
||||
SetPlayerData(player);
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadPlayerCashData()
|
||||
@@ -172,30 +168,25 @@ namespace TON
|
||||
|
||||
public void UpdatePlayerData()
|
||||
{
|
||||
Debug.Log($"player {player.level}: {player.attackPower}, {player.defensivePower}");
|
||||
int index = playersData.FindIndex(x => x.id == player.id);
|
||||
if (index > -1)
|
||||
// 캐릭터 데이터 서버 업데이트
|
||||
playerDataManager.UpdatePlayerData(player, isSuccess =>
|
||||
{
|
||||
playersData[index] = player;
|
||||
Assert.IsTrue(JSONLoader.SaveUpdatedJsonToPersistentData(playersData, "player"));
|
||||
Initalize();
|
||||
}
|
||||
if (isSuccess)
|
||||
{
|
||||
Initalize();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SetCurrentUserData()
|
||||
public void SetPlayerData(PlayerData playerData)
|
||||
{
|
||||
if (playersData.Count > 0)
|
||||
player = playerData;
|
||||
|
||||
// 사용자 정보가 있을때만 레벨업 필요 초기값 세팅
|
||||
if (playerData != null)
|
||||
{
|
||||
// 현재 플레이어 1개만 사용하므로 0번째 인덱스의 플레이어 데이터를 사용
|
||||
PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
||||
player = playersData[0];
|
||||
// 현재 플레이어의 정보를 세팅하고, 레벨업 필요 경험치 정보를 세팅
|
||||
requireLevelUpExp = GetRequiredExp(player.level);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("유효하지 않은 캐릭터 정보 입니다.");
|
||||
}
|
||||
}
|
||||
|
||||
// 플레이어가 사망했을때 호출
|
||||
@@ -209,5 +200,12 @@ namespace TON
|
||||
UIManager.Show<GameWinUI>(UIList.GameWinUI);
|
||||
}
|
||||
|
||||
public void CreateNewPlayer(PlayerData player, System.Action<bool> onComplete = null)
|
||||
{
|
||||
playerDataManager.CreateNewPlayer(player, isSuccess =>
|
||||
{
|
||||
onComplete?.Invoke(isSuccess);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,21 +8,14 @@ namespace TON
|
||||
{
|
||||
public static bool SpawnPlayerCharacter()
|
||||
{
|
||||
List<PlayerData> playerDatas = PlayerDataManager.Singleton.playersData;
|
||||
// 저장된 인덱스 가져오기
|
||||
int selectedIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||
// 인덱스가 범위를 벗어나지 않는지 확인
|
||||
if (selectedIndex < 0 || selectedIndex >= playerDatas.Count)
|
||||
{
|
||||
Debug.LogError($"Invalid player index: {selectedIndex}");
|
||||
return false;
|
||||
}
|
||||
string prefabName = playerDatas[selectedIndex].type == "b" ? "TON.Player_B" : "TON.Player_W";
|
||||
PlayerData playerData = PlayerDataManager.Singleton.player;
|
||||
|
||||
string prefabName = playerData.type == "b" ? "TON.Player_B" : "TON.Player_W";
|
||||
// Resources에서 프리팹 로드
|
||||
GameObject characterPrefab = Resources.Load<GameObject>($"Player/{prefabName}");
|
||||
if (characterPrefab == null)
|
||||
{
|
||||
Debug.LogError($"Failed to load character prefab: {playerDatas[selectedIndex].type}");
|
||||
Debug.LogError($"Failed to load character prefab: {playerData.type}");
|
||||
return false;
|
||||
}
|
||||
// TON.Player 오브젝트 찾기
|
||||
|
||||
Reference in New Issue
Block a user