From ec231f4110c782d44ea2820a1eaaa7a5711c6f16 Mon Sep 17 00:00:00 2001 From: smchoi <ws5260@naver.com> Date: 수, 24 7월 2024 13:29:47 +0900 Subject: [PATCH] Add : 카메라 줌인& 줌아웃 기능 추가 --- Assets/Korail/Scripts/Action/ActionButton.cs | 80 +++++++++++---------------------------- 1 files changed, 23 insertions(+), 57 deletions(-) diff --git a/Assets/Korail/Scripts/Action/ActionButton.cs b/Assets/Korail/Scripts/Action/ActionButton.cs index 4ac6c65..9305652 100644 --- a/Assets/Korail/Scripts/Action/ActionButton.cs +++ b/Assets/Korail/Scripts/Action/ActionButton.cs @@ -1,6 +1,8 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Animations; public class ActionButton : MonoBehaviour { @@ -12,17 +14,23 @@ /// <summary> /// 애니메이션 속도 /// </summary> - public float Speed =1; + public float Speed; /// <summary> /// 애니메이션 목표 회전값(Euler) 또는 목표 좌표 /// </summary> public Vector3 TargetRot; + /// <summary> + /// 이동 애니메이션 여부 + /// true면 이동 false면 회전 애니메이션 + /// </summary> + public bool isFixed; - public bool isFixed = false; - public float waitForSecond = 0.5f; + private Quaternion targetRot; + + private Quaternion initRot; private Vector3 targetPos; @@ -36,20 +44,16 @@ private bool isEnd; /// <summary> - /// 코루틴이 시작했는지 여부 - /// </summary> - private bool isStart = false; - - - - /// <summary> /// 애니메이션 종료를 시작값으로(VR에서만) /// </summary> public bool VREndStart; void Start() { + + targetPos = TargetRot; initPos = transform.localPosition; + Initialize(); } @@ -68,16 +72,13 @@ void EndInit() { - transform.localPosition = targetPos; isEnd = true; } void Init() { - transform.localPosition = initPos; - isEnd = false; } @@ -106,60 +107,25 @@ { t += Speed * Time.deltaTime; - if (!isFixed) + if (isEnd) { - if(!isEnd && !isStart) + // 초기 좌표까지 애니메이션 + transform.localPosition = Vector3.Lerp(transform.localPosition, initPos, t); + if (transform.localPosition == initPos) { - isStart = true; - StartCoroutine(MoveEndAndInit()); + InitValues(false); } - } else { - if (isEnd) + // 목표 좌표까지 애니메이션 + transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, t); + if (transform.localPosition == targetPos) { - // 초기 좌표까지 애니메이션 - MoveInitPos(); - } - else - { - // 목표 좌표까지 애니메이션 - MoveEndPos(); + InitValues(true); } } - - - } - } - - private void MoveEndPos() - { - - transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, t); - if (transform.localPosition == targetPos) - { - InitValues(true); - } - } - - private void MoveInitPos() - { - transform.localPosition = Vector3.Lerp(transform.localPosition, initPos, t); - if (transform.localPosition == initPos) - { - InitValues(false); - } - } - - - IEnumerator MoveEndAndInit() - { - MoveEndPos(); - yield return new WaitForSeconds(waitForSecond); - MoveInitPos(); - isStart = false; } } -- Gitblit v1.8.0