Exemple #1
0
 /// <summary>
 /// 建造 确认 or 取消
 /// </summary>
 /// <param name="confirm"></param>
 private void OnBuildConfirm(bool confirm)
 {
     if (confirm)
     {
         if (!IsoMap.Instance.CanPlaceBuilding(currentBuilding.GetTilePos().x, currentBuilding.GetTilePos().y,
                                               currentBuilding.width, currentBuilding.height))
         {
             return;//TODO alert sound
         }
         //send to server
         GameManager.Instance.RequestBuyBuilding(currentBuilding);
         if (isConstructMulti)
         {
             TilePoint?suggestPoint = null;
             if (lastPoint != null)
             {
                 var delta = currentBuilding.GetTilePos() - lastPoint.Value;
                 if (Mathf.Abs(delta.x) + Mathf.Abs(delta.y) == currentBuilding.width) //只有在挨着的时候才处理
                 {
                     var newPoint = currentBuilding.GetTilePos() + delta;
                     if (IsoMap.Instance.CanPlaceBuilding(newPoint.x, newPoint.y, currentBuilding.width,
                                                          currentBuilding.height))
                     {
                         suggestPoint = newPoint;
                     }
                 }
             }
             if (suggestPoint == null && currentBuilding.model.entityType == EntityType.Wall)
             {
                 //判断当前建筑四周是否有墙
                 var currPoint = currentBuilding.GetTilePos();
                 if (IsoMap.Instance.IsWallStrict(currPoint.x - 2, currPoint.y))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(2, 0));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x + 2, currPoint.y))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(-2, 0));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x, currPoint.y - 2))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(0, 2));
                 }
                 else if (IsoMap.Instance.IsWallStrict(currPoint.x, currPoint.y + 2))
                 {
                     suggestPoint = SuggestPosition(currPoint + new TilePoint(0, -2));
                 }
             }
             if (suggestPoint == null)
             {
                 suggestPoint = SuggestPosition(currentBuilding.GetTilePos());
             }
             lastPoint = currentBuilding.GetTilePos();
             var tileEntity = TileEntity.Create(OwnerType.Defender, currentBuilding.model);
             tileEntity.Init();
             BuildCompleteCleanUp();//清除上一次的建造
             SetBuildingObject(tileEntity, isConstructMulti, suggestPoint);
         }
         else
         {
             lastPoint = currentBuilding.GetTilePos();
             BuildCompleteCleanUp();
         }
     }
     else
     {
         currentBuilding.Destroy();
         BuildCompleteCleanUp();
     }
 }