하트 데이터 시스템 추가
This commit is contained in:
11
Gameton-06/Assets/Gameton/Resources/GameData/heart.json
Normal file
11
Gameton-06/Assets/Gameton/Resources/GameData/heart.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"characterId": 0,
|
||||||
|
"currentHearts": 3,
|
||||||
|
"maxHearts": 3,
|
||||||
|
"heartRechargeTime": 600,
|
||||||
|
"lastHeartTime": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d14f7b3e0fd4d9f47adfc2efae717bc7
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -39,7 +39,7 @@ namespace TON
|
|||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
int playerIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
int playerIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||||
PlayerData playerData = PlayerDataManager.Singleton.players[playerIndex];
|
PlayerData playerData = PlayerDataManager.Singleton.playersData[playerIndex];
|
||||||
|
|
||||||
currentHP = maxHP = playerData.hp;
|
currentHP = maxHP = playerData.hp;
|
||||||
currentSP = maxSP = playerData.mp;
|
currentSP = maxSP = playerData.mp;
|
||||||
|
|||||||
8
Gameton-06/Assets/Gameton/Scripts/Character/Heart.meta
Normal file
8
Gameton-06/Assets/Gameton/Scripts/Character/Heart.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8fdf4902484ac024db58b4d3bdf63a71
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
public class HeartDataManager : SingletonBase<HeartDataManager>
|
||||||
|
{
|
||||||
|
public List<HeartData> heartDatas { get; private set; }
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private HeartData currentHeartData;
|
||||||
|
private int characterId;
|
||||||
|
|
||||||
|
protected override void Awake()
|
||||||
|
{
|
||||||
|
base.Awake();
|
||||||
|
LoadHeartData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadHeartData()
|
||||||
|
{
|
||||||
|
heartDatas = JSONLoader.LoadFromResources<List<HeartData>>("Heart");
|
||||||
|
if (heartDatas == null)
|
||||||
|
{
|
||||||
|
heartDatas = new List<HeartData>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void CreateNewHeartSystem(int characterId)
|
||||||
|
{
|
||||||
|
HeartData heartData = new HeartData(characterId);
|
||||||
|
heartDatas.Add(heartData);
|
||||||
|
JSONLoader.SaveToFile(heartDatas, "heart");
|
||||||
|
Debug.Log($"heartData test:: {heartData.currentHearts}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCurrentUserHeart()
|
||||||
|
{
|
||||||
|
characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
||||||
|
if (characterId > -1)
|
||||||
|
{
|
||||||
|
currentHeartData = heartDatas[characterId];
|
||||||
|
if (currentHeartData != null)
|
||||||
|
{
|
||||||
|
RechargeHearts();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("하트 정보 불러오기 중 오류 발생 ::: 초기값으로 재정의 합니다.");
|
||||||
|
CreateNewHeartSystem(characterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("유효하지 않은 캐릭터 정보입니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveHeartData()
|
||||||
|
{
|
||||||
|
heartDatas[characterId] = currentHeartData;
|
||||||
|
JSONLoader.SaveToFile(heartDatas, "heart");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RechargeHearts()
|
||||||
|
{
|
||||||
|
if (currentHeartData.currentHearts >= currentHeartData.maxHearts) return;
|
||||||
|
|
||||||
|
DateTime lastTime = DateTime.Parse(currentHeartData.lastHeartTime);
|
||||||
|
TimeSpan timePassed = DateTime.Now - lastTime;
|
||||||
|
int heartsToRecover = (int)(timePassed.TotalSeconds / currentHeartData.heartRechargeTime);
|
||||||
|
|
||||||
|
if (heartsToRecover > 0)
|
||||||
|
{
|
||||||
|
currentHeartData.currentHearts = Mathf.Min(currentHeartData.currentHearts + heartsToRecover, currentHeartData.maxHearts);
|
||||||
|
currentHeartData.lastHeartTime = DateTime.Now.ToString();
|
||||||
|
SaveHeartData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetCurrentHearts() => currentHeartData.currentHearts;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ca4edb88329beff4985e4e7e946cde59
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
public class HeartSystem : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da6da2289d3d066469e66212f110b960
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -9,7 +9,7 @@ namespace TON
|
|||||||
|
|
||||||
public static void SpawnPlayerCharacter()
|
public static void SpawnPlayerCharacter()
|
||||||
{
|
{
|
||||||
List<PlayerData> playerDatas = PlayerDataManager.Singleton.players;
|
List<PlayerData> playerDatas = PlayerDataManager.Singleton.playersData;
|
||||||
// 저장된 인덱스 가져오기
|
// 저장된 인덱스 가져오기
|
||||||
int selectedIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
int selectedIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace TON
|
|||||||
public class PlayerDataManager : SingletonBase<PlayerDataManager>
|
public class PlayerDataManager : SingletonBase<PlayerDataManager>
|
||||||
{
|
{
|
||||||
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
// 사용자가 생성해둔 플레이어 데이터를 싱글톤으로 전역 사용하기 위함
|
||||||
public List<PlayerData> players { get; private set; }
|
public List<PlayerData> playersData { get; private set; }
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
@@ -17,11 +17,12 @@ namespace TON
|
|||||||
|
|
||||||
private void LoadPlayerData()
|
private void LoadPlayerData()
|
||||||
{
|
{
|
||||||
players = JSONLoader.LoadFromResources<List<PlayerData>>("Player");
|
playersData = JSONLoader.LoadFromResources<List<PlayerData>>("Player");
|
||||||
if (players == null)
|
if (playersData == null)
|
||||||
{
|
{
|
||||||
players = new List<PlayerData>();
|
playersData = new List<PlayerData>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
Gameton-06/Assets/Gameton/Scripts/GameData/HeartData.cs
Normal file
37
Gameton-06/Assets/Gameton/Scripts/GameData/HeartData.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TON
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
public class HeartData
|
||||||
|
{
|
||||||
|
public int characterId;
|
||||||
|
public int currentHearts;
|
||||||
|
public int maxHearts = 3;
|
||||||
|
public int heartRechargeTime = 600; // 10분
|
||||||
|
public string lastHeartTime;
|
||||||
|
|
||||||
|
// 캐릭터 생성시 하트 데이터 생성자
|
||||||
|
public HeartData(int characterId)
|
||||||
|
{
|
||||||
|
this.characterId = characterId;
|
||||||
|
currentHearts = maxHearts;
|
||||||
|
}
|
||||||
|
// 하트 소모 시 변경할 객체 생성자자
|
||||||
|
public void UseHeart()
|
||||||
|
{
|
||||||
|
if (currentHearts > 0)
|
||||||
|
{
|
||||||
|
currentHearts--;
|
||||||
|
lastHeartTime = DateTime.UtcNow.ToString(); // 마지막 사용 시간 갱신
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("하트가 부족합니다!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Gameton-06/Assets/Gameton/Scripts/GameData/HeartData.cs.meta
Normal file
11
Gameton-06/Assets/Gameton/Scripts/GameData/HeartData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e006f5e55c10bc94b873cdacefc572de
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -10,6 +10,8 @@ namespace TON
|
|||||||
{
|
{
|
||||||
[SerializeField] private Button createButton; // Create 버튼 참조
|
[SerializeField] private Button createButton; // Create 버튼 참조
|
||||||
[SerializeField] private List<PlayerData> playerDatas;
|
[SerializeField] private List<PlayerData> playerDatas;
|
||||||
|
[SerializeField] private List<HeartData> heartDatas;
|
||||||
|
|
||||||
|
|
||||||
public GameObject characterCreateUI_Modal;
|
public GameObject characterCreateUI_Modal;
|
||||||
|
|
||||||
@@ -17,7 +19,9 @@ namespace TON
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
playerDatas = PlayerDataManager.Singleton.players;
|
playerDatas = PlayerDataManager.Singleton.playersData;
|
||||||
|
heartDatas = HeartDataManager.Singleton.heartDatas;
|
||||||
|
|
||||||
// 처음에는 버튼을 비활성화
|
// 처음에는 버튼을 비활성화
|
||||||
createButton.interactable = false;
|
createButton.interactable = false;
|
||||||
}
|
}
|
||||||
@@ -53,6 +57,10 @@ namespace TON
|
|||||||
playerDatas.Add(player);
|
playerDatas.Add(player);
|
||||||
JSONLoader.SaveToFile(playerDatas, "player");
|
JSONLoader.SaveToFile(playerDatas, "player");
|
||||||
|
|
||||||
|
// 하트 시스템을 생성한다
|
||||||
|
HeartDataManager.Singleton.CreateNewHeartSystem(playerDatas.Count);
|
||||||
|
HeartDataManager.Singleton.SetCurrentUserHeart();
|
||||||
|
|
||||||
// 씬 변경
|
// 씬 변경
|
||||||
UIManager.Hide<CharaterCreateUI>(UIList.CharaterCreateUI);
|
UIManager.Hide<CharaterCreateUI>(UIList.CharaterCreateUI);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace TON
|
|||||||
[SerializeField] private Button playButton; // Play 버튼 참조
|
[SerializeField] private Button playButton; // Play 버튼 참조
|
||||||
|
|
||||||
[SerializeField] private List<PlayerData> playerDatas;
|
[SerializeField] private List<PlayerData> playerDatas;
|
||||||
|
[SerializeField] private List<HeartData> heartDatas;
|
||||||
|
|
||||||
private int currentSelectCharacterIndex;
|
private int currentSelectCharacterIndex;
|
||||||
|
|
||||||
@@ -23,7 +24,8 @@ namespace TON
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
playerDatas = PlayerDataManager.Singleton.players;
|
playerDatas = PlayerDataManager.Singleton.playersData;
|
||||||
|
heartDatas = HeartDataManager.Singleton.heartDatas;
|
||||||
|
|
||||||
// 캐릭터를 선택한 이후에 버튼 활성화 할 수 있도록 초기 비활성화 적용
|
// 캐릭터를 선택한 이후에 버튼 활성화 할 수 있도록 초기 비활성화 적용
|
||||||
playButton.interactable = false;
|
playButton.interactable = false;
|
||||||
@@ -58,6 +60,7 @@ namespace TON
|
|||||||
public void OnClickPlayButton()
|
public void OnClickPlayButton()
|
||||||
{
|
{
|
||||||
PlayerPrefs.SetInt("SelectedPlayerIndex", currentSelectCharacterIndex);
|
PlayerPrefs.SetInt("SelectedPlayerIndex", currentSelectCharacterIndex);
|
||||||
|
HeartDataManager.Singleton.SetCurrentUserHeart();
|
||||||
|
|
||||||
UIManager.Hide<CharaterSelectUI>(UIList.CharaterSelectUI);
|
UIManager.Hide<CharaterSelectUI>(UIList.CharaterSelectUI);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace TON
|
|||||||
UIManager.Hide<TitleUI>(UIList.TitleUI);
|
UIManager.Hide<TitleUI>(UIList.TitleUI);
|
||||||
|
|
||||||
// 플레이어가 가지고 있는 캐릭터들의 데이터 불러옴
|
// 플레이어가 가지고 있는 캐릭터들의 데이터 불러옴
|
||||||
List<PlayerData> players = PlayerDataManager.Singleton.players;
|
List<PlayerData> players = PlayerDataManager.Singleton.playersData;
|
||||||
|
|
||||||
if (players.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user