BindJoinableSpaces (Unity)

- Declaration

public static IDisposable BindJoinableSpaces(Action<CavrnusSpaceInfo> spaceAdded, Action<CavrnusSpaceInfo> spaceUpdated, Action<CavrnusSpaceInfo> spaceRemoved)

- Description

Triggers when joinable spaces become available, or when their metadata changes.

When called, you will immediately get spaceAdded events for all spaces currently in your list.

- Sample

using CavrnusSdk.API; using System.Collections.Generic; using UnityEngine; public class BindJoinableSpaces : MonoBehaviour { public SpaceOptionUI SpaceUiPrefab; public Transform SpacesListParent; private Dictionary<CavrnusSpaceInfo, SpaceOptionUI> instantiatedSpaceOptions = new Dictionary<CavrnusSpaceInfo, SpaceOptionUI>(); void Start() { CavrnusFunctionLibrary.BindJoinableSpaces(space => SpaceAdded(space), space => SpaceUpdated(space), space => SpaceRemoved(space)); } private void SpaceAdded(CavrnusSpaceInfo space) { var spaceOption = GameObject.Instantiate(SpaceUiPrefab, SpacesListParent); spaceOption.Setup(space); } private void SpaceUpdated(CavrnusSpaceInfo space) { var oldSpaceOption = instantiatedSpaceOptions[space]; GameObject.Destroy(oldSpaceOption); var spaceOption = GameObject.Instantiate(SpaceUiPrefab, SpacesListParent); spaceOption.Setup(space); } private void SpaceRemoved(CavrnusSpaceInfo space) { var oldSpaceOption = instantiatedSpaceOptions[space]; GameObject.Destroy(oldSpaceOption); } }