Using Timeline: Custom Scripts

確認済のバージョン: 2017.1

-

難易度: 中級

How to control the playable director and our Timeline sequences using a custom script.

Using Timeline: Custom Scripts

中級 Animation

TimelineController

Code snippet

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

public class TimelineController : MonoBehaviour {

    public List playableDirectors;
    public List timelines;


    public void Play()
    {
        foreach (PlayableDirector playableDirector in playableDirectors) 
        {
            playableDirector.Play ();
        }
    }

    public void PlayFromTimelines(int index)
    {
        TimelineAsset selectedAsset;

        if (timelines.Count <= index) 
        {
            selectedAsset = timelines [timelines.Count - 1];
        } 
        else 
        {
            selectedAsset = timelines [index];
        }

        playableDirectors [0].Play (selectedAsset);
    }
}

ButtonCollider

Code snippet

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class ButtonCollider : MonoBehaviour {

    public UnityEvent onSpacebar;
    public UnityEvent onReturn;


    public void OnTriggerStay()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (onSpacebar != null)
            {
                onSpacebar.Invoke();
            }
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (onReturn != null)
            {
                onReturn.Invoke();
            }
        }
    }
}

関連するチュートリアル

関連ドキュメント