【Debug】添加try...catch和日志测试

iOS_release
zhangaotian 2024-07-19 14:17:49 +08:00
parent 4cf5adbb3f
commit b60a4953ed
4 changed files with 156 additions and 98 deletions

View File

@ -15,7 +15,7 @@ MonoBehaviour:
m_DefaultGroup: d58d9f3a3b49b264e94d9dd1182e2910
m_currentHash:
serializedVersion: 2
Hash: 055613adb1a6e9184deaa9c262f9202f
Hash: 3980b428a3d1445ac52889f7249df15d
m_OptimizeCatalogSize: 0
m_BuildRemoteCatalog: 0
m_BundleLocalCatalog: 0

View File

@ -27,6 +27,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: b5b08b0ba867e46bd90a825d41b818c9
m_Address: Assets/Config/Build
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
m_ReadOnly: 0
m_Settings: {fileID: 11400000, guid: ed93b85c5b1133d4c93abe6c976cf739, type: 2}
m_SchemaSet:

View File

@ -184,26 +184,33 @@ namespace Framework.Manager
/// </summary>
private void InitNodesInfo()
{
foreach (var node in _curBuildData.NodeInfos)
try
{
var nodeInfo = new NodeInfo
foreach (var node in _curBuildData.NodeInfos)
{
Name = node.Name,
Options = new Dictionary<string, OptionInfo>(),
IconPath = node.IconPath
};
foreach (var option in node.Options)
{
var optionInfo = new OptionInfo()
var nodeInfo = new NodeInfo
{
Name = option
Name = node.Name,
Options = new Dictionary<string, OptionInfo>(),
IconPath = node.IconPath
};
nodeInfo.Options.Add(option, optionInfo);
}
foreach (var option in node.Options)
{
var optionInfo = new OptionInfo()
{
Name = option
};
NodeInfos.Add(nodeInfo.Name, nodeInfo);
nodeInfo.Options.Add(option, optionInfo);
}
NodeInfos.Add(nodeInfo.Name, nodeInfo);
}
}
catch (Exception e)
{
DebugUtil.LogError("BuildManager.InitNodesInfo 初始化节点错误 :{0}", e);
}
}
@ -212,63 +219,48 @@ namespace Framework.Manager
/// </summary>
private void InitUserBuildInfo(UserBuildInfo userBuildInfo)
{
//游戏中传入数据
if (userBuildInfo != null)
try
{
_userBuildInfo = userBuildInfo;
}
else
{
StorageManager.Instance.Init();
_userBuildInfo = StorageManager.Instance.GetStorage<UserBuildInfo>(GlobalConstants.UserBuildSaveKey);
if (_userBuildInfo == null)
//游戏中传入数据
if (userBuildInfo != null)
{
var buildId = _curBuildData.buildID;
_userBuildInfo = new UserBuildInfo(buildId);
_userBuildInfo = userBuildInfo;
}
}
foreach (var nodeInfo in NodeInfos)
{
if (_userBuildInfo.ChooseNodeInfo.TryGetValue(nodeInfo.Key, out var option))
else
{
continue;
StorageManager.Instance.Init();
_userBuildInfo =
StorageManager.Instance.GetStorage<UserBuildInfo>(GlobalConstants.UserBuildSaveKey);
if (_userBuildInfo == null)
{
var buildId = _curBuildData.buildID;
_userBuildInfo = new UserBuildInfo(buildId);
}
}
var optionInfo = nodeInfo.Value.GetOptionInfo();
if (optionInfo == null) return;
_userBuildInfo.ChooseNodeInfo.TryAdd(nodeInfo.Key, optionInfo.Name);
}
//打印Debug玩家Build信息
/*foreach (var infos in _userBuildInfo.ChooseNodeInfo)
{
DebugUtil.LogError("节点 {0} 选择的的是 {1}", infos.Key, infos.Value);
}*/
}
/// <summary>
/// 异步加载该建造物品图标
/// </summary>
private async UniTask InitIcon()
{
foreach (var nodeInfo in NodeInfos.Values)
{
foreach (var optionInfo in nodeInfo.Options.Values)
foreach (var nodeInfo in NodeInfos)
{
var index = GameBuildUtils.ExtractNumber(optionInfo.Name);
if (_userBuildInfo.ChooseNodeInfo.TryGetValue(nodeInfo.Key, out var option))
{
continue;
}
optionInfo.IconName = await InitOptionIcon(nodeInfo.IconPath, index);
var optionInfo = nodeInfo.Value.GetOptionInfo();
if (optionInfo == null) return;
_userBuildInfo.ChooseNodeInfo.TryAdd(nodeInfo.Key, optionInfo.Name);
}
}
}
private async void InitBlueprint()
{
var path = string.Format(Constants.Constants.BuildBlueprint, _curBuildData.buildID);
DebugUtil.LogError("加载蓝图的路径:{0}", path);
CurBlueprint = await AssetManager.Instance.LoadAssetAsync<Sprite>(path);
//打印Debug玩家Build信息
/*foreach (var infos in _userBuildInfo.ChooseNodeInfo)
{
DebugUtil.LogError("节点 {0} 选择的的是 {1}", infos.Key, infos.Value);
}*/
}
catch (Exception e)
{
DebugUtil.LogError("BuildManager.InitUserBuildInfo 初始玩家信息错误 :{0}", e);
}
}
/// <summary>
@ -276,41 +268,71 @@ namespace Framework.Manager
/// </summary>
private void InitCondition()
{
switch (_curBuildData.unlockType)
try
{
case UnlockType.ForGroup:
switch (_curBuildData.unlockType)
{
foreach (var unlockInfo in _curBuildData.unlockInfos)
case UnlockType.ForGroup:
{
var nodeName = string.Format(NodeName, unlockInfo.conditionGroup);
if (NodeInfos.TryGetValue(nodeName, out var nodeInfo))
foreach (var unlockInfo in _curBuildData.unlockInfos)
{
nodeInfo.Condition = unlockInfo.condition;
//DebugUtil.LogError("挂点解锁:节点{0}的解锁条件是:{1}", nodeInfo.Name, unlockInfo.condition);
}
}
break;
}
case UnlockType.ForThematic:
{
foreach (var unlockInfo in _curBuildData.unlockInfos)
{
var optionName = string.Format(OptionName, unlockInfo.conditionGroup);
foreach (var nodeInfo in NodeInfos.Values)
{
if (nodeInfo.Options.TryGetValue(optionName, out var optionInfo))
var nodeName = string.Format(NodeName, unlockInfo.conditionGroup);
if (NodeInfos.TryGetValue(nodeName, out var nodeInfo))
{
optionInfo.Condition = unlockInfo.condition;
DebugUtil.LogError("主题解锁:节点{0}的选项{1}的解锁条件是:{2}", nodeInfo.Name, optionInfo.Name,
unlockInfo.condition);
nodeInfo.Condition = unlockInfo.condition;
//DebugUtil.LogError("挂点解锁:节点{0}的解锁条件是:{1}", nodeInfo.Name, unlockInfo.condition);
}
}
}
break;
break;
}
case UnlockType.ForThematic:
{
foreach (var unlockInfo in _curBuildData.unlockInfos)
{
var optionName = string.Format(OptionName, unlockInfo.conditionGroup);
foreach (var nodeInfo in NodeInfos.Values)
{
if (nodeInfo.Options.TryGetValue(optionName, out var optionInfo))
{
optionInfo.Condition = unlockInfo.condition;
DebugUtil.LogError("主题解锁:节点{0}的选项{1}的解锁条件是:{2}", nodeInfo.Name, optionInfo.Name,
unlockInfo.condition);
}
}
}
break;
}
}
}
catch (Exception e)
{
DebugUtil.LogError("BuildManager.InitCondition 初始化条件错误 :{0}", e);
}
}
/// <summary>
/// 异步加载该建造物品图标
/// </summary>
private async UniTask InitIcon()
{
try
{
foreach (var nodeInfo in NodeInfos.Values)
{
foreach (var optionInfo in nodeInfo.Options.Values)
{
var index = GameBuildUtils.ExtractNumber(optionInfo.Name);
optionInfo.IconName = await InitOptionIcon(nodeInfo.IconPath, index);
}
}
}
catch (Exception e)
{
DebugUtil.LogError("BuildManager.InitIcon 初始化图标数据错误 :{0}", e);
}
}
/// <summary>
@ -318,21 +340,45 @@ namespace Framework.Manager
/// </summary>
private async UniTask<string> InitOptionIcon(string iconsPath, int index)
{
var fileEntries = Directory.GetFiles(iconsPath, "*.png");
foreach (var filePath in fileEntries)
try
{
var fileName = Path.GetFileName(filePath);
var name = fileName.Replace(".png", "");
if (GameBuildUtils.ExtractNumber(name) == index)
var fileEntries = Directory.GetFiles(iconsPath, "*.png");
foreach (var filePath in fileEntries)
{
var assetPath = filePath.Replace(Application.dataPath, "").Replace('\\', '/');
var sprite = await AssetManager.Instance.LoadAssetAsync<Sprite>(assetPath);
_iconSprites.TryAdd(name, sprite);
return name;
var fileName = Path.GetFileName(filePath);
var name = fileName.Replace(".png", "");
if (GameBuildUtils.ExtractNumber(name) == index)
{
var assetPath = filePath.Replace(Application.dataPath, "").Replace('\\', '/');
var sprite = await AssetManager.Instance.LoadAssetAsync<Sprite>(assetPath);
_iconSprites.TryAdd(name, sprite);
return name;
}
}
}
return null;
return null;
}
catch (Exception e)
{
DebugUtil.LogError("BuildManager.InitOptionIcon 加载选项图标错误, 路径: {0}, Error: {1}", iconsPath, e);
return null;
}
}
/// <summary>
/// 加载当前场景蓝图
/// </summary>
private async void InitBlueprint()
{
try
{
var path = string.Format(Constants.Constants.BuildBlueprint, _curBuildData.buildID);
CurBlueprint = await AssetManager.Instance.LoadAssetAsync<Sprite>(path);
}
catch (Exception e)
{
DebugUtil.LogError("BuildManager.InitBlueprint 加载蓝图错误 :{0}", e);
}
}
/// <summary>

View File

@ -63,6 +63,13 @@ namespace Gameplay.LoadingExecutor
var buildPath = string.Format(Framework.Constants.Constants.SceneBuildPath, buildId);
var buildConfig = string.Format(Framework.Constants.Constants.BuildConfigPath, buildId);
var buildData = await JsonHelper.LoadFromAddressable<BuildData>(buildConfig);
//Debug TODO 删除
DebugUtil.LogError("当前buildID: {0}", buildData.buildID);
foreach (var nodeInfo in buildData.NodeInfos)
{
DebugUtil.LogError("加载{0}图标路径:{1}", nodeInfo.Name, nodeInfo.IconPath);
}
await BuildManager.Instance.Init(buildData, true, buildInfo);
await Addressables.LoadSceneAsync(buildPath).ToUniTask();
}