Jungle Runtime
The JungleRuntime class manages the playback of JungleTree instances.
Overview
The JungleRuntime class provides the following functionalities:
- Managing the playback lifecycle of
JungleTreeinstances. - Providing events for tree start and stop.
Example
Below is an example of a script that plays a tree and stops it five seconds later.
using Jungle;
using UnityEngine;
public class JungleRuntimeExample : MonoBehaviour
{
[SerializeField]
private JungleTree tree;
private string _playbackUid;
private void Start()
{
_playbackUid = JungleRuntime.Play(tree);
// Stop the tree after five seconds
Invoke(nameof(StopTreeAfterFiveSeconds), 5);
}
private void StopTreeAfterFiveSeconds()
{
JungleRuntime.Stop(_playbackUid);
}
}
Properties
Playbacks
public static IReadOnlyList<JunglePlayback> Playbacks { get; }
List of all currently running Jungle Playbacks.
Events
OnTreePlay
public static event Action<JungleTree> OnTreePlay
Called when a JungleTree has started playing.
Values
JungleTree: A reference to the tree that has started playing.
OnTreeStop
public static event Action<JungleTree> OnTreeStop
Called when a JungleTree has finished playing or was stopped.
Values
JungleTree: A reference to the tree that has stopped playing.
Methods
TryGetPlayback
public static bool TryGetPlayback(JungleTree tree, out JunglePlayback playback)
Attempts to get the JunglePlayback associated with the given JungleTree.
Parameters
tree: TheJungleTreeinstance to find an associatedJunglePlaybackfor.out playback: A reference to theJunglePlaybackinstance associated with the given tree. (nullif not found)
Returns
true if a playback associated with the given tree is found; otherwise, false.
IsTreePlaying
public static bool IsTreePlaying(JungleTree tree)
Checks if the given JungleTree instance is currently playing.
Parameters
tree: TheJungleTreeinstance to check.
Returns
true if the given tree is playing; otherwise, false.
Play
public static string Play(JungleTree tree)
Starts playing the given JungleTree.
Parameters
tree: TheJungleTreeinstance to play.
Returns
A string representing the unique identifier of the JunglePlayback associated with the tree.
(null if the tree cannot be played)
The Play method can only be called while in play mode.
Play (w/ out playback)
public static string Play(JungleTree tree, out JunglePlayback playback)
Starts playing the specified JungleTree instance and returns the associated JunglePlayback.
Parameters
tree: TheJungleTreeinstance to play.out playback: A reference to theJunglePlaybackassociated with the given tree. (nullif the tree cannot be played)
Returns
A string representing the unique identifier of the JunglePlayback associated with the tree.
(null if the tree cannot be played)
The Play method can only be called while in play mode.
Stop (JungleTree)
public static void Stop(JungleTree tree)
Stops the given JungleTree if it's currently running.
Parameters
tree: TheJungleTreeinstance to stop.
The Stop method can only be called while in play mode.
Stop (JunglePlayback)
public static void Stop(JunglePlayback playback)
Stops the given JunglePlayback if it's currently running.
Parameters
playback: TheJunglePlaybackinstance to stop.
The Stop method can only be called while in play mode.