/// <summary> /// 拖动结束 /// </summary> public void OnDragEnd() { if (canMove == false || m_type == Config.PieceType.K) { return; } m_isTipsShow = false; var px = m_target.transform.position.x - m_beginPos.x; var pz = m_target.transform.position.z - m_beginPos.z; var d = Math.Sqrt(px * px + pz * pz); var dx = Math.Abs(px); var dz = Math.Abs(pz); int xblock = (int)Math.Round(dx / Config.PieceWidth, 0); int zblock = (int)Math.Round(dz / Config.PieceWidth, 0); var dir = GetDirectByDeltaXZ(px, pz); Vector2 to = new Vector2(m_X + xblock * dir.x, m_Z + zblock * dir.y); if (d >= Config.MoveDistance && to.x <= 8 && to.x >= 1 && to.y >= 1 && to.y <= 8)//todo 不能直接套用 { var tempEat = App.ChessLogic02.GetPiece(to.x - 1, to.y - 1); m_body = new object[] { m_X, m_Z, m_mediator.pieceData.color, to, tempEat }; if (App.ChessLogic02.DoMove(new Vector2(m_X - 1, m_Z - 1), new Vector2(to.x - 1, to.y - 1))) { var piece = App.ChessLogic02.GetPiece((int)to.x - 1, (int)to.y - 1);//移动后的棋子 var indexFrom = CoorToIndex((int)m_X, (int)m_Z); var indexTo = CoorToIndex((int)to.x, (int)to.y); ActiveInfo.Builder activeInfo = ActiveInfo.CreateBuilder(); MoveInfo.Builder moveInfo = MoveInfo.CreateBuilder(); moveInfo.SetFrom(indexFrom); moveInfo.SetTo(indexTo); moveInfo.SetUserId(m_UserProxy.GetPlayerId()); activeInfo.SetIsCall(false); activeInfo.SetMoveInfo(moveInfo); m_mediator.NotityDragEnd(activeInfo); object[] args = new object[] { new Vector2(m_X, m_Z), to, new Vector2(-1, tempEat) };//0:from, 1:to, 2.x:兵生变类型 -1为没有, 2.y:吃棋信息 ShowMove(args); StopFlash(); App.SoundManager.PlaySoundClip(Config.Sound.DragSuccess); } else { SetPiecePos(m_X, m_Z); m_mediator.NotityDragEnd(null);//不能移动 App.SoundManager.PlaySoundClip(Config.Sound.DragFail); } } else { SetPiecePos(m_X, m_Z); m_mediator.NotityDragEnd(null);//距离不够 驳回 } m_target.SetActive(false); }
public void OnModelClick(Vector3 clickPoint) { if (m_selectType > -1) { var pointX = clickPoint.x; var pointZ = clickPoint.z; var offsetX = pointX % 2; var offsetZ = pointZ % 2; var x = (pointX - offsetX) / 2; var z = (pointZ - offsetZ) / 2; var point = new Vector2(x, z); if (canNext == true && App.ChessLogic02.DoSummon(point, m_selectType)) { Debug.Log("召唤成功"); var type = m_selectType % 10; m_mediator.Energy -= Config.PieceCost[type]; if (m_isTest == false) { ActiveInfo.Builder activeInfo = ActiveInfo.CreateBuilder(); activeInfo.SetIsCall(true); CallInfo.Builder callInfo = CallInfo.CreateBuilder(); callInfo.SetIndex(CoorToIndex((int)(x + 1), (int)(z + 1))); callInfo.SetType(type); callInfo.SetUserId(m_proxy.GetPlayerId()); activeInfo.SetCallInfo(callInfo); m_mediator.NotifyPlayerActive(activeInfo); } OnSummon(m_selectType, new Vector2(point.x + 1, point.y + 1)); } else { Debug.Log("召唤失败"); } m_selectType = -1; OnSummonTipsHide(); OnEnergyEffectHide(); } else { var pointX = clickPoint.x; var pointZ = clickPoint.z; var offsetX = pointX % 2; var offsetZ = pointZ % 2; var x = (pointX - offsetX) / 2; var z = (pointZ - offsetZ) / 2; var point = new Vector2(x + 1, z + 1); m_mediator.NotifyPieceClick(point); } }