| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.Animations; |
| | | |
| | | public class ActionButton : MonoBehaviour |
| | | { |
| | |
| | | /// <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; |
| | | |
| | |
| | | private bool isEnd; |
| | | |
| | | /// <summary> |
| | | /// 코루틴이 시작했는지 여부 |
| | | /// </summary> |
| | | private bool isStart = false; |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 애니메이션 종료를 시작값으로(VR에서만) |
| | | /// </summary> |
| | | public bool VREndStart; |
| | | |
| | | void Start() |
| | | { |
| | | initPos = transform.localPosition; |
| | | |
| | | targetPos = TargetRot; |
| | | initPos = transform.localPosition; |
| | | |
| | | |
| | | |
| | | Initialize(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | void EndInit() |
| | | { |
| | | if (!isFixed) |
| | | { |
| | | transform.localRotation = targetRot; |
| | | |
| | | transform.localPosition = targetPos; |
| | | } |
| | | else |
| | | { |
| | | transform.localPosition = targetPos; |
| | | |
| | | } |
| | | isEnd = true; |
| | | } |
| | | |
| | | void Init() |
| | | { |
| | | if (!isFixed) |
| | | { |
| | | transform.localRotation = initRot; |
| | | |
| | | transform.localPosition = initPos; |
| | | } |
| | | else |
| | | { |
| | | transform.localPosition = initPos; |
| | | |
| | | } |
| | | isEnd = false; |
| | | } |
| | | |
| | |
| | | if (Run) |
| | | { |
| | | t += Speed * Time.deltaTime; |
| | | |
| | | if (!isFixed) |
| | | { |
| | | if(!isEnd && !isStart) |
| | | if (isEnd) |
| | | { |
| | | isStart = true; |
| | | StartCoroutine(MoveEndAndInit()); |
| | | // 초기 회전값까지 애니메이션 |
| | | transform.localRotation = Quaternion.Slerp(transform.localRotation, initRot, t); |
| | | if (transform.localRotation == initRot) |
| | | { |
| | | InitValues(false); |
| | | } |
| | | } |
| | | |
| | | else |
| | | { |
| | | // 목표 회전값까지 애니메이션 |
| | | transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRot, t); |
| | | if (transform.localRotation == targetRot) |
| | | { |
| | | InitValues(true); |
| | | |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (isEnd) |
| | | { |
| | | // 초기 좌표까지 애니메이션 |
| | | MoveInitPos(); |
| | | transform.localPosition = Vector3.Lerp(transform.localPosition, initPos, t); |
| | | if (transform.localPosition == initPos) |
| | | { |
| | | InitValues(false); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 목표 좌표까지 애니메이션 |
| | | MoveEndPos(); |
| | | transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, t); |
| | | if (transform.localPosition == targetPos) |
| | | { |
| | | 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; |
| | | } |
| | | } |