浏览代码

Pushing TimelineBinder script now works with multiple objects if needed

/main
Amel Negra 3 年前
当前提交
9dc93db3
共有 3 个文件被更改,包括 41 次插入34 次删除
  1. 41
      UOP1_Project/Assets/Scripts/Cutscenes/TimelineBinder.cs
  2. 34
      UOP1_Project/Assets/Scripts/Cutscenes/MainCharacterBinder.cs
  3. 0
      /UOP1_Project/Assets/Scripts/Cutscenes/TimelineBinder.cs.meta

41
UOP1_Project/Assets/Scripts/Cutscenes/TimelineBinder.cs


using UnityEngine;
using UnityEngine.Playables;
public class TimelineBinder : MonoBehaviour
{
[SerializeField] private PlayableDirector _playableDirector;
[SerializeField] private GameObject[] _objectsToBind;
public string[] objectsToBindTags;
public string[] trackNames;
[SerializeField] private TransformEventChannelSO _playerInstantiatedChannel = default;
private void OnEnable()
{
_playerInstantiatedChannel.OnEventRaised += BindPlayer;
}
private void OnDisable()
{
_playerInstantiatedChannel.OnEventRaised -= BindPlayer;
}
private void BindPlayer(Transform playerTransform)
{
_objectsToBind = new GameObject[objectsToBindTags.Length];
for (int i=0; i< objectsToBindTags.Length; ++i)
{
_objectsToBind[i] = GameObject.FindGameObjectWithTag(objectsToBindTags[i]);
Debug.Log(objectsToBindTags[i]);
}
foreach (var playableAssetOutput in _playableDirector.playableAsset.outputs)
{
for (int i = 0; i < objectsToBindTags.Length; ++i)
{
if (playableAssetOutput.streamName == trackNames[i])
{
_playableDirector.SetGenericBinding(playableAssetOutput.sourceObject, _objectsToBind[i]);
}
}
}
}
}

34
UOP1_Project/Assets/Scripts/Cutscenes/MainCharacterBinder.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
public class MainCharacterBinder : MonoBehaviour
{
[SerializeField] private PlayableDirector _playableDirector;
[SerializeField] private Animator _objectToBind;
public string trackName;
[SerializeField] private TransformEventChannelSO _playerInstantiatedChannel = default;
private void OnEnable()
{
_playerInstantiatedChannel.OnEventRaised += BindPlayer;
}
private void OnDisable()
{
_playerInstantiatedChannel.OnEventRaised -= BindPlayer;
}
private void BindPlayer(Transform playerTransform)
{
_objectToBind = GameObject.FindGameObjectWithTag("Player").GetComponent<Animator>();
foreach (var playableAssetOutput in _playableDirector.playableAsset.outputs)
{
if (playableAssetOutput.streamName == trackName)
{
_playableDirector.SetGenericBinding(playableAssetOutput.sourceObject, _objectToBind);
}
}
}
}

/UOP1_Project/Assets/Scripts/Cutscenes/MainCharacterBinder.cs.meta → /UOP1_Project/Assets/Scripts/Cutscenes/TimelineBinder.cs.meta

正在加载...
取消
保存