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

99 lines
2.9 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;
using PhxhSDK;
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
{
public static uint RaycastUnit(Vector3 screenPosition)
{
var camera = CameraManager.Instance.MainCamera;
if (camera)
{
var ray = camera.ScreenPointToRay(screenPosition);
var info = GameplayInfoManager.Instance.QueryByRaycast(ray, LayerMask.GetMask("Unit"));
if (info != null && info.type == GameplayInfoManager.GameplayInfo.GameInfoType.Unit)
{
return info.id;
}
}
return Constants.INVALID_UINT_ID;
}
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 15:04:56 +08:00
return cfg.LevelData;
2023-10-19 15:00:19 +08:00
}
public static async UniTask<LevelData> LoadLevelData(int id)
{
var levelFilePath = GetLevelFilePath(id);
var levelData = await JsonHelper.LoadFromAddressble<LevelData>(levelFilePath);
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;
}
}
}
}
}