Jungle Runtime
The JungleRuntime
class manages the playback of JungleTree
instances.
Overview
The JungleRuntime
class provides the following functionalities:
- Managing the playback lifecycle of
JungleTree
instances. - 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
: TheJungleTree
instance to find an associatedJunglePlayback
for.out playback
: A reference to theJunglePlayback
instance associated with the given tree. (null
if 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
: TheJungleTree
instance 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
: TheJungleTree
instance 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
: TheJungleTree
instance to play.out playback
: A reference to theJunglePlayback
associated with the given tree. (null
if 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
: TheJungleTree
instance 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
: TheJunglePlayback
instance to stop.
The Stop
method can only be called while in play mode.