修复保存的bug | 提升性能 | 追加提示
This commit is contained in:
parent
21f27e76e4
commit
b7302cca65
23
Assets/DebugOpen.cs
Normal file
23
Assets/DebugOpen.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class DebugOpen : MonoBehaviour {
|
||||||
|
|
||||||
|
public Debugger debugger;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
debugger.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
//按住上方向键+三角建,再按下X键
|
||||||
|
if (Input.GetKey(KeyCode.JoystickButton3) && Input.GetKey(KeyCode.JoystickButton8))
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.JoystickButton0))
|
||||||
|
{
|
||||||
|
debugger.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/DebugOpen.cs.meta
Normal file
11
Assets/DebugOpen.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f4bf72723ac1f6d4b857a876100cd015
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Binary file not shown.
@ -6,50 +6,64 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
public class HomeCanvasController : MonoBehaviour
|
public class HomeCanvasController : MonoBehaviour
|
||||||
{
|
{
|
||||||
private Button newGameButton;
|
private Button newGameButton;
|
||||||
private Button loadGameButton;
|
private Button loadGameButton;
|
||||||
private Button exitGameButton;
|
private Button exitGameButton;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
newGameButton = transform.Find("Panel").Find("NewGameButton").GetComponent<Button>();
|
newGameButton = transform.Find("Panel").Find("NewGameButton").GetComponent<Button>();
|
||||||
loadGameButton = transform.Find("Panel").Find("LoadGameButton").GetComponent<Button>();
|
loadGameButton = transform.Find("Panel").Find("LoadGameButton").GetComponent<Button>();
|
||||||
exitGameButton = transform.Find("Panel").Find("ExitGameButton").GetComponent<Button>();
|
exitGameButton = transform.Find("Panel").Find("ExitGameButton").GetComponent<Button>();
|
||||||
|
|
||||||
newGameButton.onClick.AddListener(() => { NewGameEvent(); });
|
newGameButton.onClick.AddListener(() => { NewGameEvent(); });
|
||||||
loadGameButton.onClick.AddListener(() => { LoadGameEvent(); });
|
loadGameButton.onClick.AddListener(() => { LoadGameEvent(); });
|
||||||
exitGameButton.onClick.AddListener(ExitGameEvent);
|
exitGameButton.onClick.AddListener(ExitGameEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新游戏
|
/// 新游戏
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void NewGameEvent()
|
public void NewGameEvent()
|
||||||
{
|
{
|
||||||
// 设置标识符
|
// 设置标识符
|
||||||
PlayerPrefs.SetInt("NewGame", 1);
|
PlayerPrefs.SetInt("NewGame", 1);
|
||||||
// 加载场景
|
// 加载场景
|
||||||
SceneManager.LoadScene("Level");
|
SceneManager.LoadScene("Level");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载游戏
|
/// 加载游戏
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadGameEvent()
|
public void LoadGameEvent()
|
||||||
{
|
{
|
||||||
// 加载游戏存档
|
// 加载游戏存档
|
||||||
if (ResourceManager.Instance.GetGameArchiveStatus()) SceneManager.LoadScene("Level");
|
if (ResourceManager.Instance.GetGameArchiveStatus())
|
||||||
}
|
{
|
||||||
|
SceneManager.LoadScene("Level");
|
||||||
|
// UI 提示
|
||||||
|
GameManager.Instance.UIManager.ShowInfo("已读档!");
|
||||||
|
// 音频播放
|
||||||
|
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "Save");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// UI 提示
|
||||||
|
GameManager.Instance.UIManager.ShowInfo("未发现存档!");
|
||||||
|
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "No");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
}
|
||||||
/// 退出游戏
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public void ExitGameEvent()
|
/// 退出游戏
|
||||||
{
|
/// </summary>
|
||||||
|
public void ExitGameEvent()
|
||||||
|
{
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
UnityEditor.EditorApplication.isPlaying = false;
|
UnityEditor.EditorApplication.isPlaying = false;
|
||||||
#else
|
#else
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
//using System.IO;
|
//using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -7,10 +9,10 @@ using UnityEngine;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public enum EResourceType
|
public enum EResourceType
|
||||||
{
|
{
|
||||||
Environment,
|
Environment,
|
||||||
Item,
|
Item,
|
||||||
Actor,
|
Actor,
|
||||||
Enemy,
|
Enemy,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -19,10 +21,10 @@ public enum EResourceType
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class MapResourceInfo
|
public class MapResourceInfo
|
||||||
{
|
{
|
||||||
public int Level;
|
public int Level;
|
||||||
public EResourceType Type;
|
public EResourceType Type;
|
||||||
public int ID;
|
public int ID;
|
||||||
public Vector2 Point;
|
public Vector2 Point;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,12 +33,12 @@ public class MapResourceInfo
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class ResourceInfo
|
public class ResourceInfo
|
||||||
{
|
{
|
||||||
public EResourceType Type;
|
public EResourceType Type;
|
||||||
public int ID;
|
public int ID;
|
||||||
public string Name;
|
public string Name;
|
||||||
public string Info;
|
public string Info;
|
||||||
public string Path;
|
public string Path;
|
||||||
public string IconPath;
|
public string IconPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -45,12 +47,12 @@ public class ResourceInfo
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class GameInfo
|
public class GameInfo
|
||||||
{
|
{
|
||||||
public string MapArchive;
|
public string MapArchive;
|
||||||
public string PlayerInfo;
|
public string PlayerInfo;
|
||||||
public int LevelInfo;
|
public int LevelInfo;
|
||||||
public int MaxLevelInfo;
|
public int MaxLevelInfo;
|
||||||
public string BackpackInfo;
|
public string BackpackInfo;
|
||||||
public string PlotInfo;
|
public string PlotInfo;
|
||||||
//每个层商店购买次数
|
//每个层商店购买次数
|
||||||
public int StoreBuyNum_F4 = 0;
|
public int StoreBuyNum_F4 = 0;
|
||||||
public int StoreBuyNum_F12 = 0;
|
public int StoreBuyNum_F12 = 0;
|
||||||
@ -60,187 +62,203 @@ public class GameInfo
|
|||||||
|
|
||||||
public class ResourceManager : Singleton<ResourceManager>
|
public class ResourceManager : Singleton<ResourceManager>
|
||||||
{
|
{
|
||||||
//private string _mapInfoPath = Application.dataPath + "/Settings/地图信息.txt";
|
//private string _mapInfoPath = Application.dataPath + "/Settings/地图信息.txt";
|
||||||
//private string _propertyInfoPath = Application.dataPath + "/Settings/属性列表.txt";
|
//private string _propertyInfoPath = Application.dataPath + "/Settings/属性列表.txt";
|
||||||
|
|
||||||
private List<MapResourceInfo> _mapResourceInfoList = new List<MapResourceInfo>();
|
private List<MapResourceInfo> _mapResourceInfoList = new List<MapResourceInfo>();
|
||||||
private Dictionary<EResourceType, Dictionary<int, ResourceInfo>> _resourceInfoDic = new Dictionary<EResourceType, Dictionary<int, ResourceInfo>>();
|
private Dictionary<EResourceType, Dictionary<int, ResourceInfo>> _resourceInfoDic = new Dictionary<EResourceType, Dictionary<int, ResourceInfo>>();
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
string SaveDataDirPath = Application.persistentDataPath;
|
||||||
|
#elif UNITY_PSP2
|
||||||
|
string SaveDataDirPath = "ux0:data/MoTaForPSVita";
|
||||||
|
#endif
|
||||||
|
string SaveDataFilePath => SaveDataDirPath + "/GameSaveData.json";
|
||||||
|
|
||||||
public ResourceManager()
|
public ResourceManager()
|
||||||
{
|
{
|
||||||
LoadPropertyFile();
|
LoadPropertyFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 绑定事件
|
/// 绑定事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void BindEvent()
|
public void BindEvent()
|
||||||
{
|
{
|
||||||
GameManager.Instance.EventManager.OnSaveGameInput += SaveGameInfoEvent;
|
GameManager.Instance.EventManager.OnSaveGameInput += SaveGameInfoEvent;
|
||||||
GameManager.Instance.EventManager.OnLevelChanged += LoadLevelEvent;
|
GameManager.Instance.EventManager.OnLevelChanged += LoadLevelEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新建游戏信息
|
/// 新建游戏信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void NewGameInfo()
|
public void NewGameInfo()
|
||||||
{
|
{
|
||||||
//// 打开 txt 设置地图信息
|
//// 打开 txt 设置地图信息
|
||||||
//using (FileStream fs = new FileStream(_mapInfoPath, FileMode.Open))
|
//using (FileStream fs = new FileStream(_mapInfoPath, FileMode.Open))
|
||||||
//{
|
//{
|
||||||
// // 创建 txt 字节长度的 byte 数组
|
// // 创建 txt 字节长度的 byte 数组
|
||||||
// byte[] bytes = new byte[fs.Length];
|
// byte[] bytes = new byte[fs.Length];
|
||||||
// // 读取 txt 字节到 byte 数组
|
// // 读取 txt 字节到 byte 数组
|
||||||
// fs.Read(bytes, 0, bytes.Length);
|
// fs.Read(bytes, 0, bytes.Length);
|
||||||
// // 用 utf-8 解码
|
// // 用 utf-8 解码
|
||||||
// string mapStr = System.Text.Encoding.UTF8.GetString(bytes);
|
// string mapStr = System.Text.Encoding.UTF8.GetString(bytes);
|
||||||
// // json 转对象 list
|
// // json 转对象 list
|
||||||
// _mapResourceInfoList = JsonUtility.FromJson<Serialization<MapResourceInfo>>(mapStr).ToList();
|
// _mapResourceInfoList = JsonUtility.FromJson<Serialization<MapResourceInfo>>(mapStr).ToList();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//Debug.Log("mapinfo" + Resources.Load<TextAsset>("cfg/mapinfo").text);
|
//Debug.Log("mapinfo" + Resources.Load<TextAsset>("cfg/mapinfo").text);
|
||||||
_mapResourceInfoList = JsonUtility.FromJson<Serialization<MapResourceInfo>>(Resources.Load<TextAsset>("cfg/mapinfo").text).ToList();
|
_mapResourceInfoList = JsonUtility.FromJson<Serialization<MapResourceInfo>>(Resources.Load<TextAsset>("cfg/mapinfo").text).ToList();
|
||||||
|
|
||||||
// 初始化剧情信息
|
|
||||||
GameManager.Instance.PlotManager.Init();
|
|
||||||
// 设置层数信息
|
|
||||||
GameManager.Instance.LevelManager.Level = 1;
|
|
||||||
// 设置玩家信息
|
|
||||||
GameManager.Instance.PlayerManager.PlayerInfo = new PlayerInfo
|
|
||||||
{
|
|
||||||
Health = 1000,
|
|
||||||
Attack = 100,
|
|
||||||
Defence = 100,
|
|
||||||
Gold = 0,
|
|
||||||
WeaponID = 32,
|
|
||||||
ArmorID = 33,
|
|
||||||
NotepadInfo = "",
|
|
||||||
};
|
|
||||||
// 删除标识符
|
|
||||||
PlayerPrefs.DeleteKey("NewGame");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
// 初始化剧情信息
|
||||||
/// 加载资源
|
GameManager.Instance.PlotManager.Init();
|
||||||
/// </summary>
|
// 设置层数信息
|
||||||
/// <param name="type">资源类型</param>
|
GameManager.Instance.LevelManager.Level = 1;
|
||||||
/// <param name="id">资源 id</param>
|
// 设置玩家信息
|
||||||
/// <returns>资源物体</returns>
|
GameManager.Instance.PlayerManager.PlayerInfo = new PlayerInfo
|
||||||
public GameObject LoadResource(EResourceType type, int id)
|
{
|
||||||
{
|
Health = 1000,
|
||||||
// 获取资源属性
|
Attack = 100,
|
||||||
ResourceInfo tempInfo = _resourceInfoDic[type][id];
|
Defence = 100,
|
||||||
if (null == tempInfo) return null;
|
Gold = 0,
|
||||||
//Debug.Log("加载资源:"+ tempInfo.Path);
|
WeaponID = 32,
|
||||||
// 创建资源并返回
|
ArmorID = 33,
|
||||||
return Object.Instantiate(Resources.Load<GameObject>(tempInfo.Path), Vector3.zero, Quaternion.identity);
|
NotepadInfo = "",
|
||||||
}
|
};
|
||||||
|
// 删除标识符
|
||||||
|
PlayerPrefs.DeleteKey("NewGame");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源信息
|
/// 加载资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">资源类型</param>
|
/// <param name="type">资源类型</param>
|
||||||
/// <param name="id">资源 id</param>
|
/// <param name="id">资源 id</param>
|
||||||
/// <returns>资源信息</returns>
|
/// <returns>资源物体</returns>
|
||||||
public ResourceInfo GetResourceInfo(EResourceType type, int id)
|
public GameObject LoadResource(EResourceType type, int id)
|
||||||
{
|
{
|
||||||
if (!_resourceInfoDic.ContainsKey(type)) return null;
|
// 获取资源属性
|
||||||
if (!_resourceInfoDic[type].ContainsKey(id)) return null;
|
ResourceInfo tempInfo = _resourceInfoDic[type][id];
|
||||||
return _resourceInfoDic[type][id];
|
if (null == tempInfo) return null;
|
||||||
}
|
//Debug.Log("加载资源:"+ tempInfo.Path);
|
||||||
|
// 创建资源并返回
|
||||||
|
return Object.Instantiate(Resources.Load<GameObject>(tempInfo.Path), Vector3.zero, Quaternion.identity);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取新游戏状态
|
/// 获取资源信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="type">资源类型</param>
|
||||||
public bool GetNewGameStatus()
|
/// <param name="id">资源 id</param>
|
||||||
{
|
/// <returns>资源信息</returns>
|
||||||
return PlayerPrefs.HasKey("NewGame");
|
public ResourceInfo GetResourceInfo(EResourceType type, int id)
|
||||||
}
|
{
|
||||||
|
if (!_resourceInfoDic.ContainsKey(type)) return null;
|
||||||
|
if (!_resourceInfoDic[type].ContainsKey(id)) return null;
|
||||||
|
return _resourceInfoDic[type][id];
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取游戏存档状态
|
/// 获取新游戏状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>是否有存档</returns>
|
/// <returns></returns>
|
||||||
public bool GetGameArchiveStatus()
|
public bool GetNewGameStatus()
|
||||||
{
|
{
|
||||||
return PlayerPrefs.HasKey("GameInfo");
|
return PlayerPrefs.HasKey("NewGame");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载游戏存档
|
/// 获取游戏存档状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>是否能够加载</returns>
|
/// <returns>是否有存档</returns>
|
||||||
public void LoadGameArchive()
|
public bool GetGameArchiveStatus()
|
||||||
{
|
{
|
||||||
// 判断存档是否存在
|
#if UNITY_EDITOR_WIN
|
||||||
if (!PlayerPrefs.HasKey("GameInfo")) return;
|
return PlayerPrefs.HasKey("GameInfo");
|
||||||
// json 对象转 GameInfo
|
#else
|
||||||
GameInfo gameInfo = JsonUtility.FromJson<GameInfo>(PlayerPrefs.GetString("GameInfo"));
|
return System.IO.File.Exists(SaveDataFilePath);
|
||||||
// 加载存档
|
#endif
|
||||||
_mapResourceInfoList = JsonUtility.FromJson<Serialization<MapResourceInfo>>(gameInfo.MapArchive).ToList();
|
|
||||||
// 加载背包信息
|
|
||||||
GameManager.Instance.BackpackManager.BackpackDictionary = JsonUtility.FromJson<Serialization<int, ItemInfo>>(gameInfo.BackpackInfo).ToDictionary();
|
|
||||||
// 加载玩家信息
|
|
||||||
GameManager.Instance.PlayerManager.PlayerInfo = JsonUtility.FromJson<PlayerInfo>(gameInfo.PlayerInfo);
|
|
||||||
// 加载剧情信息
|
|
||||||
GameManager.Instance.PlotManager.PlotDictionary = JsonUtility.FromJson<Serialization<int, int>>(gameInfo.PlotInfo).ToDictionary();
|
|
||||||
// 加载层数信息
|
|
||||||
GameManager.Instance.LevelManager.Level = gameInfo.LevelInfo;
|
|
||||||
GameManager.Instance.LevelManager.MaxLevel = gameInfo.MaxLevelInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
}
|
||||||
/// 移动玩家位置
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="level">关卡</param>
|
|
||||||
/// <param name="point">位置</param>
|
|
||||||
public void MovePlayerPointForLevel(int level, Vector2 point)
|
|
||||||
{
|
|
||||||
_mapResourceInfoList.ForEach(mri =>
|
|
||||||
{
|
|
||||||
if (mri.Level == level && mri.Type == EResourceType.Actor && mri.ID == 1)
|
|
||||||
{
|
|
||||||
mri.Point = point;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建资源到关卡
|
/// 加载游戏存档
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="level"></param>
|
/// <returns>是否能够加载</returns>
|
||||||
/// <param name="type"></param>
|
public void LoadGameArchive()
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <param name="point"></param>
|
// 判断存档是否存在
|
||||||
public void MakeResourceForLevel(int level, EResourceType type, int id, Vector2 point)
|
#if UNITY_EDITOR_WIN
|
||||||
{
|
if (!PlayerPrefs.HasKey("GameInfo")) return;
|
||||||
_mapResourceInfoList.Add(new MapResourceInfo()
|
// json 对象转 GameInfo
|
||||||
{
|
GameInfo gameInfo = JsonUtility.FromJson<GameInfo>(PlayerPrefs.GetString("GameInfo"));
|
||||||
Level = level,
|
#else
|
||||||
Type = type,
|
if (!System.IO.File.Exists(SaveDataFilePath)) return;
|
||||||
ID = id,
|
GameInfo gameInfo = JsonUtility.FromJson<GameInfo>(System.IO.File.ReadAllText(SaveDataFilePath));
|
||||||
Point = point,
|
#endif
|
||||||
});
|
// 加载存档
|
||||||
}
|
_mapResourceInfoList = JsonUtility.FromJson<Serialization<MapResourceInfo>>(gameInfo.MapArchive).ToList();
|
||||||
|
// 加载背包信息
|
||||||
|
GameManager.Instance.BackpackManager.BackpackDictionary = JsonUtility.FromJson<Serialization<int, ItemInfo>>(gameInfo.BackpackInfo).ToDictionary();
|
||||||
|
// 加载玩家信息
|
||||||
|
GameManager.Instance.PlayerManager.PlayerInfo = JsonUtility.FromJson<PlayerInfo>(gameInfo.PlayerInfo);
|
||||||
|
// 加载剧情信息
|
||||||
|
GameManager.Instance.PlotManager.PlotDictionary = JsonUtility.FromJson<Serialization<int, int>>(gameInfo.PlotInfo).ToDictionary();
|
||||||
|
// 加载层数信息
|
||||||
|
GameManager.Instance.LevelManager.Level = gameInfo.LevelInfo;
|
||||||
|
GameManager.Instance.LevelManager.MaxLevel = gameInfo.MaxLevelInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载属性文件
|
/// 移动玩家位置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void LoadPropertyFile()
|
/// <param name="level">关卡</param>
|
||||||
{
|
/// <param name="point">位置</param>
|
||||||
|
public void MovePlayerPointForLevel(int level, Vector2 point)
|
||||||
|
{
|
||||||
|
_mapResourceInfoList.ForEach(mri =>
|
||||||
|
{
|
||||||
|
if (mri.Level == level && mri.Type == EResourceType.Actor && mri.ID == 1)
|
||||||
|
{
|
||||||
|
mri.Point = point;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Debug.Log("attinfo" + Resources.Load<TextAsset>("cfg/attinfo").text);
|
/// <summary>
|
||||||
List<ResourceInfo> tempList = JsonUtility.FromJson<Serialization<ResourceInfo>>(Resources.Load<TextAsset>("cfg/attinfo").text).ToList();
|
/// 创建资源到关卡
|
||||||
// 将 list 加入字典
|
/// </summary>
|
||||||
tempList.ForEach(ri =>
|
/// <param name="level"></param>
|
||||||
{
|
/// <param name="type"></param>
|
||||||
if (!_resourceInfoDic.ContainsKey(ri.Type)) _resourceInfoDic.Add(ri.Type, new Dictionary<int, ResourceInfo>());
|
/// <param name="id"></param>
|
||||||
if (!_resourceInfoDic[ri.Type].ContainsKey(ri.ID)) _resourceInfoDic[ri.Type].Add(ri.ID, ri);
|
/// <param name="point"></param>
|
||||||
});
|
public void MakeResourceForLevel(int level, EResourceType type, int id, Vector2 point)
|
||||||
|
{
|
||||||
|
_mapResourceInfoList.Add(new MapResourceInfo()
|
||||||
|
{
|
||||||
|
Level = level,
|
||||||
|
Type = type,
|
||||||
|
ID = id,
|
||||||
|
Point = point,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/*// 判断属性文件是否存在
|
/// <summary>
|
||||||
|
/// 加载属性文件
|
||||||
|
/// </summary>
|
||||||
|
private void LoadPropertyFile()
|
||||||
|
{
|
||||||
|
|
||||||
|
//Debug.Log("attinfo" + Resources.Load<TextAsset>("cfg/attinfo").text);
|
||||||
|
List<ResourceInfo> tempList = JsonUtility.FromJson<Serialization<ResourceInfo>>(Resources.Load<TextAsset>("cfg/attinfo").text).ToList();
|
||||||
|
// 将 list 加入字典
|
||||||
|
tempList.ForEach(ri =>
|
||||||
|
{
|
||||||
|
if (!_resourceInfoDic.ContainsKey(ri.Type)) _resourceInfoDic.Add(ri.Type, new Dictionary<int, ResourceInfo>());
|
||||||
|
if (!_resourceInfoDic[ri.Type].ContainsKey(ri.ID)) _resourceInfoDic[ri.Type].Add(ri.ID, ri);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*// 判断属性文件是否存在
|
||||||
if (!File.Exists(_propertyInfoPath)) return;
|
if (!File.Exists(_propertyInfoPath)) return;
|
||||||
// 打开 txt
|
// 打开 txt
|
||||||
using (FileStream fs = new FileStream(_propertyInfoPath, FileMode.Open))
|
using (FileStream fs = new FileStream(_propertyInfoPath, FileMode.Open))
|
||||||
@ -260,115 +278,143 @@ public class ResourceManager : Singleton<ResourceManager>
|
|||||||
if (!_resourceInfoDic[ri.Type].ContainsKey(ri.ID)) _resourceInfoDic[ri.Type].Add(ri.ID, ri);
|
if (!_resourceInfoDic[ri.Type].ContainsKey(ri.ID)) _resourceInfoDic[ri.Type].Add(ri.ID, ri);
|
||||||
});
|
});
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载关卡事件
|
/// 加载关卡事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="oldIndex">旧关卡序号</param>
|
/// <param name="oldIndex">旧关卡序号</param>
|
||||||
/// <param name="newIndex">新关卡序号</param>
|
/// <param name="newIndex">新关卡序号</param>
|
||||||
private void LoadLevelEvent(int oldIndex, int newIndex)
|
private void LoadLevelEvent(int oldIndex, int newIndex)
|
||||||
{
|
{
|
||||||
// 判断地图信息是否存在
|
// 判断地图信息是否存在
|
||||||
if (_mapResourceInfoList.Count == 0) return;
|
if (_mapResourceInfoList.Count == 0) return;
|
||||||
// 获取当前关卡在用资源
|
// 获取当前关卡在用资源
|
||||||
for (int i = _mapResourceInfoList.Count - 1; i >= 0; i--)
|
for (int i = _mapResourceInfoList.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (_mapResourceInfoList[i].Level == oldIndex) _mapResourceInfoList.RemoveAt(i);
|
if (_mapResourceInfoList[i].Level == oldIndex) _mapResourceInfoList.RemoveAt(i);
|
||||||
}
|
}
|
||||||
// 更新到资源信息中
|
// 更新到资源信息中
|
||||||
GameManager.Instance.PoolManager.UseList.ForEach(u =>
|
GameManager.Instance.PoolManager.UseList.ForEach(u =>
|
||||||
{
|
{
|
||||||
EResourceType type = EResourceType.Actor;
|
EResourceType type = EResourceType.Actor;
|
||||||
switch (u.tag)
|
switch (u.tag)
|
||||||
{
|
{
|
||||||
case "Item":
|
case "Item":
|
||||||
type = EResourceType.Item;
|
type = EResourceType.Item;
|
||||||
break;
|
break;
|
||||||
case "Enemy":
|
case "Enemy":
|
||||||
type = EResourceType.Enemy;
|
type = EResourceType.Enemy;
|
||||||
break;
|
break;
|
||||||
case "Environment":
|
case "Environment":
|
||||||
type = EResourceType.Environment;
|
type = EResourceType.Environment;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_mapResourceInfoList.Add(new MapResourceInfo
|
_mapResourceInfoList.Add(new MapResourceInfo
|
||||||
{
|
{
|
||||||
Level = oldIndex,
|
Level = oldIndex,
|
||||||
Type = type,
|
Type = type,
|
||||||
ID = u.GetComponent<ResourceController>().ID,
|
ID = u.GetComponent<ResourceController>().ID,
|
||||||
Point = u.transform.position,
|
Point = u.transform.position,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 回收资源
|
// 回收资源
|
||||||
GameManager.Instance.PoolManager.RecycleResource();
|
GameManager.Instance.PoolManager.RecycleResource();
|
||||||
// 加载资源
|
// 加载资源
|
||||||
foreach (var info in _mapResourceInfoList)
|
foreach (var info in _mapResourceInfoList)
|
||||||
{
|
{
|
||||||
// 判断关卡一致
|
// 判断关卡一致
|
||||||
if (info.Level == newIndex)
|
if (info.Level == newIndex)
|
||||||
{
|
{
|
||||||
GameObject tempObj = GameManager.Instance.PoolManager.GetResourceInFreePool(info.Type, info.ID);
|
GameObject tempObj = GameManager.Instance.PoolManager.GetResourceInFreePool(info.Type, info.ID);
|
||||||
tempObj.transform.position = info.Point;
|
tempObj.transform.position = info.Point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 加载完毕执行事件
|
// 加载完毕执行事件
|
||||||
GameManager.Instance.EventManager.OnResourceLoaded?.Invoke();
|
GameManager.Instance.EventManager.OnResourceLoaded?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存游戏信息事件
|
/// 保存游戏信息事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void SaveGameInfoEvent()
|
private void SaveGameInfoEvent()
|
||||||
{
|
{
|
||||||
// 删除当前关卡资源
|
// 删除当前关卡资源
|
||||||
for (int i = _mapResourceInfoList.Count - 1; i >= 0; i--)
|
for (int i = _mapResourceInfoList.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (_mapResourceInfoList[i].Level == GameManager.Instance.LevelManager.Level) _mapResourceInfoList.RemoveAt(i);
|
if (_mapResourceInfoList[i].Level == GameManager.Instance.LevelManager.Level) _mapResourceInfoList.RemoveAt(i);
|
||||||
}
|
}
|
||||||
// 将在用对象池资源加入资源信息中
|
// 将在用对象池资源加入资源信息中
|
||||||
GameManager.Instance.PoolManager.UseList.ForEach(u =>
|
GameManager.Instance.PoolManager.UseList.ForEach(u =>
|
||||||
{
|
{
|
||||||
EResourceType type = EResourceType.Actor;
|
EResourceType type = EResourceType.Actor;
|
||||||
switch (u.tag)
|
switch (u.tag)
|
||||||
{
|
{
|
||||||
case "Item":
|
case "Item":
|
||||||
type = EResourceType.Item;
|
type = EResourceType.Item;
|
||||||
break;
|
break;
|
||||||
case "Enemy":
|
case "Enemy":
|
||||||
type = EResourceType.Enemy;
|
type = EResourceType.Enemy;
|
||||||
break;
|
break;
|
||||||
case "Environment":
|
case "Environment":
|
||||||
type = EResourceType.Environment;
|
type = EResourceType.Environment;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_mapResourceInfoList.Add(new MapResourceInfo
|
_mapResourceInfoList.Add(new MapResourceInfo
|
||||||
{
|
{
|
||||||
Level = GameManager.Instance.LevelManager.Level,
|
Level = GameManager.Instance.LevelManager.Level,
|
||||||
Type = type,
|
Type = type,
|
||||||
ID = u.GetComponent<ResourceController>().ID,
|
ID = u.GetComponent<ResourceController>().ID,
|
||||||
Point = u.transform.position,
|
Point = u.transform.position,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 获取游戏信息
|
// 获取游戏信息
|
||||||
GameInfo gameInfo = new GameInfo
|
GameInfo gameInfo = new GameInfo
|
||||||
{
|
{
|
||||||
MapArchive = JsonUtility.ToJson(new Serialization<MapResourceInfo>(_mapResourceInfoList)),
|
MapArchive = JsonUtility.ToJson(new Serialization<MapResourceInfo>(_mapResourceInfoList)),
|
||||||
PlayerInfo = JsonUtility.ToJson(GameManager.Instance.PlayerManager.PlayerInfo),
|
PlayerInfo = JsonUtility.ToJson(GameManager.Instance.PlayerManager.PlayerInfo),
|
||||||
LevelInfo = GameManager.Instance.LevelManager.Level,
|
LevelInfo = GameManager.Instance.LevelManager.Level,
|
||||||
MaxLevelInfo = GameManager.Instance.LevelManager.MaxLevel,
|
MaxLevelInfo = GameManager.Instance.LevelManager.MaxLevel,
|
||||||
BackpackInfo = JsonUtility.ToJson(new Serialization<int, ItemInfo>(GameManager.Instance.BackpackManager.BackpackDictionary)),
|
BackpackInfo = JsonUtility.ToJson(new Serialization<int, ItemInfo>(GameManager.Instance.BackpackManager.BackpackDictionary)),
|
||||||
PlotInfo = JsonUtility.ToJson(new Serialization<int, int>(GameManager.Instance.PlotManager.PlotDictionary)),
|
PlotInfo = JsonUtility.ToJson(new Serialization<int, int>(GameManager.Instance.PlotManager.PlotDictionary)),
|
||||||
|
|
||||||
};
|
};
|
||||||
// 保存资源信息
|
// 保存资源信息
|
||||||
PlayerPrefs.SetString("GameInfo", JsonUtility.ToJson(gameInfo));
|
|
||||||
// UI 提示
|
try
|
||||||
GameManager.Instance.UIManager.ShowInfo("游戏保存成功!");
|
{
|
||||||
// 音频播放
|
#if UNITY_EDITOR_WIN
|
||||||
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "Save");
|
PlayerPrefs.SetString("GameInfo", JsonUtility.ToJson(gameInfo));
|
||||||
}
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
Debug.Log($"SaveDataDirPath->{SaveDataDirPath}");
|
||||||
|
Debug.Log($"Directory.Exists(SaveDataDirPath)->{Directory.Exists(SaveDataDirPath)}");
|
||||||
|
if (!Directory.Exists(SaveDataDirPath))
|
||||||
|
{
|
||||||
|
Debug.Log($"Directory.CreateDirectory(SaveDataDirPath)");
|
||||||
|
Directory.CreateDirectory(SaveDataDirPath);
|
||||||
|
}
|
||||||
|
string savestring = JsonUtility.ToJson(gameInfo);
|
||||||
|
Debug.Log($"savestring->{savestring}");
|
||||||
|
File.WriteAllText(SaveDataFilePath, savestring);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// UI 提示
|
||||||
|
GameManager.Instance.UIManager.ShowInfo("游戏已存档!");
|
||||||
|
// 音频播放
|
||||||
|
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "Save");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// UI 提示
|
||||||
|
GameManager.Instance.UIManager.ShowInfo("存档失败!");
|
||||||
|
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "No");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user