하트 데이터 시스템 추가
This commit is contained in:
@@ -39,7 +39,7 @@ namespace TON
|
||||
public void Initialize()
|
||||
{
|
||||
int playerIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||
PlayerData playerData = PlayerDataManager.Singleton.players[playerIndex];
|
||||
PlayerData playerData = PlayerDataManager.Singleton.playersData[playerIndex];
|
||||
|
||||
currentHP = maxHP = playerData.hp;
|
||||
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()
|
||||
{
|
||||
List<PlayerData> playerDatas = PlayerDataManager.Singleton.players;
|
||||
List<PlayerData> playerDatas = PlayerDataManager.Singleton.playersData;
|
||||
// 저장된 인덱스 가져오기
|
||||
int selectedIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user