脚本内容如下,主要注意得通过Resolve(playable.GetGraph().GetResolver())方法去获得Timeline传入的值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using UnityEngine.UI;
public class NewPlayableAsset : BasicPlayableBehaviour
{
[Header("对话框")]
public ExposedReference<Text> dialog;
private Text _dialog;
[Multiline(3)]
public string dialogStr;
public override void OnGraphStart(Playable playable)
{
_dialog = dialog.Resolve(playable.GetGraph().GetResolver());
}
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
public override void OnBehaviourPause(Playable playable, FrameData info)
{
if (_dialog)
{
_dialog.gameObject.SetActive(false);
}
}
}
然后和动画一样插入Track后可以看到下方的属性是我们可以编辑的了。
做一个文本变换的效果:
脚本自定义功能也完成~ 触发机制
之后修改成条件触发判定,不在是直接播放游戏就开始运行
做了一个触发的脚本功能
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Timeline;
using UnityEngine.Playables;
public class StoryControl : MonoBehaviour
{
public bool isTrigger;
public GameObject ui_tip;
public PlayableDirector playableDirector;
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == &#34;Trigger&#34;)
{
ui_tip.gameObject.SetActive(true);
isTrigger = true;
}
}
public void OnTriggerExit(Collider other)
{
if (other.gameObject.name == &#34;Trigger&#34;)
{
ui_tip.gameObject.SetActive(false);
isTrigger = true;
}
}
public void Update()
{
if (isTrigger)
{
if (Input.GetKeyDown(KeyCode.E))
{
playableDirector.Play();
}
}
}