Beispiel #1
0
        /// <summary>
        /// Publish the spacePin.
        /// </summary>
        /// <param name="spacePin">SpacePinASA to publish</param>
        /// <returns>True on success.</returns>
        /// <remarks>
        /// It may be this should be a private member.
        /// </remarks>
        public async Task <bool> Publish(SpacePinASA spacePin)
        {
            if (!IsReady)
            {
                // mafinc - Should we wait until it is ready? Maybe as a binder option?
                return(false);
            }

            int idx = FindSpacePin(spacePin);

            if (idx < 0)
            {
                Debug.LogError($"Trying to publish unknown space pin. Must be added in inspector or AddSpacePin() first.");
                return(false);
            }

            int cloudIdx = FindBindingBySpacePinId(spacePin.SpacePinId);

            if (cloudIdx >= 0)
            {
                SimpleConsole.AddLine(ConsoleHigh, $"Publishing previously published space pin={spacePin.SpacePinId}, deleting from cloud first.");
                await publisher.Delete(bindings[cloudIdx].cloudAnchorId);

                RemoveBinding(spacePin.SpacePinId);
            }

            var obj = ExtractForPublisher(spacePin);

            if (obj == null)
            {
                return(false);
            }
            CloudAnchorId cloudAnchorId = await publisher.Create(obj);

            if (string.IsNullOrEmpty(cloudAnchorId))
            {
                Debug.LogError($"Failed to create cloud anchor for {spacePin.SpacePinId}");
                return(false);
            }
            SetBinding(spacePin.SpacePinId, cloudAnchorId);
            return(true);
        }