private void UpdateBoard() { BoardInfo boardInfoLeft = CreateBoardInfo(PlayerConstant.Position.Left); BoardInfo boardInfoRight = CreateBoardInfo(PlayerConstant.Position.Right); BallInfo ballInfo = CreateBallInfo(); boardInfoLeft = boardController[(int)Pong.PlayerConstant.Position.Left].MoveBoard( boardInfoLeft, ballInfo); boardLeftRigidbody.position = ToVector2(boardInfoLeft.Position); boardInfoRight = boardController[(int)Pong.PlayerConstant.Position.Right].MoveBoard( boardInfoRight, ballInfo); boardRightRigidbody.position = ToVector2(boardInfoRight.Position); }
/// <summary> /// ボードの移動処理 /// </summary> /// <param name="board">現在のボード情報</param> /// <param name="ball">現在のボール情報</param> /// <returns>移動した後のボード情報を返す</returns> public BoardInfo MoveBoard(BoardInfo board, BallInfo ball) { if (ball == null) { return(board); } Vector3 boardPosition = board.Position; Vector3 ballPosition = ball.Position; float boardMargin = board.Height / BoardMarginDivision; if (IsAllowableRangePosition(ballPosition.y, boardPosition.y, boardMargin)) { // 誤差含めて範囲内なら何もしない return(board); } // 移動 return(Move(board, ballPosition, boardPosition)); }
/// <summary> /// 移動 /// </summary> /// <param name="board">自分の板情報</param> /// <param name="ball">ボール情報</param> /// <returns>移動した後の板の情報</returns> public BoardInfo MoveBoard(BoardInfo board, BallInfo ball) { //Debug.Log(string.Format("board x = {0} y = {1} z = {2}", // board.Position.x, board.Position.y, board.Position.z)); //Debug.Log(string.Format("ball x = {0} y = {1} z = {2}", // ball.Position.x, ball.Position.y, ball.Position.z)); if (touchAction.IsDragging()) { // タッチ中 if (isTracingEnable) { // タッチのY座標だけ追従する Vector3 touchPosition = touchAction.GetTouchPosition(camera); Vector3 boardPosition = board.Position; boardPosition.y = touchPosition.y; return(new BoardInfo(board.Height, boardPosition)); } } if (touchAction.IsTouchBegan()) { Vector3 touchPosition = touchAction.GetTouchPosition(camera); // タッチを開始したときに範囲内ならバーの追従を開始 if ((position == PlayerConstant.Position.Left) && (touchPosition.x < 0)) { isTracingEnable = true; return(board); } if ((position == PlayerConstant.Position.Right) && (touchPosition.x > 0)) { isTracingEnable = true; return(board); } } // タッチ終了、あるいはキャンセルなどされていたら追従を終了 isTracingEnable = false; return(board); }