BindSpaceUsers (Unity)

- Declaration

public static IDisposable BindSpaceUsers(this CavrnusSpaceConnection spaceConn, Action<CavrnusUser> userAdded, Action<CavrnusUser> userRemoved)

- Description

Throws events whenever CavrnusUsers enter/exit the given space.

Note that userAdded will be triggered immediately for every user that is already present.

This is the best way to maintain a list of users in, say, a UI panel. If you just want a snapshot of the current users for, say, debugging, consider calling GetCurrentSpaceUsers.

- Sample

public class SpaceUserAudioController : MonoBehaviour { [SerializeField] private AudioSource audioSource; [SerializeField] private AudioClip joinClip; [SerializeField] private AudioClip exitClip; public void Start() { CavrnusFunctionLibrary.AwaitAnySpaceConnection(spaceConn => { spaceConn.BindSpaceUsers(UserJoined, UserExited); }); } private void UserJoined(CavrnusUser user) => audioSource.PlayOneShot(joinClip); private void UserExited(CavrnusUser user) => audioSource.PlayOneShot(exitClip); }

Related pages