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

99 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Cysharp.Threading.Tasks;
using Framework;
using System.Collections.Generic;
using PhxhSDK;
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.FileName);
}
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;
}
}
}
}
}