feat: 게임 플레이어 로그인 후 재화 데이터 가져오도록 적용
This commit is contained in:
@@ -0,0 +1,119 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using BackEnd;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 뒤끝 서버 데이터 관리 담당 클래스
|
||||||
|
/// </summary>
|
||||||
|
public class BackendCashDataManager
|
||||||
|
{
|
||||||
|
// 테이블 이름 상수
|
||||||
|
private const string CASH_TABLE = "CASH_DATA";
|
||||||
|
|
||||||
|
|
||||||
|
// PlayerDataManager에서 재화 데이터 로드
|
||||||
|
public void LoadMyCashData(System.Action<CashData> onComplete)
|
||||||
|
{
|
||||||
|
CashData cashData = new CashData();
|
||||||
|
|
||||||
|
Backend.PlayerData.GetMyData(CASH_TABLE, callback =>
|
||||||
|
{
|
||||||
|
if (callback.IsSuccess() == false)
|
||||||
|
{
|
||||||
|
Debug.Log("데이터 읽기 중에 문제가 발생했습니다 : " + callback.ToString());
|
||||||
|
onComplete?.Invoke(cashData); // 에러 상황에서도 기본 데이터 반환
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 불러오기에는 성공했으나 데이터가 존재하지 않는 경우
|
||||||
|
if (callback.IsSuccess() && callback.FlattenRows().Count <= 0)
|
||||||
|
{
|
||||||
|
Debug.Log("데이터가 존재하지 않습니다");
|
||||||
|
InsertInitData(() =>
|
||||||
|
{
|
||||||
|
// 초기 데이터 삽입 후 다시 데이터를 불러옴
|
||||||
|
LoadDataAfterInsert(onComplete);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1개 이상 데이터를 불러온 경우
|
||||||
|
if (callback.FlattenRows().Count > 0)
|
||||||
|
{
|
||||||
|
cashData.fish = int.Parse(callback.FlattenRows()[0]["fish"].ToString());
|
||||||
|
cashData.gold = int.Parse(callback.FlattenRows()[0]["gold"].ToString());
|
||||||
|
onComplete?.Invoke(cashData); // 성공 시 데이터 반환
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 데이터 삽입 후 다시 불러오는 메소드
|
||||||
|
private void LoadDataAfterInsert(System.Action<CashData> onComplete)
|
||||||
|
{
|
||||||
|
Backend.PlayerData.GetMyData(CASH_TABLE, callback =>
|
||||||
|
{
|
||||||
|
CashData cashData = new CashData();
|
||||||
|
|
||||||
|
if (callback.IsSuccess() && callback.FlattenRows().Count > 0)
|
||||||
|
{
|
||||||
|
cashData.fish = int.Parse(callback.FlattenRows()[0]["fish"].ToString());
|
||||||
|
cashData.gold = int.Parse(callback.FlattenRows()[0]["gold"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
onComplete?.Invoke(cashData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 캐릭터 초기 생성 시 row 삽입
|
||||||
|
/// </summary>
|
||||||
|
public void InsertInitData(System.Action onComplete = null)
|
||||||
|
{
|
||||||
|
Param param = new Param();
|
||||||
|
param.Add("gold", 0);
|
||||||
|
param.Add("fish", 0);
|
||||||
|
|
||||||
|
Backend.PlayerData.InsertData(CASH_TABLE, param, callback =>
|
||||||
|
{
|
||||||
|
if (callback.IsSuccess())
|
||||||
|
{
|
||||||
|
Debug.Log("초기 데이터 삽입 성공");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("초기 데이터 삽입 실패: " + callback.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
onComplete?.Invoke();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateFishData(int fish, System.Action<CashData> onComplete = null)
|
||||||
|
{
|
||||||
|
Param param = new Param();
|
||||||
|
param.Add("fish", fish);
|
||||||
|
|
||||||
|
Backend.PlayerData.UpdateMyLatestData(CASH_TABLE, param, callback =>
|
||||||
|
{
|
||||||
|
CashData updatedData = new CashData { fish = fish };
|
||||||
|
onComplete?.Invoke(updatedData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateGoldData(int gold, System.Action<CashData> onComplete = null)
|
||||||
|
{
|
||||||
|
Param param = new Param();
|
||||||
|
param.Add("gold", gold);
|
||||||
|
|
||||||
|
Backend.PlayerData.UpdateMyLatestData(CASH_TABLE, param, callback =>
|
||||||
|
{
|
||||||
|
CashData updatedData = new CashData { gold = gold };
|
||||||
|
onComplete?.Invoke(updatedData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7af50547bf0c623478090ca1a2a45822
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -62,7 +62,8 @@ namespace TON
|
|||||||
if (isSuccess)
|
if (isSuccess)
|
||||||
{
|
{
|
||||||
Debug.Log("로그인 성공!");
|
Debug.Log("로그인 성공!");
|
||||||
// 게임 시작 로직은 Main.cs에서 처리
|
|
||||||
|
PlayerDataManager.Singleton.Initalize();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,21 +9,23 @@ namespace TON
|
|||||||
{
|
{
|
||||||
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
||||||
public List<PlayerData> playersData { get; private set; }
|
public List<PlayerData> playersData { get; private set; }
|
||||||
|
|
||||||
public PlayerData player { get; private set; }
|
public PlayerData player { get; private set; }
|
||||||
|
public int goldAmount { get; private set; }
|
||||||
[SerializeField]
|
public int fishAmount { get; private set; }
|
||||||
private int expVariable = 50; // 경험치 변수 (조정 가능)
|
|
||||||
[SerializeField]
|
|
||||||
private int attackGrowthFactor = 50; // 공격력 성장 변수 (조정 가능)
|
|
||||||
|
|
||||||
public int defensiveIntention { get; private set; } = 200; // 방어력 변수 (조정 가능)
|
public int defensiveIntention { get; private set; } = 200; // 방어력 변수 (조정 가능)
|
||||||
|
|
||||||
|
[SerializeField] private int expVariable = 50; // 경험치 변수 (조정 가능)
|
||||||
|
[SerializeField] private int attackGrowthFactor = 50; // 공격력 성장 변수 (조정 가능)
|
||||||
|
|
||||||
|
private BackendCashDataManager cashDataManager;
|
||||||
|
|
||||||
public void Initalize()
|
public void Initalize()
|
||||||
{
|
{
|
||||||
|
cashDataManager = new BackendCashDataManager();
|
||||||
|
|
||||||
LoadPlayerData();
|
LoadPlayerData();
|
||||||
// PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
LoadPlayerCashData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPlayerData()
|
private void LoadPlayerData()
|
||||||
@@ -41,6 +43,35 @@ namespace TON
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadPlayerCashData()
|
||||||
|
{
|
||||||
|
cashDataManager.LoadMyCashData(cashData =>
|
||||||
|
{
|
||||||
|
// 데이터 로드 완료 후 실행될 코드
|
||||||
|
goldAmount = cashData.gold;
|
||||||
|
fishAmount = cashData.fish;
|
||||||
|
Debug.Log($"로드된 골드: {cashData.gold}, 물고기: {cashData.fish}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddGold(int amount)
|
||||||
|
{
|
||||||
|
goldAmount += amount;
|
||||||
|
cashDataManager.UpdateGoldData(goldAmount, updatedData =>
|
||||||
|
{
|
||||||
|
// TODO: UI 업데이트 로직 적용
|
||||||
|
// UpdateUI();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void AddFish(int amount)
|
||||||
|
{
|
||||||
|
fishAmount += amount;
|
||||||
|
cashDataManager.UpdateFishData(fishAmount, updatedData =>
|
||||||
|
{
|
||||||
|
// TODO: UI 업데이트 로직 적용
|
||||||
|
// UpdateUI();
|
||||||
|
});
|
||||||
|
}
|
||||||
// 공격력과 방어력 업데이트
|
// 공격력과 방어력 업데이트
|
||||||
private void UpdateStats(int currentLevel)
|
private void UpdateStats(int currentLevel)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,9 +28,6 @@ namespace TON
|
|||||||
BackendManager.Singleton.Initalize();
|
BackendManager.Singleton.Initalize();
|
||||||
UIManager.Singleton.Initalize();
|
UIManager.Singleton.Initalize();
|
||||||
|
|
||||||
// TODO : GameDataModel.Singleton.Initalize();
|
|
||||||
PlayerDataManager.Singleton.Initalize();
|
|
||||||
|
|
||||||
isIniaialized = true;
|
isIniaialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19
Gameton-06/Assets/Gameton/Scripts/GameData/CashData.cs
Normal file
19
Gameton-06/Assets/Gameton/Scripts/GameData/CashData.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
public class CashData
|
||||||
|
{
|
||||||
|
public int gold;
|
||||||
|
public int fish;
|
||||||
|
|
||||||
|
public CashData()
|
||||||
|
{
|
||||||
|
gold = 0;
|
||||||
|
fish = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Gameton-06/Assets/Gameton/Scripts/GameData/CashData.cs.meta
Normal file
11
Gameton-06/Assets/Gameton/Scripts/GameData/CashData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c5faca4862c71c94ab30d84b1ec35872
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
|
|
||||||
namespace TON
|
namespace TON
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,18 @@ namespace TON
|
|||||||
// 상점 : 골드/생선
|
// 상점 : 골드/생선
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
// Scene activeScene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();
|
SetCashAmount();
|
||||||
|
SetObjectActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetCashAmount()
|
||||||
|
{
|
||||||
|
goldObject.GetComponentInChildren<TextMeshProUGUI>().text = $"{PlayerDataManager.Singleton.goldAmount}";
|
||||||
|
fishObject.GetComponentInChildren<TextMeshProUGUI>().text = $"{PlayerDataManager.Singleton.fishAmount}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetObjectActive()
|
||||||
|
{
|
||||||
SceneType activeScene = Main.Singleton.currentSceneType;
|
SceneType activeScene = Main.Singleton.currentSceneType;
|
||||||
|
|
||||||
if (activeScene == SceneType.Lobby)
|
if (activeScene == SceneType.Lobby)
|
||||||
@@ -42,7 +53,6 @@ namespace TON
|
|||||||
settingObject.SetActive(false);
|
settingObject.SetActive(false);
|
||||||
parseObject.SetActive(false);
|
parseObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClickSettingButton()
|
public void OnClickSettingButton()
|
||||||
|
|||||||
Reference in New Issue
Block a user