//拖拽位置创建 public static void CreateManorGoByDrag(CSDrag csDrag, Action <SCDrag> ResponseSCDragCallBack) { if (StaticData.IsUsedLocalDataNotServer) { //测试 SCDrag scDrag = new SCDrag() { SoilId = 1002 }; ResponseSCDragCallBack(scDrag); } else { ProtocalManager.Instance().SendCSDrag(csDrag, ResponseSCDragCallBack, (error) => { }, false); } }
// Update is called once per frame void Update() { if (Root2dSceneManager._instance.currHandleTile != this.gameObject) { return; } var worldComponent = Root2dSceneManager._instance.worldCameraComponent; var clickObj = StaticData.UI_GetCurrentSelect(); bool isUIScrollMask = false; bool isUIDecorateMask = false; if (clickObj != null)//表明是UI { isUIScrollMask = clickObj.CompareTag(TagHelper.UIScrollMask); isUIDecorateMask = clickObj.CompareTag(TagHelper.DecorateUIMask); } if (!isDrag && Input.GetMouseButtonUp(0) && (clickObj == null || isUIScrollMask || isUIDecorateMask))//鼠标抬起 { //关闭掉正在处理的装饰物 if (isUIDecorateMask && StaticData.GetUIWorldHandleComponent().isRotatingDecorate) { StaticData.GetUIWorldHandleComponent().OnButtonRotateOKClick(false); StaticData.GetUIWorldHandleComponent().SetHandleTileUIClose(); } isPress = false; isDrag = false; isLongPress = false; if (timeCurrPress > timeOnClickMinThreshold && timeCurrPress <= timeLongPressThreshold) { StaticData.DebugGreen("触发小地块点击"); OnTileClick(); } timeCurrPress = 0f; } else if (isDrag) { //正在拖拽,判定是否小于边缘 EnumDirection direction = EnumDirection.None; for (int i = 0; i < worldComponent.listDirection.Count; i++) { float xDir = worldComponent.listDirection[i].x; float yDir = worldComponent.listDirection[i].y; var newPos = Input.mousePosition + new Vector3(xDir, yDir, 0) * ManorCameraWorldComponent.SizeScreenToSide; //四个方向判定 if (newPos.x <= 0f) { direction = EnumDirection.Left; break; } else if (newPos.x >= Screen.width) { direction = EnumDirection.Right; break; } else if (newPos.y <= 0f) { direction = EnumDirection.Bottom; break; } else if (newPos.y >= Screen.height) { direction = EnumDirection.Up; break; } } if (direction != EnumDirection.None)//表示是自动滑动 { worldComponent.TriggerAutoScroll(direction); } else {//改变了方向 worldComponent.EndAutoScroll(); } } //只要鼠标抬起,就停止自动滚动 if (Input.GetMouseButtonUp(0))//滑动过程中鼠标抬起也终止自动滑动 { worldComponent.EndAutoScroll(); } if (isPress && !isDrag) { timeCurrPress += Time.deltaTime; //小地块滑动 if (Vector2.Distance(tileMousePos, Input.mousePosition) <= 10f)//10f做为滑动的阈值 { if (timeCurrPress >= timeLongPressThreshold) { if (!Root2dSceneManager._instance.isFriendManor)//好友庄园不能长按拖动 { //正在处理装饰物 if (StaticData.GetUIWorldHandleComponent().isRotatingDecorate&& typeTile == TypeManorDecorate.Decorate) { isPress = false; return; } isLongPress = true; StaticData.DebugGreen("触发小地块拖动"); BeginDrag(true); } } } } if (isBeginPlace && Input.GetMouseButton(0))//鼠标按住处理 { SetTilePos(false); //播放完抬起动画再检查 if (isUpAnimPlaying == false) { CheckIsCanPlace(() => { //显示红色箭头 TipsTileComponent._instance.SetCanPlace(transform, false, this); }, () => { //显示蓝色箭头 TipsTileComponent._instance.SetCanPlace(transform, true, this); }); } } if (Input.GetMouseButtonUp(0))//鼠标抬起 { ctsWaitPlayUpAnim?.Cancel(); isUpAnimPlaying = false; //庄园角色移动,继续气泡播放 if (isNPC) { Root2dSceneManager._instance.GetManorBubbleComponent().ResetBeginAnimByTime(); } //关闭提示 TipsTileComponent._instance.CloseAll(); //打开Manor UI UIManorComponent uiManorComponent = UIComponent.GetComponentHaveExist <UIManorComponent>(UIType.UIManor); uiManorComponent.DragTileOrDecorateCloseSelfManor(false); TipsTileComponent._instance.CloseUpAnim(); ResetHandleVar(); if (GoUIRootScroll != null) { GoUIRootScroll.SetActive(true); } CheckIsCanPlace(() => { if (isBeginPlace == false) { return; } CancelPlaceHandle(); isBeginPlace = false; return; }, () => { if (isBeginPlace == false) { return; } isBeginPlace = false; //放置的时候排序 Root2dSceneManager._instance.UpdateSortLayer(true); if (!this.isDragFromScene)//创建过程 { CSDrag csDrag = new CSDrag() { Type = (int)DecorateType, Xaxle = transform.localPosition.x, Yaxle = transform.localPosition.y, GoodId = this.CropGoodId }; ManorProtocalHelper.CreateManorGoByDrag(csDrag, (scDrag) => { //设置id this.SoilId = scDrag.SoilId; //地块使用数+1 //可以放置,地块数量变化 if (DecorateType == TypeManorDecorate.Tile && this.CropGoodId == 0) { //扣除货币 StaticData.UpdateWareHouseItem(Root2dSceneManager._instance.dealClassCurrency.IdGameItem, -Root2dSceneManager._instance.dealClassCurrency.Price); } else if (DecorateType == TypeManorDecorate.Decorate && this.CropGoodId != 0) { StaticData.DecorateMinusOne(this.CropGoodId); uiManorComponent.RefreshDecorateList(); //拖拽生成装饰物 StaticData.GetUIWorldHandleComponent().OpenRebackDecorate(this); } }); } else { //移动位置 CSChangeLocation csChangeLocation = new CSChangeLocation() { SoilId = this.SoilId, Xaxle = transform.localPosition.x, Yaxle = transform.localPosition.y }; ManorProtocalHelper.MoveManorGo(csChangeLocation, (succ) => { }); } }); } }
public void SendCSDrag(CSDrag csdrag, Action <SCDrag> ResponseSCDragCallBack, Action <ErrorInfo> errorCallBack, bool isShowDefaultTip = true) { OpCodeType opCodeType = ListOPRelation.GetOpCodeTypeByRequest <CSDrag> (); ProtoSendMethod.BusinessRequest <SCDrag>(csdrag, opCodeType, ResponseSCDragCallBack, errorCallBack, isShowDefaultTip); }