103 lines
3.8 KiB
C#
103 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
using Game.Pathfinding;
|
|
using JetBrains.Annotations;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using Game.Room;
|
|
|
|
namespace Game
|
|
{
|
|
[Procedure(ProcedureType.EnterGameSceneProcedure)]
|
|
class EnterGameSceneProcedure : ProcedureBase
|
|
{
|
|
public override void OnEnter()
|
|
{
|
|
base.OnEnter();
|
|
var player = Game.playerManager.CreatePlayer("测试", "player", 10);
|
|
Game.playerManager.SetCurrentPlayer(player);
|
|
var room = Game.roomManager.GetRoom(RoomType.出生点);
|
|
var joinPosition = room.roomInfo.GetJoinPosition();
|
|
var wayPoints = Game.bfsManager.FindPath(joinPosition);
|
|
|
|
UniTask.Create(async () =>
|
|
{
|
|
await player.MoveAsync(wayPoints, room, new CancellationToken());
|
|
this.OnLeave();
|
|
});
|
|
}
|
|
|
|
public override void OnLeave()
|
|
{
|
|
base.OnLeave();
|
|
Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneLogicProcedure);
|
|
}
|
|
}
|
|
|
|
[Procedure(ProcedureType.GameSceneLogicProcedure)]
|
|
class GameSceneLogicProcedure : ProcedureBase
|
|
{
|
|
public override void OnEnter()
|
|
{
|
|
base.OnEnter();
|
|
|
|
// UniTask.Create(async () =>
|
|
// {
|
|
// await ResourceManager.Instance.LoadSceneAsync(SceneType.Game.ToString());
|
|
// EventManager.Instance.FireNow(this,new LoadingGameSceneFinishEventArgs(true));
|
|
// });
|
|
|
|
// var gameGlobalConfig = GameObject.FindObjectOfType<GameGlobalConfig>();
|
|
// BFS<WayPoint> bfs = new BFS<WayPoint>(CreateGraph(gameGlobalConfig));
|
|
// var beginNode = GetNode(bfs, new Vector2(-29f,-16.5f));
|
|
// var endNode = GetNode(bfs, new Vector2(-15.8f,44.3f));
|
|
// var findPath = bfs.FindPath(beginNode, endNode);
|
|
// var wayPoints = new List<WayPoint>();
|
|
// findPath.GetDatas(wayPoints);
|
|
// Debug.Log($"Indices:{string.Join(',',findPath.GetNodes().Select(x=> x.index))}");
|
|
// Debug.Log($"Positions:{string.Join(',',findPath.GetNodes().Select(x=> x.data.position))}");
|
|
|
|
// player.MoveAsync()
|
|
|
|
// var findPath = Game.bfsManager.FindPath(new Vector2(-29f, -16.5f), new Vector3(-15.8f, 44.3f));
|
|
// var wayPoints = new List<WayPoint>();
|
|
// findPath.GetDatas(wayPoints);
|
|
// Debug.Log($"Indices:{string.Join(',',findPath.GetNodes().Select(x=> x.index))}");
|
|
// Debug.Log($"Positions:{string.Join(',',findPath.GetNodes().Select(x=> x.data.position))}");
|
|
}
|
|
|
|
// [CanBeNull]
|
|
// private static Node<WayPoint> GetNode(BFS<WayPoint> bfs, Vector2 position)
|
|
// {
|
|
// float distance = float.MaxValue;
|
|
// Node<WayPoint> targetStartNode = null;
|
|
// bfs.GetNode(node =>
|
|
// {
|
|
// var magnitude = ((Vector2)node.data.position - position).magnitude;
|
|
// if (magnitude < distance)
|
|
// {
|
|
// distance = magnitude;
|
|
// targetStartNode = node;
|
|
// }
|
|
//
|
|
// return false;
|
|
// });
|
|
// return targetStartNode;
|
|
// }
|
|
//
|
|
// private Graph<WayPoint> CreateGraph(GameGlobalConfig gameGlobalConfig)
|
|
// {
|
|
// var graph = new WayPointGraph();
|
|
// graph.Initialize(gameGlobalConfig.nodeMaps);
|
|
// return graph;
|
|
// }
|
|
|
|
public override void OnLeave()
|
|
{
|
|
base.OnLeave();
|
|
// UIManager.Instance.ShowUI(UIType.GameSceneMainUI);
|
|
// ProcedureManager.Instance.ChangeProcedure(ProcedureType.GameSceneLogicProcedure);
|
|
}
|
|
}
|
|
} |