100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
using Cysharp.Threading.Tasks;
|
||
using Framework;
|
||
using System.Collections.Generic;
|
||
using PhxhSDK;
|
||
using PhxhSDK.Phxh;
|
||
using TGS;
|
||
using UnityEngine;
|
||
using static Gameplay.Level.LevelData;
|
||
using Constants = Framework.Constants;
|
||
|
||
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;
|
||
}
|
||
|
||
// public static bool CheckEnterLevel(int levelId)
|
||
// {
|
||
// var configFilePath = GetLevelFilePath(levelId);
|
||
// if (AssetManager.Instance.CanLocateAsset(configFilePath))
|
||
// {
|
||
// return true;
|
||
// }
|
||
//
|
||
// else
|
||
// {
|
||
// return false;
|
||
// }
|
||
// }
|
||
|
||
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;
|
||
}
|
||
return string.Format(Constants.LEVEL_CONFIG_FORMAT_PATH,cfg.LevelData);
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
} |