WXMC/.svn/pristine/74/74e6c54e5554cccda723c286d47489dc8dad45b4.svn-base
2024-12-04 16:18:46 +08:00

67 lines
1.4 KiB
Plaintext

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public class SlideTimeline : Slidable
{
[SerializeField]
private PlayableDirector m_director;
[SerializeField]
private PlayableAsset m_animation;
[SerializeField]
private bool m_loop;
[SerializeField]
private float m_slideSpeed;
[SerializeField]
[Range(0.0f, 1.0f)]
private float m_slidePercent = 0.0f;
private void Start()
{
m_director.playOnAwake = false;
m_director.Pause();
m_director.playableAsset = m_animation;
}
public override void OnStartInteract(Touch touch)
{
base.OnStartInteract(touch);
m_director.Play();
}
public override void OnEndInteract(Touch touch)
{
base.OnEndInteract(touch);
m_director.Pause();
}
public override void Slide(float delta)
{
base.Slide(delta);
float percent_delta = delta * m_slideSpeed;
m_slidePercent += percent_delta;
if (m_loop)
{
if (m_slidePercent > 1.0f)
{
m_slidePercent -= 1.0f;
}
else if (m_slidePercent < 0.0f)
{
m_slidePercent += 1.0f;
}
}
float total_time = (float)m_animation.duration;
m_director.time = total_time * m_slidePercent;
}
}