using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Animations;
public class ActionButton : MonoBehaviour
{
///
/// ¾Ö´Ï¸ÞÀÌ¼Ç ½ÇÇà ¿©ºÎ
///
public bool Run;
///
/// ¾Ö´Ï¸ÞÀÌ¼Ç ¼Óµµ
///
public float Speed;
///
/// ¾Ö´Ï¸ÞÀÌ¼Ç ¸ñÇ¥ ȸÀü°ª(Euler) ¶Ç´Â ¸ñÇ¥ ÁÂÇ¥
///
public Vector3 TargetRot;
///
/// À̵¿ ¾Ö´Ï¸ÞÀÌ¼Ç ¿©ºÎ
/// true¸é À̵¿ false¸é ȸÀü ¾Ö´Ï¸ÞÀ̼Ç
///
public bool isFixed;
private Quaternion targetRot;
private Quaternion initRot;
private Vector3 targetPos;
private Vector3 initPos;
private float t;
///
/// ¾Ö´Ï¸ÞÀÌ¼Ç Á¾·á ¿©ºÎ
///
private bool isEnd;
///
/// ¾Ö´Ï¸ÞÀÌ¼Ç Á¾·á¸¦ ½ÃÀÛ°ªÀ¸·Î(VR¿¡¼¸¸)
///
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(isFixed)
{
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);
}
}
} else
{
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)
{
isEnd = true;
t = 0;
}
}
}
}
}
}