/// <summary> /// Pull generic data from a space pin to pass to a publisher. /// </summary> /// <param name="spacePin">The space pin to extract from.</param> /// <returns>Null on failure, else a valid local peg and associated properties.</returns> private LocalPegAndProperties ExtractForPublisher(SpacePinASA spacePin) { if (!spacePin.IsReadyForPublish) { Debug.LogError($"Trying to publish a space pin with no native anchor. Place it first."); return(null); } LocalPegAndProperties ret = new LocalPegAndProperties(spacePin.LocalPeg, spacePin.Properties); return(ret); }
/// <summary> /// Add a space pin to the list of managed pins. /// </summary> /// <param name="spacePin">Pin to add.</param> /// <returns>True if not already there but added.</returns> public bool AddSpacePin(SpacePinASA spacePin) { // mafish - make sure it's not already in there. int idx = FindSpacePin(spacePin); if (idx <= 0) { spacePins.Add(spacePin); spacePin.Publisher = publisher; return(true); } return(false); }
/// <summary> /// Determine whether a space pin has necessary setup to be published. /// </summary> /// <param name="spacePin">The space pin to check.</param> /// <returns>True if the space pin can be published.</returns> private bool IsReadyForPublish(SpacePinASA spacePin) { if (spacePin == null) { SimpleConsole.AddLine(ConsoleHigh, $"Getting null space pin to check ready for publish."); return(false); } if (spacePin.Publisher != publisher) { SimpleConsole.AddLine(ConsoleHigh, $"SpacePin={spacePin.SpacePinId} has different publisher than binder={name}."); return(false); } return(spacePin.IsReadyForPublish); }
/// <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); }
/// <inheritdoc/> public async Task <bool> Search() { if (!IsReady) { return(false); } Dictionary <CloudAnchorId, LocalPegAndProperties> found = await publisher.Find(searchRadius); var wltMgr = WorldLockingManager.GetInstance(); bool foundAny = false; foreach (var keyval in found) { string spacePinId = keyval.Value.properties[SpacePinIdKey]; string cloudAnchorId = keyval.Key; var pegAndProps = keyval.Value; int idx = FindSpacePinById(spacePinId); if (idx >= 0) { CreateBinding(spacePinId, cloudAnchorId); foundAny = true; SpacePinASA spacePin = spacePins[idx]; Pose lockedPose = wltMgr.LockedFromFrozen.Multiply(pegAndProps.localPeg.GlobalPose); SimpleConsole.AddLine(ConsoleLow, $"Srch: {lockedPose.ToString("F3")}"); spacePin.SetLockedPose(lockedPose); spacePin.SetLocalPeg(pegAndProps.localPeg); } else { SimpleConsole.AddLine(ConsoleHigh, $"Found anchor for unknown SpacePin={spacePinId}."); } } return(foundAny); }