Beispiel #1
0
    public async void DeleteCurrentAnchor()
    {
        if (aRTapHandler.objectToPlace != null)
        {
            Log.debug("Trying to discard anchor");
            if (anchorLerper.hasAnchorSelected)
            {
                Log.debug("Anchor has been lerped");
                anchorLerper.PrepareToDelete();
            }
            Log.debug("Destroying");
            Destroy(aRTapHandler.objectToPlace);
            Log.debug("Setting text");
            anchorInfoText.GetComponentInParent <FadeText>().SetText($"Anchor creation canceled");
            return;
        }
        Log.debug("Trying to delete existing anchor");
        AnchorProperties anchorToDeleteProperties = aRTapHandler.currentSelectedAnchor.GetComponent <AnchorProperties>();

        anchorInfoText.text = $"Deleting anchor:\n{anchorToDeleteProperties.anchorLabel}...";
        Log.debug($"Try to Delete CloudSpatialAnchor: {currentCloudSpatialAnchor.Identifier} ");
        await spatialAnchorManager.DeleteAnchorAsync(currentCloudSpatialAnchor);

        Log.debug($"CloudSpatialAnchor is Deleted: {currentCloudSpatialAnchor.Identifier}");
        anchorInfoText.GetComponentInParent <FadeText>().SetText($"Anchor deleted \nLabel: {anchorToDeleteProperties.anchorLabel}");
        Destroy(anchorToDeleteProperties.button);
        FindObjectOfType <AnchorButtonPopulator>().RemoveAnchorFromDictionary(anchorToDeleteProperties.anchorID);
        await anchorConverter.ResetSession();

        anchorConverter.FindAnchorsByLocation();
    }
    public async void AddAnchorToButtonList(AnchorProperties anchorProperties)
    {
        if (ButtonExists(anchorProperties))
        {
            Log.debug($"Button for {anchorProperties.name} exists");
            existingButtons.TryGetValue(anchorProperties.anchorID, out anchorProperties.button);
            anchorProperties.button.GetComponent <AnchorButtonHandler>().anchorProperties = anchorProperties;
            return;
        }
        Log.debug($"Button for {anchorProperties.name} does not exist");
        GameObject buttonToAdd = Instantiate(anchorButtonPrefab) as GameObject;

        buttonToAdd.name = $"Anchor Button: {anchorProperties.anchorLabel}";
        TMP_Text tmpText = buttonToAdd.GetComponentInChildren <TMP_Text>();

        tmpText.text             = anchorProperties.anchorLabel;
        tmpText.enableAutoSizing = false;
        tmpText.fontSize         = addAnchorButton.GetComponentInChildren <TMP_Text>().fontSize;
        buttonToAdd.GetComponent <RectTransform>().sizeDelta = new Vector2(containerWidth / (2.5f), containerHeight * (.8f));
        buttonToAdd.transform.SetParent(contentContainer.transform);
        anchorProperties.button = buttonToAdd;
        AnchorButtonHandler anchorButtonHandler = buttonToAdd.GetComponent <AnchorButtonHandler>();

        anchorButtonHandler.anchorProperties = anchorProperties;
        existingButtons.Add(anchorProperties.anchorID, buttonToAdd);
        buttonToAdd.transform.SetSiblingIndex(0);
        SortButtons();
        await Task.Delay(50);

        Canvas.ForceUpdateCanvases();
        scrollBar.GetComponent <Scrollbar>().value = 1f;
    }
Beispiel #3
0
 private void UpdateAnchorProperties(CloudSpatialAnchor cloudAnchor, AnchorProperties anchorProperties)
 {
     Log.debug($"anchor properties local anchor local scale is : {anchorProperties.gameObject.transform.localScale.x.ToString()}");
     cloudAnchor.AppProperties[AnchorProperties.ScaleKey] = anchorProperties.gameObject.transform.localScale.x.ToString();
     cloudAnchor.AppProperties[AnchorProperties.DateKey]  = anchorProperties.dateSecondsString;
     if (anchorProperties.anchorLabel != null)
     {
         cloudAnchor.AppProperties[AnchorProperties.AnchorLabelKey] = anchorProperties.anchorLabel;
     }
 }
Beispiel #4
0
 void Update()
 {
     if (aRTapHandler == null || aRTapHandler.currentSelectedAnchor == null)
     {
         ColorTween(this.colors.normalColor * this.colors.colorMultiplier);
         return;
     }
     buttonAnchorProperties          = this.gameObject.GetComponent <AnchorButtonHandler>().anchorProperties;
     currentSelectedAnchorProperties = aRTapHandler.currentSelectedAnchor.GetComponent <AnchorProperties>();
     if (buttonAnchorProperties != null && currentSelectedAnchorProperties != this.gameObject.GetComponent <AnchorButtonHandler>().anchorProperties)
     {
         ColorTween(this.colors.normalColor * this.colors.colorMultiplier);
     }
 }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (!(anchorManager.currentCloudSpatialAnchor is null))
        {
            foreach (ARAnchor anchor in aRAnchorManager.trackables)
            {
                AnchorProperties anchorProperties = anchor.gameObject.GetComponent <AnchorProperties>();

                if (anchorProperties.anchorID == anchorManager.currentCloudSpatialAnchor.Identifier)
                {
                    distanceText.text = System.Math.Round(Vector3.Distance(anchor.transform.position, Camera.main.transform.position) * 3.28084, 1) + " ft";
                    break;
                }
            }
        }
Beispiel #6
0
    private void AnchorConverter_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        if (args.Status == LocateAnchorStatus.Located)
        {
            Log.debug($"Anchor Located : {args.Anchor.Identifier}");

            if (args.Identifier == null || args.Anchor == null)
            {
                Log.debug("Anchor or Identifier is null");
                return;
            }

            anchorManager.AddCloudSpatialAnchor(args.Anchor);

            foreach (ARAnchor anchor in aRAnchorManager.trackables)
            {
                if (anchor == null)
                {
                    break;
                }
                if (anchor.transform.position == args.Anchor.GetPose().position)
                {
                    Debug.Log($"Trying to add anchor. {anchor.name}");
                    AnchorProperties anchorProperties = anchor.gameObject.GetComponent <AnchorProperties>();

                    Debug.Log($"AnchorID : {anchorProperties.anchorID}");
                    Debug.Log($"Instantiate Render. {anchor.name}");
                    GetAnchorProperties(args.Anchor, anchorProperties);
                    GameObject anchorRender = Instantiate(arAnchorContainerRender, new Vector3(0f, 0f, 0f), Quaternion.Euler(0f, 0f, 0f));
                    if (anchorProperties.anchorLabel != null && anchorProperties.anchorLabel.Length > 0)
                    {
                        anchorRender.GetComponentInChildren <TMPro.TMP_Text>().text = RenameAnchorHandler.LoopLabel(anchorProperties.anchorLabel);
                    }

                    anchorRender.transform.SetParent(anchor.transform, false);
                    Log.debug($" {anchorProperties.anchorLabel} 's anchorRender scale is :{anchorRender.gameObject.transform.localScale.x}, anchor scale is : {anchor.transform.localScale.x}");
                    FindObjectOfType <AnchorButtonPopulator>().AddAnchorToButtonList(anchorProperties);
                    Log.debug($"Assign Parent for Render. {anchor.name}");
                    break;
                }
            }
            anchorFirstTimeFound = true;
            Log.debug($"Checking first AnchorFirstTimeFound :{anchorFirstTimeFound}");
        }
    }
Beispiel #7
0
    private void GetAnchorProperties(CloudSpatialAnchor cloudAnchor, AnchorProperties anchorProperties)
    {
        anchorProperties.anchorID = cloudAnchor.Identifier;

        anchorProperties.anchorLabel        = cloudAnchor.AppProperties.SafeGet(AnchorProperties.AnchorLabelKey);
        anchorProperties.dateSecondsString  = cloudAnchor.AppProperties.SafeGet(AnchorProperties.DateKey);
        anchorProperties.cloudSpatialAnchor = cloudAnchor;

        var scaleString = cloudAnchor.AppProperties.SafeGet(AnchorProperties.ScaleKey);

        if (scaleString is string)
        {
            float x = float.Parse(scaleString);
            Log.debug($"anchor properties from cloud anchor local scale is : {x}");
            anchorProperties.gameObject.transform.localScale = new Vector3(1f, 1f, 1f) * x;
            Log.debug($"anchor properties from cloud anchor  after local scale is : {anchorProperties.gameObject.transform.localScale}");
        }
    }
Beispiel #8
0
    public int CompareTo(object obj)
    {
        if (obj is null)
        {
            return(1);
        }

        AnchorProperties ap = obj as AnchorProperties;

        if (ap is null)
        {
            throw new ArgumentException("Should be AnchorProperties!");
        }
        else
        {
            return(ap.dateSeconds.CompareTo(this.dateSeconds));
        }
    }
Beispiel #9
0
    public async Task UpdateExistingAnchor(CloudSpatialAnchor cloudAnchor, AnchorProperties anchorProperties)
    {
        UpdateAnchorProperties(cloudAnchor, anchorProperties);
        try
        {
            Log.debug("Trying to update current cloudAnchor");
            anchorInfoText.text = $"Trying to update cloud anchor";
            //progressBar.SetActive(false);
            await spatialAnchorManager.Session.UpdateAnchorPropertiesAsync(cloudAnchor);

            anchorInfoText.GetComponentInParent <FadeText>().SetText("Anchor updated!");
        }
        catch (Exception ex)
        {
            Log.debug(ex.Message);
            anchorInfoText.GetComponentInParent <FadeText>().SetText("Oops there was problem updated anchor!");
        }
        FindAnchorsByLocation();
    }
Beispiel #10
0
    public async void SaveAnchor()
    {
        anchorLerper.SubmitAnchor();
        Debug.Log("We are placing an anchor in to the cloud.");
        AnchorProperties anchorProperties = aRTapHandler.currentSelectedAnchor.GetComponent <AnchorProperties>();

        if (anchorProperties.anchorID != null)
        {
            await anchorConverter.UpdateExistingAnchor(anchorProperties.cloudSpatialAnchor, anchorProperties);

            Log.debug("Changing The Button Name");
            anchorProperties.button.GetComponentInChildren <TMP_Text>().text = anchorProperties.anchorLabel;
        }
        else
        {
            aRTapHandler.PlaceAnchor();
        }

        appController.EnterSelectMode();
        AnchorList.SetActive(true);
        AnchorOptionsUIElement.SetActive(false);
    }
Beispiel #11
0
    public async Task CreateCloudAnchor(CloudSpatialAnchor cloudAnchor, AnchorProperties anchorProperties)
    {
        anchorProperties.dateSecondsString = $"{(Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds}";
        UpdateAnchorProperties(cloudAnchor, anchorProperties);
        if (cloudAnchor == null)
        {
            Log.debug("Cloud anchor is null");
            return;
        }
        tutorialManager.gameObject.SetActive(true);

        anchorInfoText.GetComponentInParent <FadeText>().ShowText();
        while (!spatialAnchorManager.IsReadyForCreate)
        {
            progressBar.SetActive(true);
            Log.debug($"Not enough environmental data : {spatialAnchorManager.SessionStatus.RecommendedForCreateProgress}");
            anchorInfoText.text = $"Look around to gather more data";
            progressBar.GetComponent <Slider>().value = spatialAnchorManager.SessionStatus.RecommendedForCreateProgress;
            await Task.Delay(333);
        }
        tutorialManager.gameObject.SetActive(false);

        try
        {
            Log.debug("Trying to create cloud anchor");
            anchorInfoText.text = $"Creating anchor...";
            progressBar.SetActive(false);
            await spatialAnchorManager.CreateAnchorAsync(cloudAnchor);

            anchorInfoText.GetComponentInParent <FadeText>().SetText("Anchor created!");
        }
        catch (Exception ex)
        {
            Log.debug(ex.Message);
            anchorInfoText.GetComponentInParent <FadeText>().SetText("Oops there was problem created anchor!");
        }
    }
 private bool ButtonExists(AnchorProperties anchorProperties)
 {
     return(existingButtons.ContainsKey(anchorProperties.anchorID));
 }