UnityTimeLine组件——基本参数使用及说明

TImeLine学习

常见API使用方法如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using UnityEngine.UI;

/// 
/// 功能测试专用脚本
/// 
public class Test : MonoBehaviour {
     
	public PlayableDirector Player;
    private float sumTime = 0;
    public Slider mProcess;
    public Text mTime;
   
    void Update () {
     
        UpdateProcess((float)Player.time, (float)Player.duration);
        if (Input.GetKeyDown(KeyCode.W))//当前时间
        {
     
			print(Player.time+"时间");
        }
        if (Input.GetKeyDown(KeyCode.A))//播放
        {
     
            Player.Play();
            print("播放");
        }
        if (Input.GetKeyDown(KeyCode.S))//停止(清空播放进度,之后点击播放重头播放)
        {
     
            Player.Stop();
            print("停止播放,在播放时从头");
        }
        if (Input.GetKeyDown(KeyCode.D))//直接设置播放进度,类似拖动视频的进度条
        {
     
            Player.time =5;
            print("设置进度"+5);
            print(Player.time);
        }
        if (Input.GetKeyDown(KeyCode.F))//恢复播放(点击暂停后的恢复,播放进度不改变)
        {
     
            Player.Resume();
            print("恢复");
        }
        if (Input.GetKeyDown(KeyCode.Q))//暂停播放
        {
     
            Player.Pause();
            print("暂停当前的动画");
        }
        if (Input.GetKeyDown(KeyCode.R))//整体时间
        {
     
            print("总时间" + Player.duration);
        }
    }
    /// 
    /// 进度条后时间显示  eg:00:00/00:00
    /// 
    /// 
    void OnValueChange(float value)
    {
     
        float tempSumTime = sumTime;

        float tempCurTime = sumTime * mProcess.value;
        tempSumTime /= 1000 * 60;
        tempCurTime /= 1000 * 60;
        mTime.text = string.Format("{0:00}:{1:00} / {2:00}:{3:00}", Mathf.FloorToInt(tempCurTime), Mathf.FloorToInt((tempCurTime - Mathf.FloorToInt(tempCurTime)) * 60), Mathf.FloorToInt(tempSumTime), Mathf.FloorToInt((tempSumTime - Mathf.FloorToInt(tempSumTime)) * 60));
    }
    /// 
    /// 更新进度
    /// 
    /// 
    /// 
    public void UpdateProcess(float curTime, float sumTime)
    {
           
        this.sumTime = sumTime;
        float rtn = curTime / sumTime;
        if (rtn > 0 && rtn < 1)
        {
     
            mProcess.value = Mathf.Clamp01(rtn);
        }

    }

    void OnEnable()
    {
     
        mProcess.onValueChanged.AddListener(OnValueChange);
    }
    void OnDisable()
    {
     
        mProcess.onValueChanged.RemoveListener(OnValueChange);
    }
}

你可能感兴趣的:(Unity,unity,unity3d,vr)