PlayableGraph.Connect
Declaration
public bool Connect(U source, int sourceOutputPort, V destination, int destinationInputPort);Параметры
| Параметр | Описание |
|---|---|
| источник | Исходный воспроизводимый файл или его обработчик. |
| sourceOutputPort | Порт, используемый в исходном воспроизводимом файле. |
| место назначения | Конечный воспроизводимый файл или его обработчик. |
| destinationInputPort | Порт, используемый в игре-назначении. Если установлено значение -1, то создается и подключается новый порт. |
Возвращаемое значение
логическое Возвращает true, если подключение успешно.
Описание
Соединяет два экземпляра Playable.
Соединения определяют топологию PlayableGraph и то, как она оценивается.
Playables могут быть соединены вместе, образуя деревообразную структуру. Каждый Playable имеет набор входов и набор выходов. Их можно рассматривать как «слоты», к которым могут быть присоединены другие Playables.
Когда Playable создается впервые, количество его входов сбросилось до 0, что означает, что к нему не присоединены дочерние Playables. Выходы ведут себя немного по-другому — каждый Playable имеет по умолчанию выход, созданный при первом создании.
Playables соединяются методом PlayableGraph.Connect, и вы можете разъединить их друг от друга с помощью PlayableGraph.Disconnect.
Нет ограничения на количество входов, которое может иметь Playable.
using UnityEngine; using UnityEngine.Animations; using UnityEngine.Playables;
public class GraphCreationSample : MonoBehaviour { PlayableGraph m_Graph; public AnimationClip clipA; public AnimationClip clipB;
void Start() { // Create the PlayableGraph. m_Graph = PlayableGraph.Create();
// Add an AnimationPlayableOutput to the graph. var animOutput = AnimationPlayableOutput.Create(m_Graph, "AnimationOutput", GetComponent<Animator>());
// Add an AnimationMixerPlayable to the graph. var mixerPlayable = AnimationMixerPlayable.Create(m_Graph, 2);
// Add two AnimationClipPlayable to the graph. var clipPlayableA = AnimationClipPlayable.Create(m_Graph, clipA); var clipPlayableB = AnimationClipPlayable.Create(m_Graph, clipB);
// Create the topology, connect the AnimationClipPlayable to the // AnimationMixerPlayable. m_Graph.Connect(clipPlayableA, 0, mixerPlayable, 0); m_Graph.Connect(clipPlayableB, 0, mixerPlayable, 1);
// Use the AnimationMixerPlayable as the source for the AnimationPlayableOutput. animOutput.SetSourcePlayable(mixerPlayable);
// Set the weight for both inputs of the mixer. mixerPlayable.SetInputWeight(0, 1); mixerPlayable.SetInputWeight(1, 1);
// Play the graph. m_Graph.Play(); }
private void OnDestroy() { // Destroy the graph once done with it. m_Graph.Destroy(); } }