Skip to main content
Version: 2.0.x (Unreleased)

Jungle Playback

The JunglePlayback class handles the playback of a JungleTree. It handles various systems such as node lifecycle, error reporting, and revert actions.

How it Works

Playbacks are automatically created by the JungleRuntime when a tree is played. When the playback is initialized, it creates temporary copies of all JungleNode instances on the associated tree. These temporary copies are called playback node instances, and they are deleted when the tree stops playing.

These temporary playback instances are created to prevent serialized data from being overridden during node playback.

Overview

The JunglePlayback class provides the following functionalities:

  • Automatically manages node lifecycle.
  • Provides event hooks for node lifecycle events.
  • Handles revert actions.

Properties

Uid

public readonly string Uid;

The unique identifier for the playback.


Tree

public readonly JungleTree Tree;

A reference to the JungleTree the playback is playing/associated with.


Nodes

public IReadOnlyCollection<JungleNode> Nodes { get; }

A list of all the runtime equivalent JungleNode instances.


Time

public float Time { get; }

The total amount of time in seconds that the playback has been playing for.

note

The Time property uses unscaled time.


Events

OnNodeStart

public event Action<string> OnNodeStart

Invoked when the playback starts a JungleNode.

Values

  • string: The unique identifier of the JungleNode that started.

OnNodeStop

public event Action<string> OnNodeStop

Invoked when the playback stops a JungleNode.

Values

  • string: The unique identifier of the JungleNode that stopped.

OnNodeError

public event Action<string, string> OnNodeError

Invoked when a JungleNode encounters an error.

Values

  • string: The unique identifier of the JungleNode that encountered the error.
  • string: The error message.

Methods

TryGetEquivalentNode

public bool TryGetEquivalentNode(JungleNode originalNode, out JungleNode equivalentNode)

Tries to get the equivalent playback JungleNode instance to the given original JungleNode instance.

Parameters

  • originalNode: The original JungleNode instance to find an equivalent of.
  • out equivalentNode: The equivalent playback instance to the original node instance. (null if not found)

Returns

true if an equivalent playback instance could be found; otherwise, false.


TryGetNodeByUid

public bool TryGetNodeByUid(string nodeUid, out JungleNode node)

Tries to get a JungleNode with the given unique identifier.

Parameters

  • nodeUid: The unique identifier of the JungleNode to find.
  • out node: The JungleNode found with the given unique identifier. (null if not found)

Returns

  • true if a JungleNode with the given unique identifier could be found; otherwise, false.
note

The returned JungleNode instance is the playback's copied instance, not the original tree instance.


IsNodeRunning

public bool IsNodeRunning(string nodeUid)

Checks if a JungleNode with the given unique identifier is running.

Parameters

  • nodeUid: The unique identifier of the JungleNode to check.

Returns

true if a JungleNode with the given unique identifier is running; otherwise, false.


StopNode

public void StopNode(string nodeUid)

Stops a JungleNode with the given unique identifier.

Parameters

  • nodeUid: The unique identifier of the JungleNode to be stopped.

AddRevertAction

public string AddRevertAction(Action action)

Adds the given action to the list of actions to be called when the playback stops.

Parameters

  • action: The action to be reverted when the playback stops.

Returns

A unique identifier for the given revert action.


RemoveRevertAction

public void RemoveRevertAction(string revertActionUid)

Removes a revert action with the given unique identifier from the list of actions to be called when the playback stops.

Parameters

  • revertActionUid: The unique identifier of the revert action to remove.