/// <summary> /// 合并地图后显示 /// </summary> /// <param name="mapClass"></param> private void ShowCombineMap(MapClass mapClass) { isWinFull = false; for (int i = 0; i < mapObjList.Count; i++) { Destroy(mapObjList[i]); } mapObjList.Clear(); if (wallParentTempObj != null) { Destroy(wallParentTempObj); } if (mapParentTempObj != null) { Destroy(mapParentTempObj); } mapGridList.Clear(); balkVecList.Clear(); mapVecToItemDic.Clear(); int squareIndex = 0; switch (mapClass.width) { case 12: squareIndex = 0; break; case 16: squareIndex = 1; break; case 20: squareIndex = 2; break; default: squareIndex = 0; break; } if (lastSquareIndex != squareIndex) { if (squareTrm != null && ballTrm != null) { Destroy(ballTrm.gameObject); Destroy(squareTrm.gameObject); } GameObject squareObj = Instantiate(squarePrefabs[squareIndex]); squareTrm = squareObj.transform; mapParentTrm = squareTrm.GetComponent <SquareItem>().groundParentTrm; GameObject ballObj = Instantiate(ballItemObj); ballTrm = ballObj.transform; ballObj.transform.SetParent(mapParentTrm); BallChangeSkin(); } lastSquareIndex = squareIndex; touchCtrl.SetSquareTrm(squareTrm, ballTrm); Tweener tweener = squareTrm.DOLocalRotate(Vector3.zero, 0.5f); tweener.OnComplete(() => { Color fillColor = ConfigSystem.instance.GetMapColor(); Color wallColor = ConfigSystem.instance.GetWallColor(); Vector3 initBallPos = outBorderVec; #region 合并个体优化地图加载 //GameObject wallParentObj = GameObject.CreatePrimitive(PrimitiveType.Cube); //wallParentObj.transform.localPosition = Vector3.zero; //Destroy(wallParentObj.GetComponent<BoxCollider>()); //wallParentObj.name = "WallParent"; //wallParentObj.GetComponent<MeshRenderer>().material.color = wallColor; //wallParentTempObj = wallParentObj; //GameObject mapParentObj = GameObject.CreatePrimitive(PrimitiveType.Cube); //mapParentObj.transform.localPosition = Vector3.zero; //Destroy(mapParentObj.GetComponent<BoxCollider>()); //mapParentObj.name = "MapParent"; //mapParentTempObj = mapParentObj; //float baseY = 3f; ////加载地图 //for (int i = 0; i < mapClass.gridList.Count; i++) //{ // GridClass gridClass = mapClass.gridList[i]; // if (gridClass.type == 0) // { // GameObject obj = Instantiate(gridItemObj); // obj.transform.SetParent(wallParentObj.transform); // obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, baseY + 0f, gridClass.gridIndex.z); // obj.transform.localScale = new Vector3(1f, 0.5f, 1f); // GridItem gridInfo = obj.GetComponent<GridItem>(); // gridInfo.Init(gridClass, fillColor); // //mapObjList.Add(obj); // gridInfo.isOpenCollision = false; // GameObject wallObj = Instantiate(wallItemObj); // wallObj.transform.SetParent(wallParentObj.transform); // wallObj.transform.localPosition = new Vector3(gridClass.gridIndex.x, baseY + 0.5f, gridClass.gridIndex.z); // wallObj.transform.localScale = new Vector3(1f, 0.5f, 1f); // GridItem gridInfo2 = wallObj.GetComponent<GridItem>(); // gridInfo2.InitWall(wallColor); // //mapObjList.Add(wallObj); // } // else // { // GameObject obj = Instantiate(gridItemObj); // obj.transform.SetParent(mapParentObj.transform); // obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, baseY + 0f, gridClass.gridIndex.z); // obj.transform.localScale = new Vector3(1f, 0.5f, 1f); // GridItem gridInfo = obj.GetComponent<GridItem>(); // gridInfo.Init(gridClass, fillColor); // //mapObjList.Add(obj); // Vector3 mapIntVec = obj.transform.localPosition; // mapVecToItemDic.Add(new Vector3(Mathf.Round(mapIntVec.x), baseY + 0f, Mathf.Round(mapIntVec.z)), gridInfo); // gridInfo.isOpenCollision = true; // mapGridList.Add(gridClass.index); // if (gridClass.type == 2) // { // if (initBallPos == outBorderVec) // { // initBallPos = gridClass.gridIndex; // } // } // balkVecList.Add(gridClass.gridIndex); // } //} //CombineMeshs wallCombineMeshs = wallParentObj.AddComponent<CombineMeshs>(); //wallCombineMeshs.NoMatCombineMeshs(); //wallParentObj.transform.SetParent(mapParentTrm); //wallParentObj.transform.localPosition = new Vector3(0f, -baseY, 0f); //CombineMeshs mapCombineMeshs = mapParentObj.AddComponent<CombineMeshs>(); //mapCombineMeshs.MatCombineMeshs(); //mapParentObj.transform.SetParent(mapParentTrm); //mapParentObj.transform.localPosition = new Vector3(0f, -baseY, 0f); #endregion #region 未优化前加载地图 //加载地图 for (int i = 0; i < mapClass.gridList.Count; i++) { GridClass gridClass = mapClass.gridList[i]; GameObject obj = Instantiate(gridItemObj); obj.transform.SetParent(mapParentTrm); obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, 0f, gridClass.gridIndex.z); obj.transform.localScale = new Vector3(1f, 0.5f, 1f); GridItem gridInfo = obj.GetComponent <GridItem>(); gridInfo.Init(gridClass, fillColor); mapObjList.Add(obj); if (gridClass.type == 0) { gridInfo.isOpenCollision = false; GameObject wallObj = Instantiate(wallItemObj); wallObj.transform.SetParent(mapParentTrm); wallObj.transform.localPosition = new Vector3(gridClass.gridIndex.x, 0.5f, gridClass.gridIndex.z); wallObj.transform.localScale = new Vector3(1f, 0.5f, 1f); GridItem gridInfo2 = wallObj.GetComponent <GridItem>(); gridInfo2.InitWall(wallColor); mapObjList.Add(wallObj); } else { Vector3 mapIntVec = obj.transform.localPosition; //obj.transform.localPosition + transform.localPosition; mapVecToItemDic.Add(new Vector3(Mathf.Round(mapIntVec.x), 0f, Mathf.Round(mapIntVec.z)), gridInfo); gridInfo.isOpenCollision = true; mapGridList.Add(gridClass.index); if (gridClass.type == 2) { if (initBallPos == outBorderVec) { initBallPos = gridClass.gridIndex; } } balkVecList.Add(gridClass.gridIndex); } } #endregion EventSystem.instance.GameMapCreateEndEvent(mapVecToItemDic); ballTrm.position = initBallPos + mapParentTrm.position + Vector3.up * 0.5f; BallGravityCtrl(false); }); }