213 lines
5.7 KiB
C#
213 lines
5.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.Playables;
|
||
using UnityEngine.Timeline;
|
||
using UnityEngine.UI;
|
||
|
||
public class timelineCtrl : MonoBehaviour
|
||
{
|
||
public Slider sliderS;
|
||
public Slider sliderM;
|
||
public Slider sliderQ;
|
||
public GameObject s;
|
||
public GameObject m;
|
||
public GameObject q;
|
||
public GameObject s1;
|
||
public GameObject m1;
|
||
public GameObject q1;
|
||
public TimelineAsset timeline;
|
||
public PlayableDirector timeplayer;
|
||
|
||
int GCnQD = 0;
|
||
private bool isDragging = false;
|
||
|
||
// Start is called before the first frame update
|
||
void Awake()
|
||
{
|
||
sliderS.onValueChanged.AddListener(OnSliderValueChanged);
|
||
sliderQ.onValueChanged.AddListener(OnSliderValueChanged);
|
||
}
|
||
|
||
private void FixedUpdate()
|
||
{
|
||
if (sliderS.gameObject.activeSelf && !isDragging)
|
||
{
|
||
SliderChengaG();
|
||
}
|
||
if (sliderQ.gameObject.activeSelf && !isDragging)
|
||
{
|
||
SliderChengaQ();
|
||
}
|
||
}
|
||
// 当Slider的值发生改变时会调用这个方法
|
||
private void OnSliderValueChanged(float value)
|
||
{
|
||
if (timeplayer != null && isDragging)
|
||
{
|
||
// 当拖动Slider时,让Timeline同步Slider的进度
|
||
if (sliderS.gameObject.activeSelf)
|
||
{
|
||
SliderChengaG2();
|
||
}
|
||
if (sliderQ.gameObject.activeSelf)
|
||
{
|
||
SliderChengaQ2();
|
||
}
|
||
}
|
||
//Debug.Log("Slider被滑动了,当前值为: " + value);
|
||
}
|
||
public void SliderChengaG()
|
||
{
|
||
if (timeplayer.time < 70)
|
||
{
|
||
sliderS.value = ((float)timeplayer.time / 70f) * 0.3761377f;
|
||
}
|
||
if (timeplayer.time > 70 && timeplayer.time < 136)
|
||
{
|
||
sliderS.value = Mathf.Lerp(0.4191301f, 0.6868095f, ((float)timeplayer.time - 70) / (float)(136 - 70));
|
||
}
|
||
if (timeplayer.time > 136 && timeplayer.time < 181)
|
||
{
|
||
sliderS.value = Mathf.Lerp(.73f, 1, ((float)timeplayer.time - 136) / (float)(181 - 136));
|
||
}
|
||
}
|
||
public void SliderChengaG2()
|
||
{
|
||
if (sliderS.value < 0.3761377f)
|
||
{
|
||
timeplayer.time = (sliderS.value * 70f) / 0.3761377f;
|
||
}
|
||
if (sliderS.value > 0.4191301f && sliderS.value < 0.6868095f)
|
||
{
|
||
timeplayer.time = 70 + ((sliderS.value - 0.4191301f) / (0.6868095f - 0.4191301f)) * 66f;
|
||
}
|
||
if (sliderS.value > 0.73f )
|
||
{
|
||
timeplayer.time = 136 + ((sliderS.value - 0.73f) / 0.27f) * 45f;
|
||
}
|
||
}
|
||
public void SliderChengaQ()
|
||
{
|
||
if (timeplayer.time < 70)
|
||
{
|
||
sliderQ.value = ((float)timeplayer.time / 70f) * 0.3761377f;
|
||
}
|
||
if (timeplayer.time > 70 && timeplayer.time < 157)
|
||
{
|
||
sliderQ.value = Mathf.Lerp(0.4191301f, 0.6868095f, ((float)timeplayer.time - 70) / (float)(157 - 70));
|
||
}
|
||
if (timeplayer.time > 157 && timeplayer.time < 315)
|
||
{
|
||
sliderQ.value = Mathf.Lerp(.73f, 1, ((float)timeplayer.time - 157) / (float)(315 - 157));
|
||
}
|
||
}
|
||
public void SliderChengaQ2()
|
||
{
|
||
if (sliderQ.value < 0.3761377f)
|
||
{
|
||
timeplayer.time = (sliderQ.value * 70f) / 0.3761377f;
|
||
}
|
||
if (sliderQ.value > 0.4191301f && sliderQ.value < 0.6868095f)
|
||
{
|
||
timeplayer.time = 70 + ((sliderQ.value - 0.4191301f) / (0.6868095f - 0.4191301f)) * 87f;
|
||
}
|
||
if (sliderQ.value > 0.73f)
|
||
{
|
||
timeplayer.time = 157 + ((sliderQ.value - 0.73f) / (1f - 0.73f)) * 158f;
|
||
}
|
||
}
|
||
|
||
// 当开始拖动Slider时调用的方法
|
||
public void OnSliderDragStart()
|
||
{
|
||
isDragging = true;
|
||
timeplayer.Pause();
|
||
}
|
||
|
||
// 当结束拖动Slider时调用的方法
|
||
public void OnSliderDragEnd()
|
||
{
|
||
timeplayer.Play();
|
||
isDragging = false;
|
||
}
|
||
|
||
public void TimeInfo(int a)
|
||
{
|
||
if (timeplayer.time <=70)
|
||
{
|
||
s.SetActive(true);
|
||
m.SetActive(false);
|
||
q.SetActive(false);
|
||
}
|
||
if (timeplayer.time > 70 && timeplayer.time < a)
|
||
{
|
||
s.SetActive(false);
|
||
m.SetActive(true);
|
||
q.SetActive(false);
|
||
}
|
||
if (timeplayer.time > a)
|
||
{
|
||
s.SetActive(false);
|
||
m.SetActive(false);
|
||
q.SetActive(true);
|
||
}
|
||
}
|
||
public void TimeInfo1(int a)
|
||
{
|
||
if (timeplayer.time <= 70)
|
||
{
|
||
s1.SetActive(true);
|
||
m1.SetActive(false);
|
||
q1.SetActive(false);
|
||
}
|
||
if (timeplayer.time > 70 && timeplayer.time < a)
|
||
{
|
||
s1.SetActive(false);
|
||
m1.SetActive(true);
|
||
q1.SetActive(false);
|
||
}
|
||
if (timeplayer.time > a)
|
||
{
|
||
s1.SetActive(false);
|
||
m1.SetActive(false);
|
||
q1.SetActive(true);
|
||
}
|
||
}
|
||
|
||
public void startSMQ(float time)
|
||
{
|
||
timeplayer.Stop();
|
||
timeplayer.initialTime = time;
|
||
timeplayer.Play();
|
||
}
|
||
|
||
public void MuteTrack(int inNum)
|
||
{
|
||
TrackAsset theTrack = timeline.GetOutputTrack(inNum);
|
||
theTrack.muted = true;
|
||
double t0 = timeplayer.time;
|
||
timeplayer.RebuildGraph();
|
||
timeplayer.time = t0;
|
||
timeplayer.Play();
|
||
}
|
||
public void UnMuteTrack(int inNum)
|
||
{
|
||
TrackAsset theTrack = timeline.GetOutputTrack(inNum);
|
||
theTrack.muted = false;
|
||
double t0 = timeplayer.time;
|
||
timeplayer.Stop();
|
||
timeplayer.time = t0;
|
||
timeplayer.Play();
|
||
}
|
||
|
||
public void pauseTimeSet(float t)
|
||
{
|
||
timeplayer.time = t;
|
||
timeplayer.Play();
|
||
timeplayer.Pause();
|
||
}
|
||
|
||
}
|