192 lines
6.7 KiB
C#
192 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AOT.PostProcess.ColorFade;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay.Area.Around;
|
|
using Gameplay.Area.BoardView;
|
|
using Gameplay.Guide;
|
|
using LTGame;
|
|
using TGS;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.Level
|
|
{
|
|
public abstract class BaseLevelState : NBaseState
|
|
{
|
|
protected Level _level;
|
|
|
|
public BaseLevelState(Level level, int stateId) : base(stateId)
|
|
{
|
|
_level = level;
|
|
}
|
|
|
|
protected async void _WaitBlackOut()
|
|
{
|
|
if (GlobalFadeManager.instance.fadeProgress <= 0.5f)
|
|
{
|
|
return;
|
|
}
|
|
GlobalFadeManager.instance.FadeOut(0.5f);
|
|
await UniTask.WaitForSeconds(0.5f);
|
|
}
|
|
|
|
public override void Run(float dt)
|
|
{
|
|
// 暂停状态下不执行
|
|
if (_level.IsPause()) return;
|
|
|
|
base.Run(dt);
|
|
}
|
|
|
|
protected override void _OnEnter(NBaseState exitState,
|
|
object param)
|
|
{
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void _OnExit(NBaseState exitState,
|
|
object param)
|
|
{
|
|
}
|
|
|
|
protected abstract void _OnCellClick(TerrainGridSystem tgs, int cellIndex, int buttonIndex);
|
|
|
|
protected abstract void _OnClick(Vector2 screenPosition);
|
|
|
|
public void ClickFromScreen(Vector2 screenPos)
|
|
{
|
|
_OnClick(screenPos);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查能否点击地板
|
|
/// </summary>
|
|
protected void CheckCellClick(TerrainGridSystem tgs, int cellIndex, int buttonIndex)
|
|
{
|
|
if (GuideManager.Instance.IsGuiding && // 在新手引导中
|
|
GuideManager.Instance.IsControlFloor && // 是否控制地板点击
|
|
GuideManager.Instance.FloorIndex != cellIndex) // 点击的不是指定地板
|
|
{
|
|
EventManager.Instance.Send(EventManager.EventName.ToFightModelDragSuc, false);
|
|
return;
|
|
}
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.Guide_ClickFloor, cellIndex);
|
|
|
|
DebugUtil.LogG($"用户点击格子:{cellIndex}");
|
|
_OnCellClick(tgs, cellIndex, buttonIndex);
|
|
|
|
// _TestCode(cellIndex);
|
|
|
|
// _TestCode2(cellIndex);
|
|
|
|
// _PerformanceTest(cellIndex);
|
|
}
|
|
|
|
private void _TestCode1(int cellIndex)
|
|
{
|
|
var blockData = _level.Map.GetBlockData(cellIndex);
|
|
if (blockData == null)
|
|
{
|
|
DebugUtil.LogError("Block data is null");
|
|
return;
|
|
}
|
|
DebugUtil.Log("blockProperty:" + blockData.GetTerrainTypeProperty().crossLevel);
|
|
_level.Map.GetRuntimeBlockProperty(cellIndex, out var runtimeBlockProperty);
|
|
DebugUtil.Log("runtimeBlockProperty:" + runtimeBlockProperty.crossLevel);
|
|
}
|
|
|
|
private void _TestCode2(int cellIndex)
|
|
{
|
|
var mathV3 = AroundHelper.GetMathPosV3(cellIndex);
|
|
var reCovertIndex = AroundHelper.GetCellIndexV3(mathV3);
|
|
DebugUtil.Log("cellIndex:" + cellIndex + " mathV3:" + mathV3 + " recovertIndex:" + reCovertIndex);
|
|
cellIndex = reCovertIndex;
|
|
|
|
var cacheList = new System.Collections.Generic.List<int>();
|
|
AroundHelper.GetAround(cellIndex, 10, cacheList);
|
|
|
|
var centerPos = _level.Map.TerrainGridSystem.CellGetPosition(cellIndex);
|
|
// 在对应位置创建一个球体
|
|
DebugUtil.CreateSphere(centerPos, 0.5f, 10f);
|
|
for (int i = 0; i < cacheList.Count; i++)
|
|
{
|
|
var searchIndex = cacheList[i];
|
|
var worldPos = _level.Map.TerrainGridSystem.CellGetPosition(searchIndex);
|
|
|
|
Debug.DrawLine(centerPos, worldPos, Color.red, 10);
|
|
}
|
|
}
|
|
|
|
private void _TestCode3(int cellIndex)
|
|
{
|
|
var mapBlockPos = _level.Map.TGSCellIndex2BlockPosition(cellIndex);
|
|
var mathV3 = AroundHelper.GetMathPosV3(cellIndex);
|
|
DebugUtil.Log("cellIndex:" + cellIndex + " mapBlockPos:" + mapBlockPos + " mathV3:" + mathV3);
|
|
|
|
// 指定一个方向
|
|
var pointsX = new List<Vector3Int>();
|
|
pointsX.Add(mathV3 + new Vector3Int(1, 0, 0));
|
|
pointsX.Add(mathV3 + new Vector3Int(-1, 0, 0));
|
|
|
|
var pointsY = new List<Vector3Int>();
|
|
pointsY.Add(mathV3 + new Vector3Int(0, 1, 0));
|
|
pointsY.Add(mathV3 + new Vector3Int(0, -1, 0));
|
|
|
|
var pointsZ = new List<Vector3Int>();
|
|
pointsZ.Add(mathV3 + new Vector3Int(0, 0, 1));
|
|
pointsZ.Add(mathV3 + new Vector3Int(0, 0, -1));
|
|
|
|
var centerPos = _level.Map.TerrainGridSystem.CellGetPosition(cellIndex);
|
|
// 在对应位置创建一个球体
|
|
DebugUtil.CreateSphere(centerPos, 0.5f, 10f);
|
|
for (int i = 0; i < pointsX.Count; i++)
|
|
{
|
|
var reCovertIndex = AroundHelper.GetCellIndexV3(pointsX[i]);
|
|
var worldPos = _level.Map.TerrainGridSystem.CellGetPosition(reCovertIndex);
|
|
Debug.DrawLine(centerPos, worldPos, Color.red, 10);
|
|
}
|
|
for (int i = 0; i < pointsY.Count; i++)
|
|
{
|
|
var reCovertIndex = AroundHelper.GetCellIndexV3(pointsY[i]);
|
|
var worldPos = _level.Map.TerrainGridSystem.CellGetPosition(reCovertIndex);
|
|
Debug.DrawLine(centerPos, worldPos, Color.green, 10);
|
|
}
|
|
for (int i = 0; i < pointsZ.Count; i++)
|
|
{
|
|
var reCovertIndex = AroundHelper.GetCellIndexV3(pointsZ[i]);
|
|
var worldPos = _level.Map.TerrainGridSystem.CellGetPosition(reCovertIndex);
|
|
Debug.DrawLine(centerPos, worldPos, Color.blue, 10);
|
|
}
|
|
|
|
}
|
|
|
|
private void _PerformanceTest(int cellIndex)
|
|
{
|
|
UnityEngine.Profiling.Profiler.BeginSample("PerformanceTest - GetAroundMath");
|
|
var cacheList = new System.Collections.Generic.List<int>();
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
cacheList.Clear();
|
|
AroundHelper.GetAroundMath(cellIndex, 7, cacheList);
|
|
}
|
|
UnityEngine.Profiling.Profiler.EndSample();
|
|
|
|
UnityEngine.Profiling.Profiler.BeginSample("PerformanceTest - GetAroundLogic");
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
cacheList.Clear();
|
|
AroundHelper.GetAroundLogic(cellIndex, 7, cacheList);
|
|
}
|
|
UnityEngine.Profiling.Profiler.EndSample();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |