NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelUtils.cs

102 lines
3.3 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using Cysharp.Threading.Tasks;
2023-08-22 19:08:45 +08:00
using Framework;
2023-10-19 15:00:19 +08:00
using System.Collections.Generic;
2024-01-04 17:22:36 +08:00
using System.IO;
2024-01-10 19:04:01 +08:00
using Gameplay.Performance;
2023-10-19 15:00:19 +08:00
using PhxhSDK;
2023-11-30 15:47:49 +08:00
using PhxhSDK.Phxh;
2023-08-22 19:08:45 +08:00
using TGS;
using UnityEngine;
using static Gameplay.Level.LevelData;
2023-10-19 15:00:19 +08:00
using Constants = Framework.Constants;
2023-08-22 19:08:45 +08:00
namespace Gameplay.Level
{
public static class LevelUtils
{
2024-01-04 17:22:36 +08:00
private const string SCENE_ORIGIN_PATH = "Assets/Scenes/Maps";
private const string SCENE_POSTPROCESS_PATH = "Assets/Art/AutoGen/Maps";
private const string SCENE_POST_PROCESS_NAME = "PostProcess";
2023-08-22 19:08:45 +08:00
2023-11-21 15:04:56 +08:00
// public static bool CheckEnterLevel(int levelId)
// {
// var configFilePath = GetLevelFilePath(levelId);
// if (AssetManager.Instance.CanLocateAsset(configFilePath))
// {
// return true;
// }
//
// else
// {
// return false;
// }
// }
2023-08-22 19:08:45 +08:00
2023-10-19 15:00:19 +08:00
public static string GetLevelFilePath(int id)
{
var cfg = TableManager.Instance.Tables.Level.DataMap.GetValueOrDefault(id);
if (cfg == null)
{
DebugUtil.LogError($"找不到level配置id:{id}");
return null;
}
2023-11-21 16:15:07 +08:00
return string.Format(Constants.LEVEL_CONFIG_FORMAT_PATH,cfg.LevelData);
2023-10-19 15:00:19 +08:00
}
public static LevelData LoadLevelData(int id)
2023-10-19 15:00:19 +08:00
{
var levelFilePath = GetLevelFilePath(id);
var levelData = JsonHelper.LoadFromAddressableSync<LevelData>(levelFilePath);
2023-10-19 15:00:19 +08:00
if (levelData == null)
{
DebugUtil.LogError("LoadData failed, can not find level data: {0}", levelFilePath);
}
return levelData;
}
2023-08-22 19:08:45 +08:00
public static float SetCharaterToward(CharacterToward npcToward)
{
switch (npcToward)
{
case CharacterToward.TopLeft:
{
return 0f;
}
case CharacterToward.TopRight:
{
return 60f;
}
case CharacterToward.Right:
{
return 120f;
}
case CharacterToward.BottomRight:
{
return 180f;
}
case CharacterToward.BottomLeft:
{
return -120f;
}
default:
{
return -60f;
}
}
}
2024-01-04 17:22:36 +08:00
2024-01-16 18:37:02 +08:00
// public static string GetPostProcessLevelScenePath(string scenePath)
// {
// var oldSceneDir = scenePath;
// var oldSceneName = Path.GetFileNameWithoutExtension(scenePath);
// var tempSceneDir = oldSceneDir.Replace( SCENE_ORIGIN_PATH, SCENE_POSTPROCESS_PATH);
// var subStr = tempSceneDir.Substring(SCENE_POSTPROCESS_PATH.Length + 1);
// var folderName = Path.GetFileNameWithoutExtension(subStr.Replace("/", "_"));
// var result = $"{SCENE_POSTPROCESS_PATH}/{folderName}/{oldSceneName}_{SCENE_POST_PROCESS_NAME}.unity";
// return result;
// }
2023-08-22 19:08:45 +08:00
}
}