Jungle Runtime
The JungleRuntime class manages the playback of JungleTree instances.
It handles starting, stopping, and updating the playbacks, and provides events for monitoring the lifecycle of the trees.
Overview
The JungleRuntime class provides the following functionalities:
- Managing the playback lifecycle of
JungleTreeinstances. - Providing events for tree start and stop.
- Ensuring that playbacks are properly cleaned up.
Methods
TryGetPlayback
public static bool TryGetPlayback(JungleTree tree, out JunglePlayback playback)
Attempts to get the JunglePlayback associated with the specified JungleTree.
Returns:
trueif the playback is found; otherwise,false.
IsPlaying
public static bool IsPlaying(JungleTree tree)
Checks if the specified JungleTree instance is currently running.
Returns:
trueif the tree is running; otherwise,false.
Play
public static string Play(JungleTree tree)
Starts playing the specified JungleTree instance.
Returns:
- A string representing the unique identifier of the playback, or
nullif the tree cannot be played.
Play
public static string Play(JungleTree tree, out JunglePlayback playback)
Starts playing the specified JungleTree instance and returns the associated JunglePlayback.
Returns:
- A string representing the unique identifier of the playback, or
nullif the tree cannot be played.
Stop
public static void Stop(JungleTree tree)
Stops the specified JungleTree instance if it is currently running.
Stop
public static void Stop(JunglePlayback playback)
Stops the specified JunglePlayback instance if it is currently registered and running.
Events
OnTreePlay
public static event Action<JungleTree> OnTreePlay
Called when a JungleTree has begun playing.
Values:
JungleTree: 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: The tree that has stopped playing.
Examples
Playing a JungleTree
To start playing a JungleTree instance, use the Play method:
using Jungle;
using UnityEngine;
public class JungleExample : MonoBehaviour
{
[SerializeField]
private JungleTree jungleTree;
private string _playbackUid;
private void Start()
{
// Option 1:
_playbackUid = JungleRuntime.Play(jungleTree);
// Option 2:
_playbackUid = JungleRuntime.Play(jungleTree, out JunglePlayback playback);
}
}
Stopping a JungleTree
To stop a running JungleTree instance, use the Stop method:
using Jungle;
using UnityEngine;
public class JungleExample : MonoBehaviour
{
[SerializeField]
private JungleTree jungleTree;
private string _playbackUid;
private JunglePlayback _playback;
private void Start()
{
_playbackUid = JungleRuntime.Play(jungleTree, out _playback);
Invoke(nameof(StopJungleTree), 5f);
}
private void StopJungleTree()
{
// Option 1: Stop via a playback uid
JungleRuntime.Stop(_playbackUid);
// Option 2: Stop via a playback reference
JungleRuntime.Stop(_playback);
}
}