#12 Add conditions for using the camera zoom function

This commit is contained in:
NTG 2023-08-08 02:23:37 +09:00
parent 517ebcf21f
commit ea03670618
3 changed files with 46 additions and 4 deletions

View File

@ -140,6 +140,17 @@ public partial class @BlueWater: IInputActionCollection2, IDisposable
""action"": ""Rotate"", ""action"": ""Rotate"",
""isComposite"": false, ""isComposite"": false,
""isPartOfComposite"": false ""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""4bc83c87-5345-4fb2-b39a-ac975f7bf47e"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Rotate"",
""isComposite"": false,
""isPartOfComposite"": false
} }
] ]
} }

View File

@ -118,6 +118,17 @@
"action": "Rotate", "action": "Rotate",
"isComposite": false, "isComposite": false,
"isPartOfComposite": false "isPartOfComposite": false
},
{
"name": "",
"id": "4bc83c87-5345-4fb2-b39a-ac975f7bf47e",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "Rotate",
"isComposite": false,
"isPartOfComposite": false
} }
] ]
} }

View File

@ -80,12 +80,29 @@ namespace BlueWaterProject
/// <summary> /// <summary>
/// New input system을 이용한 줌 인, 아웃 기능 /// New input system을 이용한 줌 인, 아웃 기능
/// </summary> /// </summary>
public void OnZoom(InputAction.CallbackContext context) private void OnZoom(InputAction.CallbackContext context)
{ {
if (!UsableZoom()) return;
var scrollValue = Mouse.current.scroll.ReadValue().normalized.y; var scrollValue = Mouse.current.scroll.ReadValue().normalized.y;
desiredZoom = Mathf.Clamp(desiredZoom - scrollValue * zoomSpeed, minZoom, maxZoom); desiredZoom = Mathf.Clamp(desiredZoom - scrollValue * zoomSpeed, minZoom, maxZoom);
} }
/// <summary>
/// Zoom 기능을 사용가능한 상태인지 확인하는 기능
/// </summary>
private bool UsableZoom()
{
var mousePos = Input.mousePosition;
// 백그라운드 실행이 아닌, 게임 화면을 실행한 상태인지 체크
var isFocusedGame = Application.isFocused;
// 화면 내에 마우스가 존재하는지 체크
var isMouseWithinGameScreen = mousePos.x >= 0 && mousePos.x <= Screen.width &&
mousePos.y >= 0 && mousePos.y <= Screen.height;
return isFocusedGame && isMouseWithinGameScreen;
}
/// <summary> /// <summary>
/// 자연스러운 줌 인, 아웃 기능 /// 자연스러운 줌 인, 아웃 기능
/// </summary> /// </summary>
@ -93,7 +110,8 @@ namespace BlueWaterProject
{ {
if (Mathf.Approximately(islandCamera.fieldOfView, desiredZoom)) return; if (Mathf.Approximately(islandCamera.fieldOfView, desiredZoom)) return;
islandCamera.fieldOfView = Mathf.Lerp(islandCamera.fieldOfView, desiredZoom, Time.deltaTime * zoomSpeed); islandCamera.fieldOfView = Mathf.Lerp(islandCamera.fieldOfView, desiredZoom,
Time.deltaTime * zoomSpeed);
if (islandCamera.fieldOfView > desiredZoom) return; if (islandCamera.fieldOfView > desiredZoom) return;
@ -107,11 +125,13 @@ namespace BlueWaterProject
if (myPos.y > max) if (myPos.y > max)
{ {
transform.position = Vector3.Lerp(transform.position, new Vector3(myPos.x, max, myPos.z), Time.deltaTime * zoomSpeed); transform.position = Vector3.Lerp(transform.position, new Vector3(myPos.x, max, myPos.z),
Time.deltaTime * zoomSpeed);
} }
else if (myPos.y < min) else if (myPos.y < min)
{ {
transform.position = Vector3.Lerp(transform.position, new Vector3(myPos.x, min, myPos.z), Time.deltaTime * zoomSpeed); transform.position = Vector3.Lerp(transform.position, new Vector3(myPos.x, min, myPos.z),
Time.deltaTime * zoomSpeed);
} }
} }