using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.Animations;
|
|
public class ActionButton : MonoBehaviour
|
{
|
/// <summary>
|
/// ¾Ö´Ï¸ÞÀÌ¼Ç ½ÇÇà ¿©ºÎ
|
/// </summary>
|
public bool Run;
|
|
/// <summary>
|
/// ¾Ö´Ï¸ÞÀÌ¼Ç ¼Óµµ
|
/// </summary>
|
public float Speed;
|
|
/// <summary>
|
/// ¾Ö´Ï¸ÞÀÌ¼Ç ¸ñÇ¥ ȸÀü°ª(Euler) ¶Ç´Â ¸ñÇ¥ ÁÂÇ¥
|
/// </summary>
|
public Vector3 TargetRot;
|
|
/// <summary>
|
/// À̵¿ ¾Ö´Ï¸ÞÀÌ¼Ç ¿©ºÎ
|
/// true¸é À̵¿ false¸é ȸÀü ¾Ö´Ï¸ÞÀ̼Ç
|
/// </summary>
|
public bool isFixed;
|
|
|
private Quaternion targetRot;
|
|
private Quaternion initRot;
|
|
private Vector3 targetPos;
|
|
private Vector3 initPos;
|
|
private float t;
|
|
/// <summary>
|
/// ¾Ö´Ï¸ÞÀÌ¼Ç Á¾·á ¿©ºÎ
|
/// </summary>
|
private bool isEnd;
|
|
/// <summary>
|
/// ¾Ö´Ï¸ÞÀÌ¼Ç Á¾·á¸¦ ½ÃÀÛ°ªÀ¸·Î(VR¿¡¼¸¸)
|
/// </summary>
|
public bool VREndStart;
|
|
void Start()
|
{
|
|
targetPos = TargetRot;
|
initPos = transform.localPosition;
|
|
Initialize();
|
}
|
|
void Initialize()
|
{
|
if (VREndStart && SceneTypeManager.Inst.IsVRMode)
|
{
|
EndInit();
|
}
|
else
|
{
|
Init();
|
}
|
}
|
|
|
void EndInit()
|
{
|
transform.localPosition = targetPos;
|
isEnd = true;
|
}
|
|
void Init()
|
{
|
transform.localPosition = initPos;
|
isEnd = false;
|
}
|
|
public void Play()
|
{
|
if (Run)
|
{
|
isEnd = !isEnd;
|
t = 0;
|
}
|
|
Run = true;
|
}
|
|
void InitValues(bool end)
|
{
|
Run = false;
|
isEnd = end;
|
t = 0;
|
}
|
|
|
void Update()
|
{
|
if (Run)
|
{
|
t += Speed * Time.deltaTime;
|
|
if (isEnd)
|
{
|
// Ãʱâ ÁÂÇ¥±îÁö ¾Ö´Ï¸ÞÀ̼Ç
|
transform.localPosition = Vector3.Lerp(transform.localPosition, initPos, t);
|
if (transform.localPosition == initPos)
|
{
|
InitValues(false);
|
}
|
}
|
else
|
{
|
// ¸ñÇ¥ ÁÂÇ¥±îÁö ¾Ö´Ï¸ÞÀ̼Ç
|
transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, t);
|
if (transform.localPosition == targetPos)
|
{
|
InitValues(true);
|
}
|
}
|
|
}
|
}
|
}
|