/// <summary> /// 移动地图 /// </summary> /// <param name="direct"></param> public IEnumerator Move(MapMoveDirect direct) { mIsStopMove = false; while (!mIsStopMove) { mMapCamera.Move(direct); yield return(null); //yield return null; } StopCoroutine("Move"); }
/// <summary> /// 移动 /// </summary> /// <param name="direct"></param> public void Move(MapMoveDirect direct) { if (mIsScaleChanged) { var viewPortHeight = (int)Camera.orthographicSize * 2; var viewPortWidth = (int)(viewPortHeight * Camera.aspect); mMaxOffsetX = (mMapRectTransform.rect.width - viewPortWidth) / 2; mMaxOffsetY = (mMapRectTransform.rect.height - viewPortHeight) / 2; mIsScaleChanged = false; } //Logger.Debug("mMaxOffsetX:" + mMaxOffsetX); //Logger.Debug("mMaxOffsetY:" + mMaxOffsetY); var currentX = transform.localPosition.x; var currentY = transform.localPosition.y; var newX = currentX; var newY = currentY; switch (direct) { case MapMoveDirect.DOWN: if (currentY > -mMaxOffsetY + MoveStep) { newY = currentY - MoveStep; } break; case MapMoveDirect.UP: if (currentY < mMaxOffsetY - MoveStep) { newY = currentY + MoveStep; } break; case MapMoveDirect.RIGHT: if (currentX < mMaxOffsetX - MoveStep) { newX = currentX + MoveStep; } break; case MapMoveDirect.LEFT: if (currentX > -mMaxOffsetX + MoveStep) { newX = currentX - MoveStep; } break; } transform.localPosition = new Vector3(newX, newY, -10); }