Unity3D :PlayableGraph

Recommended: Add NSDT Scene Editor to your 3D toolchain
3D Toolset: NSDT Jianshi Digital Twin

PlayableGraph

A PlayableGraph defines a set of playable outputs bound to a GameObject or Component. PlayableGraph also defines a set of playable items and their dependencies. Figure 1 provides an example.

PlayableGraph is responsible for managing the lifecycle of playable items and their outputs. Use PlayableGraph to create, connect and destroy playable items.

Figure 1: PlayableGraph example

In Figure 1, when the PlayableGraph is shown, the word "Playable" has been removed from the names of the graph nodes for compactness. For example, a node named "AnimationClipPlayable" appears as "AnimationClip".

A playable item is a C# structure that inherits the IPlayable interface. It is used to define its relationship to other playable items. Similarly, the playable item output is a C# structure that inherits the IPlayableOutput interface and is used to define the output of the PlayableGraph.

Figure 2 shows the most common core playable item types. Figure 3 shows the core playable output types.

Figure 2: Core playable item types

Figure 3: Core playable output types

The playable core types and playable output types are implemented as C# structs to avoid allocating memory for garbage collection.

"Playable" is the base type of all Playables, which means you can always implicitly convert a Playable to a Playable. The opposite is not true, and an exception will be thrown if 'Playable' is explicitly cast to an incompatible type. It also defines all the basic methods that can be executed on the playable. To access type-specific methods, you need to cast the playable to the appropriate type.

PlayableOutput As well, it is the base type for all Playable output and defines the base methods.

Note: Playable and  PlayableOutput a large number of methods are not exposed. But the "PlayableExtensions" and "PlayableOutputExtensions" static classes provide extension methods.

All non-abstract playables have a public static method  Create()that creates a playable of the corresponding type. The "Create()" method always takes as its first argument a PlayableGraph that holds the newly created Playable. Certain types of playables may require additional parameters. Non-abstract playable outputs also expose  Create() methods.

A valid playable output should link to a playable. If the playable output is not linked to a playable, the playable output does nothing. To link a playable output to a playable, use  PlayableOutput.SetSourcePlayable() the method. The linked Playable serves as the root of the Playable tree for that particular Playable output.

To concatenate two playables together, use  PlayableGraph.Connect() the method. Note that some playables cannot have inputs.

Use  PlayableGraph.Create() static methods to create PlayableGraph.

Use  PlayableGraph.Play() methods to play PlayableGraph.

Use  PlayableGraph.Stop() method to stop playing PlayableGraph.

Use  PlayableGraph.Evaluate() methods to evaluate the state of the PlayableGraph at a specific time.

Use  PlayableGraph.Destroy() the method to manually destroy the PlayableGraph. This method automatically destroys all Playables and Playable outputs created by the PlayableGraph. This destroy method must be called manually to destroy the PlayableGraph, otherwise Unity will issue an error message.

Guess you like

Origin blog.csdn.net/jianshi2023/article/details/130760474