forked from zxl/Frame
1
0
Fork 0
Frame/Assets/Scripts/Test.cs

157 lines
4.6 KiB
C#
Raw Normal View History

2024-04-02 18:17:57 +08:00
using System;
2024-04-08 18:20:55 +08:00
using System.Collections.Generic;
using System.Linq;
2024-04-09 13:22:52 +08:00
using Cysharp.Threading.Tasks;
2024-04-08 18:20:55 +08:00
using Game.Pathfinding;
using JetBrains.Annotations;
2024-04-06 11:59:18 +08:00
using Sirenix.OdinInspector;
2024-04-02 18:17:57 +08:00
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Game
{
public class Test : MonoBehaviour
{
// public Transform tr;
2024-04-02 18:17:57 +08:00
2024-04-09 13:22:52 +08:00
private void Awake()
{
// UniTask.Create(this.TTT);
}
// async UniTask TTT()
// {
// List<UniTask> uniTasks = new List<UniTask>();
//
// uniTasks.Add(this.TT1());
// uniTasks.Add(this.TT2());
//
// await UniTask.WhenAll(uniTasks);
// Debug.Log("TTT finish");
// }
//
// bool istrue1 = false;
//
// async UniTask TT1()
// {
// this.istrue1 = true;
// while (istrue1)
// {
// Debug.Log("等待1 ing");
// await UniTask.Yield();
// }
//
// Debug.Log("等待1 finish");
// }
//
// bool istrue2 = false;
//
// async UniTask TT2()
// {
// this.istrue2 = true;
// while (istrue2)
// {
// Debug.Log("等待2 ing");
// await UniTask.Yield();
// }
//
// Debug.Log("等待2 finish");
// }
2024-04-02 18:17:57 +08:00
private void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
2024-04-04 23:51:14 +08:00
// var go = Game.resourceManager.LoadGameObjectSync(@"player");
// // var go = ResourceManager.Instance.LoadGameObject_MMM(@"hh");
// go.name = "123";
2024-04-09 13:22:52 +08:00
// this.istrue1 = false;
2024-04-02 18:17:57 +08:00
}
if (Input.GetKeyDown(KeyCode.D))
{
2024-04-09 13:22:52 +08:00
// this.istrue2 = false;
2024-04-02 18:17:57 +08:00
//
// ResourceManager.Instance.Release("hh");
//
// CommonHelper.FindChildDeep<Image>(tr, "imag");
// Debug.Log("找到此组件l");
2024-04-03 14:38:44 +08:00
//
// ResourceManager.Instance.LoadSceneAsync("Game", LoadSceneMode.Additive);
2024-04-02 18:17:57 +08:00
//
2024-04-03 17:46:56 +08:00
// EventManager.Instance.FireNow(this, new LoadingGameSceneFinishEventArgs(true));
2024-04-06 11:59:18 +08:00
2024-04-03 17:46:56 +08:00
//
//var value = this.GetType().ToString().Split(".");
2024-04-06 11:59:18 +08:00
// Debug.Log(value[^1]);
//
// var values = Enum.GetValues(typeof(ProcedureType));
// foreach (var value in values)
// {
// UnityEngine.Debug.Log( value.ToString());
// }
2024-04-08 18:20:55 +08:00
this.AAA(this.startTr.position, this.endTr.position);
2024-04-02 18:17:57 +08:00
}
2024-04-08 18:20:55 +08:00
// RaycastHit2D hit = Physics2D.Raycast(Input.mousePosition, Vector2.up);
//
// // If it hits something...
// if (hit.collider != null)
// {
// Debug.Log($"碰撞的是 {hit.collider.name} 鼠标的点在 {hit.point}");
// }
//
// Debug.Log(hit.point);
}
2024-04-08 18:20:55 +08:00
public Transform startTr;
public Transform endTr;
void AAA(Vector2 start, Vector2 end)
{
2024-04-08 18:20:55 +08:00
var gameGlobalConfig = GameObject.FindObjectOfType<GameGlobalConfig>();
BFS<WayPoint> bfs = new BFS<WayPoint>(CreateGraph(gameGlobalConfig));
var beginNode = GetNode(bfs, start);
var endNode = GetNode(bfs, end);
Debug.Log($"start is {beginNode.index}, end is {endNode.index}");
// 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))}");
2024-04-02 18:17:57 +08:00
}
2024-04-06 11:59:18 +08:00
2024-04-08 18:20:55 +08:00
[CanBeNull]
private static Node<WayPoint> GetNode(BFS<WayPoint> bfs, Vector2 position)
2024-04-06 11:59:18 +08:00
{
2024-04-08 18:20:55 +08:00
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;
}
2024-04-06 11:59:18 +08:00
2024-04-08 18:20:55 +08:00
private Graph<WayPoint> CreateGraph(GameGlobalConfig gameGlobalConfig)
{
var graph = new WayPointGraph();
graph.Initialize(gameGlobalConfig.nodeMaps);
return graph;
2024-04-06 11:59:18 +08:00
}
2024-04-02 18:17:57 +08:00
}
}