/// <summary> /// Creates a new receiver to be managed by this manager instance. /// </summary> /// <param name="streamID">The ID of the stream to receive. Authentication will be done using the <c>authToken</c> /// on the manager instance this method is being called on.</param> /// <param name="streamRoot">Optionally, you can provide a <c>Transform</c> for the geometry to be spawned /// under.</param> /// <param name="initialiseOnCreation">Optionally, the stream can have its <c>InitializeClient</c> /// method started after being created.</param> /// <param name="receiveUpdates"></param> /// <returns>An async Task which can be awaited with a coroutine or just ignored.</returns> public virtual async Task AddReceiverAsync(string streamID, Transform streamRoot = null, bool initialiseOnCreation = false, bool receiveUpdates = true) { SpeckleUnityReceiver newReceiver = new SpeckleUnityReceiver(streamID, streamRoot, receiveUpdates); receivers.Add(newReceiver); if (initialiseOnCreation) { await newReceiver.InitializeClient(this, serverUrl, loggedInUser.Apitoken); } }
/// <summary> /// Remove a receiver of a given index in the list on this manager instance. Cleans up all GameObjects /// associated to that stream as well. /// </summary> /// <param name="receiverIndex">The index to to remove from.</param> public virtual void RemoveReceiver(int receiverIndex) { if (receiverIndex < 0 || receiverIndex >= receivers.Count) { throw new ArgumentOutOfRangeException("Receiver could not be removed because it does not exist"); } SpeckleUnityReceiver receiver = receivers[receiverIndex]; receivers.RemoveAt(receiverIndex); receiver.RemoveContents(); receiver.client?.Dispose(); if (receiver.streamRoot.name.Contains("Default Stream Root: ")) { Destroy(receiver.streamRoot.gameObject); } }