Как остановить Playable Director (Timeline) используя скрипт? - PullRequest
0 голосов
/ 30 января 2020

Я делаю вещи, используя временную шкалу в Unity3d и хочу управлять несколькими временными шкалами с помощью скрипта. playableDirectors [index] .Play () работает, но не может работать с playableDirectors [index] .Stop () . Поэтому я попробовал другой способ, GameObject.Find (). GetComponent ... , но он также не работает. Пожалуйста, помогите мне с выявлением ошибок.

TimelineController.cs

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

public class TimelineController : MonoBehaviour {

    public List<PlayableDirector> playableDirectors;
    public List<TimelineAsset> timelines;

    public int index = 0;
    public int currindex = 0;

    private void Awake()
    {
        playableDirectors[index].Play();
    }

    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.K))
        {
            if (currindex == timelines.Count - 1)
            {
                index = timelines.Count - 1;
            }
            else
            {
                index = currindex + 1;
                PlayTimelines();
            }
        }
        if (Input.GetKeyUp(KeyCode.J))
        {
            if (currindex == 0)
            {
                index = 0;
            }
            else
            {
                index = currindex - 1;
                PlayTimelines();
            }
        }
    }

    public void PlayTimelines()
    {
        playableDirectors[index].Play();
        StopTimeline();
    }

    public void StopTimeline()
    {
        if (currindex == 0) {
            GameObject.Find("Scene0").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 1) {
            GameObject.Find("Scene1").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 2) {
            GameObject.Find("Scene2").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 3) {
            GameObject.Find("Scene3").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 4) {
            GameObject.Find("Scene4").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 5) {
            GameObject.Find("Scene5").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 6) {
            GameObject.Find("Scene6").GetComponent<TimelineStopper>().Stop();}
        else if (currindex == 7) {
            GameObject.Find("Scene7").GetComponent<TimelineStopper>().Stop();}

        currindex = index;
    }
}

TimelineStopper.cs

using UnityEngine;
using UnityEngine.Playables;

public class TimelineStopper : MonoBehaviour
{
    public PlayableDirector thisPd;

    public void Stop()
    {
        thisPd.Stop();
    }
}

1 Ответ

0 голосов
/ 07 февраля 2020

это работает. TimelineController.cs

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

public class TimelineController : MonoBehaviour {

    public List<PlayableDirector> playableDirectors;
    public List<TimelineAsset> timelines;
    public List<GameObject> gameObjects;

    public int index = 0;
    public int currindex = 0;

    private void Awake()
    {
        playableDirectors[index].Play();
    }

    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.K))
        {
            if (currindex == timelines.Count - 1)
            {
                index = timelines.Count - 1;
            }
            else
            {
                index = currindex + 1;
                PlayTimelines();
            }
        }
        if (Input.GetKeyUp(KeyCode.J))
        {
            if (currindex == 0)
            {
                index = 0;
            }
            else
            {
                index = currindex - 1;
                PlayTimelines();
            }
        }
    }

    public void PlayTimelines()
    {
        gameObjects[index].SetActive(true);
        playableDirectors[index].Play();
        StopTimeline();
    }

    public void StopTimeline()
    {
        playableDirectors[currindex].time = 0;
        playableDirectors[currindex].Stop();
        playableDirectors[currindex].Evaluate();
        gameObjects[currindex].SetActive(false);

        currindex = index;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...