using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AnimationTruck : MonoBehaviour
{
public Animation ani;
public string clip_name;
public float ani_time;
[Header("Animation Slider")]
[SerializeField] Slider AnimationSlider;
[SerializeField] float speed;
private void Start()
{
Hide();
if (AnimationSlider != null)
{
AnimationSlider.maxValue = ani[clip_name].length;
AnimationSlider.onValueChanged.AddListener(delegate
{ OnChangeAnimationBySlider(AnimationSlider);
});
}
}
void OnChangeAnimationBySlider(Slider slider)
{
if (!ani.isPlaying)
{
ani.Play();
ani[clip_name].speed = 0;
}
//ani[clip_name].speed = speed;
ani[clip_name].time = slider.value;
}
public void ToggleAnimation(Toggle m_toggle)
{
if (m_toggle.isOn)
{
Show();
}
else
{
Hide();
}
}
private void Update()
{
if (AnimationSlider == null)
return;
if (AnimationSlider.value != ani[clip_name].time)
{
AnimationSlider.value = ani[clip_name].time;
}
}
public void Hide()
{
//if (ani_time == ani[clip_name].length)
// return;
ani_time = ani[clip_name].time;
func_playAni(ani_time, clip_name);
}
public void Show()
{
if (ani_time == 0)
ani_time = ani[clip_name].length;
else
ani_time = ani[clip_name].time;
func_reversPlay(ani_time, clip_name);
}
public void func_playAni(float time, string aniName)
{
ani[aniName].time = time;
ani[aniName].speed = speed;
ani.Play();
}
public void func_reversPlay(float time, string aniName)
{
ani[aniName].time = time;
ani[aniName].speed = -speed;
ani.Play();
}
}
댓글 없음:
댓글 쓰기