first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OTGIntegrated.Inventory;
|
||||
using OTGIntegrated.Quests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OTGIntegrated.Save
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class GameSaveData
|
||||
{
|
||||
public Vector3 playerPosition;
|
||||
public float currentHealth;
|
||||
public float currentMana;
|
||||
public int level;
|
||||
public int currentExp;
|
||||
public int expToNextLevel;
|
||||
public int talentPoints;
|
||||
public List<string> learnedTalentIds = new List<string>();
|
||||
public List<QuestSaveEntry> quests = new List<QuestSaveEntry>();
|
||||
public List<InventorySlotSaveData> inventory = new List<InventorySlotSaveData>();
|
||||
public string currentWeaponId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88679d8b286ea9b998dee5138457108f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,152 @@
|
||||
using System.Collections.Generic;
|
||||
using OTGIntegrated.Core;
|
||||
using OTGIntegrated.Items;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OTGIntegrated.Save
|
||||
{
|
||||
public sealed class SaveSystem : MonoBehaviour
|
||||
{
|
||||
private const string SaveKey = "OTG_Lab08_IntegratedRPG_Save";
|
||||
|
||||
public List<ItemData> itemCatalog = new List<ItemData>();
|
||||
|
||||
private GameManager gameManager;
|
||||
|
||||
public void Initialize(GameManager manager)
|
||||
{
|
||||
gameManager = manager;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (gameManager == null)
|
||||
{
|
||||
gameManager = GameManager.Instance;
|
||||
}
|
||||
|
||||
if (gameManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameSaveData data = new GameSaveData();
|
||||
|
||||
if (gameManager.playerController != null)
|
||||
{
|
||||
data.playerPosition = gameManager.playerController.transform.position;
|
||||
}
|
||||
|
||||
if (gameManager.playerStats != null)
|
||||
{
|
||||
data.currentHealth = gameManager.playerStats.CurrentHealth;
|
||||
data.currentMana = gameManager.playerStats.CurrentMana;
|
||||
}
|
||||
|
||||
if (gameManager.levelSystem != null)
|
||||
{
|
||||
data.level = gameManager.levelSystem.level;
|
||||
data.currentExp = gameManager.levelSystem.currentExp;
|
||||
data.expToNextLevel = gameManager.levelSystem.expToNextLevel;
|
||||
}
|
||||
|
||||
if (gameManager.talentManager != null)
|
||||
{
|
||||
data.talentPoints = gameManager.talentManager.availableTalentPoints;
|
||||
data.learnedTalentIds = new List<string>(gameManager.talentManager.LearnedTalentIds);
|
||||
}
|
||||
|
||||
if (gameManager.questManager != null)
|
||||
{
|
||||
data.quests = gameManager.questManager.SaveData();
|
||||
}
|
||||
|
||||
if (gameManager.inventory != null)
|
||||
{
|
||||
data.inventory = gameManager.inventory.SaveData();
|
||||
}
|
||||
|
||||
if (gameManager.weaponManager != null)
|
||||
{
|
||||
data.currentWeaponId = gameManager.weaponManager.SaveData();
|
||||
}
|
||||
|
||||
PlayerPrefs.SetString(SaveKey, JsonUtility.ToJson(data));
|
||||
PlayerPrefs.Save();
|
||||
GameEvents.RaiseNotification("Прогресс сохранён");
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(SaveKey))
|
||||
{
|
||||
GameEvents.RaiseNotification("Сохранение не найдено");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameManager == null)
|
||||
{
|
||||
gameManager = GameManager.Instance;
|
||||
}
|
||||
|
||||
if (gameManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameSaveData data = JsonUtility.FromJson<GameSaveData>(PlayerPrefs.GetString(SaveKey));
|
||||
if (data == null)
|
||||
{
|
||||
GameEvents.RaiseNotification("Сохранение повреждено");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameManager.playerController != null)
|
||||
{
|
||||
CharacterController controller = gameManager.playerController.GetComponent<CharacterController>();
|
||||
if (controller != null) controller.enabled = false;
|
||||
gameManager.playerController.transform.position = data.playerPosition;
|
||||
if (controller != null) controller.enabled = true;
|
||||
}
|
||||
|
||||
if (gameManager.levelSystem != null)
|
||||
{
|
||||
gameManager.levelSystem.SetProgress(data.level, data.currentExp, data.expToNextLevel);
|
||||
}
|
||||
|
||||
if (gameManager.inventory != null)
|
||||
{
|
||||
gameManager.inventory.LoadData(data.inventory, itemCatalog);
|
||||
}
|
||||
|
||||
if (gameManager.talentManager != null)
|
||||
{
|
||||
gameManager.talentManager.LoadProgress(data.talentPoints, data.learnedTalentIds);
|
||||
}
|
||||
|
||||
if (gameManager.questManager != null)
|
||||
{
|
||||
gameManager.questManager.LoadData(data.quests);
|
||||
}
|
||||
|
||||
if (gameManager.weaponManager != null)
|
||||
{
|
||||
gameManager.weaponManager.LoadData(data.currentWeaponId);
|
||||
}
|
||||
|
||||
if (gameManager.playerStats != null)
|
||||
{
|
||||
gameManager.playerStats.SetRuntimeVitals(data.currentHealth, data.currentMana);
|
||||
}
|
||||
|
||||
GameEvents.RaiseNotification("Прогресс загружен");
|
||||
}
|
||||
|
||||
public void ResetSave()
|
||||
{
|
||||
PlayerPrefs.DeleteKey(SaveKey);
|
||||
PlayerPrefs.Save();
|
||||
GameEvents.RaiseNotification("Сохранение сброшено");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f13f1b81e87df7c2b1ff010eaf6752f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user