private void InitGame(Scene arg0, LoadSceneMode arg1) { #region 材准备 var jar = new GroupJar(); Players = new Player[4]; GroupSet[] sets = new GroupSet[4]; Players[0] = new Player(GameManager.Instance.PlayerManager.PlayerName, jar.Roll()); CurrentPlayer = Players[0]; sets[0] = new GroupSet(Players[0], Cell, Object, true); for (int i = 1; i < 4; i++) { Players[i] = PlayerGenerator.GetPlayer(jar.Roll()); sets[i] = new GroupSet(Players[i], Cell, Object); } #endregion #region 构建棋盘 Vector2 locatorStart = new Vector2(0, 0); Vector2 step = new Vector2(0.5f, 0); int size = sets.Count(); int radius = 8; int rotation = -90; Vector2 locatorNow = locatorStart; List <Floor> edgeStarts = new List <Floor>(); List <Floor> edgeEnds = new List <Floor>(); Floor pre = null; Floor current = null; for (int i = 0; i < 4; i++) { //素材集合 GroupSet set = sets[i]; //起始点 locatorNow = locatorStart; Vector2 stepNow = Quaternion.Euler(0, 0, rotation * i) * step; locatorNow += stepNow; current = new Floor(locatorNow, FloorType.EndPoint, set.Cell, set.Player); pre = current; //通关路径 for (int j = 0; j < radius - 3; j++) { locatorNow += stepNow; current = new Floor(locatorNow, FloorType.Route, set.Cell, set.Player, null, pre); pre.Pre = current; pre = current; } //转弯路径 locatorNow += stepNow; var group = set.Player.Group; current = new Floor(locatorNow, FloorType.Corner, set.Cell, set.Player, (f, m) => m.Group == f.Player.Group, pre); edgeStarts.Add(current); pre = current; //常规路径 var index = 0; for (int x = 0; x < 13; x++) { //开头和第八格需要转弯 switch (x) { case 0: case 7: stepNow = Quaternion.Euler(0, 0, rotation) * stepNow; break; } locatorNow += stepNow; //第七格保留,在第八格后绘制 if (x == 6) { continue; } var tempSet = sets[(i + index + 1) % size]; current = new Floor(locatorNow, FloorType.Route, tempSet.Cell, tempSet.Player);//i因为定位到对应的组,Index+1是绘制当前格的偏移量 if (x == 0) { pre.AddNext((f, m) => m.Group != f.Player.Group, current); } else { pre.AddNext(null, current); } if (x == 12) { edgeEnds.Add(current); } current.Pre = pre; pre = current; if (x == 7) { //出生点 var tempNow = locatorNow; Vector2 tempStep = Quaternion.Euler(0, 0, rotation * i) * step; tempNow += tempStep; var startPoint = new Floor(tempNow, FloorType.StartPoint, set.Cell, set.Player, null, pre); //卵点 tempNow += tempStep * 2 + (Vector2)(Quaternion.Euler(0, 0, rotation) * tempStep); for (int y = 0; y < 4; y++) { tempStep = Quaternion.Euler(0, 0, rotation) * tempStep; tempNow += tempStep; var spawn = new Floor(tempNow, FloorType.Spawn, set.Cell, set.Player, null, startPoint); new Unit(set.Player, spawn, set.Object); } } index += 1; } } //连接首尾 for (int i = 0; i < edgeStarts.Count; i++) { var preEnd = edgeEnds[i == 0 ? edgeStarts.Count - 1 : i - 1]; edgeStarts[i].Pre = preEnd; } for (int i = 0; i < edgeEnds.Count; i++) { var nextStart = edgeStarts[i == edgeStarts.Count - 1 ? 0 : i + 1]; edgeEnds[i].AddNext(null, nextStart); } #endregion #region 释放参数 foreach (var set in sets) { set.Cell.SetActive(false); set.Object.SetActive(false); } #endregion ////绘制行走线路 //var move = new MoveMent(Players[0].Group, 100); //current = Players[0].Units[0].Current; //while (move.Vatality>0) //{ // var next = current.GetNext(move); // current.Display(next); // current = next; // move.Vatality--; //} //开始游戏 CurrentPlayerIndex = -1; NextPlayer(); }