using System; using System.Collections.Generic; using System.IO; using System.Linq; using Cysharp.Threading.Tasks; using Game.JSON; using Game.MVVM.Model; using Game.Pathfinding; using JetBrains.Annotations; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Sirenix.OdinInspector; using Spine.Unity; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; namespace Game { public class Test : MonoBehaviour { // public Transform tr; private void Awake() { // UniTask.Create(this.TTT); } // async UniTask TTT() // { // List uniTasks = new List(); // // 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"); // } // public SkeletonAnimation _skeletonAnimation; // public TMP_Text str; // public string str1; // public List list = new List() // { // new MenuItem() // { // id = 0, menuName = "驯龙", menuIcon = "" // }, // new MenuItem() // { // id = 1, menuName = "集市", menuIcon = "" // }, // new MenuItem() // { // id = 2, menuName = "商城", menuIcon = "" // }, // new MenuItem() // { // id = 3, menuName = "我的", menuIcon = "" // }, // }; // public List storeItems = new List(); public string str; private void Update() { if (Input.GetKeyDown(KeyCode.A)) { // Game.httpManager.ConnectAsync().Forget(); // var go = Game.resourceManager.LoadGameObjectSync(@"player"); // // var go = ResourceManager.Instance.LoadGameObject_MMM(@"hh"); // go.name = "123"; // this.istrue1 = false; // _skeletonAnimation.AnimationName = "atk"; // // AnalyzeJSON.Analyze(str1); // AnalyzeJSON.Analyze(str.text); // AnalyzeJSON.Main(str.text); // var loadAssetSync = Game.resourceManager.LoadAssetSync(AssetConstPath.Assets_GameRes_Config_StoreConfig); // var textAsset = loadAssetSync.AssetObject as TextAsset; // // var analyzeToDicDeep = AnalyzeJSON.AnalyzeToDicDeep(textAsset.text); // ////analyzeToDicDeep.Keys // var hallSceneMainUI = Game.uiManager.GetUI(UIType.HallSceneMallUI); //// hallSceneMainUI.InitMid(this.analyzeToDicDeep); // // // 解析 JSON 到动态类型 // var result = JsonConvert.DeserializeObject>(json); // // // 创建最终存储用的字典 // var finalDictionary = new Dictionary(); // // foreach (var item in result) // { // if (item.Value is JArray) // { // // 序列化嵌套数组或对象为 JSON 字符串 // finalDictionary[item.Key] = JsonConvert.SerializeObject(item.Value, Formatting.None); // } // else // { // // 直接将值转换为字符串 // finalDictionary[item.Key] = item.Value.ToString(); // } // } // // // 打印最终字典中的内容 // foreach (var pair in finalDictionary) // { // Debug.Log($"{pair.Key}: {pair.Value}"); // } } if (Input.GetKeyDown(KeyCode.S)) { Game.socketManager.CloseConnect(); } if (Input.GetKeyDown(KeyCode.D)) { // this.istrue2 = false; Game.socketManager.SendMessage(this.str); // _skeletonAnimation.AnimationName = "idle"; // // ResourceManager.Instance.Release("hh"); // // CommonHelper.FindChildDeep(tr, "imag"); // Debug.Log("找到此组件l"); // // ResourceManager.Instance.LoadSceneAsync("Game", LoadSceneMode.Additive); // // EventManager.Instance.FireNow(this, new LoadingGameSceneFinishEventArgs(true)); // //var value = this.GetType().ToString().Split("."); // Debug.Log(value[^1]); // // var values = Enum.GetValues(typeof(ProcedureType)); // foreach (var value in values) // { // UnityEngine.Debug.Log( value.ToString()); // } // this.AAA(this.startTr.position, this.endTr.position); // ShuffleAndRemoveRooms(new List() { "1", "2", "3", "4", " 5", "6", " 7", "8", "9" }); } // 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); } public void ShuffleAndRemoveRooms(List list) { // 使用Fisher-Yates洗牌算法随机打乱allRooms列表 ShuffleList(list); // 随机决定要移除的房间数量,保证至少移除一个房间,最多移除总数减一 int removeCount = UnityEngine.Random.Range(1, list.Count); // 移除指定数量的房间(从列表末尾移除) for (int i = 0; i < removeCount; i++) { list.RemoveAt(list.Count - 1); } foreach (var i in list) { Debug.Log(i); } } // 实现Fisher-Yates洗牌算法 private void ShuffleList(List list) { for (int i = list.Count - 1; i > 0; i--) { int swapIndex = UnityEngine.Random.Range(0, i + 1); (list[i], list[swapIndex]) = (list[swapIndex], list[i]); } } public Transform startTr; public Transform endTr; void AAA(Vector2 start, Vector2 end) { var gameGlobalConfig = GameObject.FindObjectOfType(); BFS bfs = new BFS(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(); // 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 GetNode(BFS bfs, Vector2 position) { float distance = float.MaxValue; Node 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 CreateGraph(GameGlobalConfig gameGlobalConfig) { var graph = new WayPointGraph(); graph.Initialize(gameGlobalConfig.nodeMaps); return graph; } } }