Beispiel #1
0
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveAreaDescriptionAndMesh()
    {
        if (m_saveThread != null)
        {
            yield break;
        }

        // Disable interaction before saving.
        m_initialized     = false;
        m_savingText.text = "Saving Area Description...";

        if (string.IsNullOrEmpty(m_savedUUID))
        {
            m_saveThread = new Thread(delegate()
            {
                // Save the Area Description to file.
                m_curAreaDescription = AreaDescription.SaveCurrent();
                AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
                m_savedUUID     = m_curAreaDescription.m_uuid;
                metadata.m_name = metadata.m_dateTime.ToLongTimeString();
                m_curAreaDescription.SaveMetadata(metadata);

                // Save the tango dynamic mesh to file.
                StartCoroutine(_DoSaveTangoDynamicMesh());
            });
            m_saveThread.Start();
        }
        else
        {
            StartCoroutine(_DoSaveTangoDynamicMesh());
        }
    }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
        // m_guiTextInputContents = "Unnamed";

        if (m_saveThread != null)
        {
            yield break;
        }
        bool saveConfirmed = true;

        if (saveConfirmed)
        {
            // Disable interaction before saving.
            m_initialized = false;
            m_savingText.gameObject.SetActive(true);
            if (m_tangoApplication.m_areaDescriptionLearningMode)
            {
                // The keyboard is not readable if you are not in the Unity main thread. Cache the value here.
                string name;
                name = GetComponent <AreaLoadingStartup>().GetName();

                m_saveThread = new Thread(delegate()
                {
                    // Start saving process in another thread.
                    m_curAreaDescription = AreaDescription.SaveCurrent();
                    AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
                    metadata.m_name = name;
                    m_curAreaDescription.SaveMetadata(metadata);
                });
                m_saveThread.Start();
                //m_saveThread.Join();
            }
        }
    }
    public void OnTangoPermissions(bool permissionsGranted)
    {
        if (permissionsGranted)
        {
            AreaDescription[]        list               = AreaDescription.GetList();
            AreaDescription          mostRecent         = null;
            AreaDescription.Metadata mostRecentMetadata = null;
            if (list.Length > 0)
            {
                // Find and load the most recent Area Description
                mostRecent         = list[0];
                mostRecentMetadata = mostRecent.GetMetadata();
                foreach (AreaDescription areaDescription in list)
                {
                    AreaDescription.Metadata metadata = areaDescription.GetMetadata();
                    if (metadata.m_dateTime > mostRecentMetadata.m_dateTime)
                    {
                        mostRecent         = areaDescription;
                        mostRecentMetadata = metadata;
                    }
                }

                m_tangoApplication.Startup(mostRecent);
            }
            else
            {
                // No Area Descriptions available.
                Debug.Log("No area descriptions available.");
            }
        }
    }
Beispiel #4
0
        public static void SaveNameAs(this AreaDescription self, string name)
        {
            var metadata = self.GetMetadata();

            metadata.m_name = name;
            self.SaveMetadata(metadata);
        }
    /// <summary>
    /// Select a specific Area Description to show details.
    /// </summary>
    /// <param name="areaDescription">Area Description to show details for, or <c>null</c> if details should be hidden.</param>
    private void _SelectAreaDescription(AreaDescription areaDescription)
    {
        m_selectedAreaDescription = areaDescription;

        if (areaDescription != null)
        {
            m_selectedMetadata = areaDescription.GetMetadata();
            m_detailsParent.gameObject.SetActive(true);

            m_detailsDate.text = m_selectedMetadata.m_dateTime.ToLongDateString() + ", " + m_selectedMetadata.m_dateTime.ToLongTimeString();

            m_detailsEditableName.text  = m_selectedMetadata.m_name;
            m_detailsEditablePosX.text  = m_selectedMetadata.m_transformationPosition[0].ToString();
            m_detailsEditablePosY.text  = m_selectedMetadata.m_transformationPosition[1].ToString();
            m_detailsEditablePosZ.text  = m_selectedMetadata.m_transformationPosition[2].ToString();
            m_detailsEditableRotQX.text = m_selectedMetadata.m_transformationRotation[0].ToString();
            m_detailsEditableRotQY.text = m_selectedMetadata.m_transformationRotation[1].ToString();
            m_detailsEditableRotQZ.text = m_selectedMetadata.m_transformationRotation[2].ToString();
            m_detailsEditableRotQW.text = m_selectedMetadata.m_transformationRotation[3].ToString();
        }
        else
        {
            m_selectedMetadata = null;
            m_detailsParent.gameObject.SetActive(false);
        }
    }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");

        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        // Save the text in a background thread.
        m_savingTextParent.gameObject.SetActive(true);
        m_saveThread = new Thread(delegate()
        {
            // Save the name put in with the Area Description.
            AreaDescription areaDescription   = AreaDescription.SaveCurrent();
            AreaDescription.Metadata metadata = areaDescription.GetMetadata();
            metadata.m_name = kb.text;
            areaDescription.SaveMetadata(metadata);
        });
        m_saveThread.Start();
    }
Beispiel #7
0
    public void InitTangoScene()
    {
        string     prefabPath = "Prefabs/UI/SceneUI";
        GameObject content    = transform.FindChild("Top/SceneBtn/Scroll View/Viewport/Content").gameObject;

        AreaDescription[] areaDescriptionList = AreaDescription.GetList();
        if (areaDescriptionList == null)
        {
            return;
        }
        for (int i = 0; i < areaDescriptionList.Length; i++)
        {
            AreaDescription desc = areaDescriptionList [i];
            _AreaDescription.Add(desc);             //保存所有的描述

            GameObject data = Instantiate(Resources.Load(prefabPath, typeof(GameObject))) as GameObject;
            data.transform.SetParent(content.transform, false);

            Text name = data.transform.FindChild("desc").GetComponent <Text> ();
            name.text = desc.GetMetadata().m_name;

            int    pos    = i;
            Button button = data.gameObject.GetComponent <Button> ();
            button.onClick.AddListener(delegate() {
                this.PressLoad(pos);
            });
        }
    }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");

        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        if (kb.done)
        {
            // Disable interaction before saving.
            m_initialized = false;
            m_savingText.gameObject.SetActive(true);
            m_saveThread = new Thread(delegate()
            {
                // Start saving process in another thread.
                m_curAreaDescription = AreaDescription.SaveCurrent();
                AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
                metadata.m_name = kb.text;
                m_curAreaDescription.SaveMetadata(metadata);
            });
            m_saveThread.Start();
        }
    }
Beispiel #9
0
 public void OnTangoPermissions(bool permissionsGranted)
 {
     if (permissionsGranted)
     {
         AreaDescription[]        list = AreaDescription.GetList();
         AreaDescription.Metadata mostRecentMetadata = null;
         if (list.Length > 0)
         {
             // Find and load the most recent Area Description
             area = list[0];
             mostRecentMetadata = area.GetMetadata();
             foreach (AreaDescription areaDescription in list)
             {
                 AreaDescription.Metadata metadata = areaDescription.GetMetadata();
                 if (metadata.m_name.Contains("nathanbrandon00"))
                 {
                     area = areaDescription;
                     break;
                 }
             }
             loadedMessage = "AREA LOADED" + Environment.NewLine;
             m_tangoApplication.Startup(area);
             loadSuccess = true;
         }
     }
 }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
#if UNITY_EDITOR
        // Work around lack of on-screen keyboard in editor:
        if (m_displayGuiTextInput || m_saveThread != null)
        {
            yield break;
        }

        m_displayGuiTextInput  = true;
        m_guiTextInputContents = "Unnamed";
        while (m_displayGuiTextInput)
        {
            yield return(null);
        }

        bool saveConfirmed = m_guiTextInputResult;
#else
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");
        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        bool saveConfirmed = kb.done;
#endif
        if (saveConfirmed)
        {
            // Disable interaction before saving.
            m_initialized = false;
            m_savingText.gameObject.SetActive(true);
            if (m_tangoApplication.m_areaDescriptionLearningMode)
            {
                m_saveThread = new Thread(delegate()
                {
                    // Start saving process in another thread.
                    m_curAreaDescription = AreaDescription.SaveCurrent();
                    AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
#if UNITY_EDITOR
                    metadata.m_name = m_guiTextInputContents;
#else
                    metadata.m_name = kb.text;
#endif
                    m_curAreaDescription.SaveMetadata(metadata);
                });
                m_saveThread.Start();
            }
            else
            {
                _SaveMarkerToDisk();
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
        }
    }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
#if UNITY_EDITOR
        // Work around lack of on-screen keyboard in editor:
        if (m_displayGuiTextInput || m_saveThread != null)
        {
            yield break;
        }

        m_displayGuiTextInput  = true;
        m_guiTextInputContents = "Unnamed";
        while (m_displayGuiTextInput)
        {
            yield return(null);
        }
#elif UNITY_ANDROID
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");
        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        // Store name so it is available when we use it from thread delegate.
        var fileNameFromKeyboard = kb.text;
#endif
#if UNITY_ANDROID || UNITY_EDITOR
        // Save the text in a background thread.
        m_savingTextParent.gameObject.SetActive(true);
        m_saveThread = new Thread(delegate()
        {
            // Save the name put in with the Area Description.
            AreaDescription areaDescription   = AreaDescription.SaveCurrent();
            AreaDescription.Metadata metadata = areaDescription.GetMetadata();
#if UNITY_EDITOR
            metadata.m_name = m_guiTextInputContents;
#else
            metadata.m_name = fileNameFromKeyboard;
#endif
            areaDescription.SaveMetadata(metadata);
        });

        m_saveThread.Start();
#else
        yield return(null);
#endif
    }
Beispiel #12
0
    /// <summary>
    /// 保存区域描述.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
                #if UNITY_EDITOR
        // Work around lack of on-screen keyboard in editor:
        if (m_displayGuiTextInput || m_saveThread != null)
        {
            yield break;
        }

        m_displayGuiTextInput  = true;
        m_guiTextInputContents = "Unnamed";
        while (m_displayGuiTextInput)
        {
            yield return(null);
        }

        bool saveConfirmed = m_guiTextInputResult;
                #else
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");
        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        bool saveConfirmed = kb.done;
                #endif
        // 保存.
        if (saveConfirmed)
        {
            // 保存前禁用交互.
            m_tangoReady = false;
            UIManager.Instance.ShowMessage("Saving...");
            if (m_tangoApplication.m_areaDescriptionLearningMode)             // 学习模式, 保存当前区域描述.
            {
                m_curAreaDescription = AreaDescription.SaveCurrent();
                AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
                                #if UNITY_EDITOR
                metadata.m_name = m_guiTextInputContents;
                                #else
                metadata.m_name = kb.text;
                                #endif
                m_curAreaDescription.SaveMetadata(metadata);
            }
            _SaveUnitToDisk();
        }
    }
Beispiel #13
0
 // If the name is blank or specified ADF is not found, null will be returned.
 AreaDescription FindAdf(string name)
 {
     if (name.Length == 0)
     {
         return(null);
     }
     else
     {
         AreaDescription adf = TangoUtil.FindAdfByName(name);
         if (adf == null)
         {
             Debug.LogWarning("ADF not found; creating a new file.");
         }
         else
         {
             Debug.LogFormat("ADF found: \n Name: {0}, \n DateTime: {1}, \n UUID: {2}",
                             adf.GetMetadata().m_name,
                             adf.GetMetadata().m_dateTime,
                             adf.m_uuid);
         }
         return(adf);
     }
 }
Beispiel #14
0
 private IEnumerator _DoSaveCurrentAreaDescription()
 {
     if (m_saveThread != null)
     {
         yield break;
     }
     if (m_tangoApplication.m_areaDescriptionLearningMode)
     {
         m_saveThread = new Thread(delegate()
         {
             // Start saving process in another thread.
             m_currentAreaDescription          = AreaDescription.SaveCurrent();
             AreaDescription.Metadata metadata = m_currentAreaDescription.GetMetadata();
             metadata.m_name = "Demo";
             m_currentAreaDescription.SaveMetadata(metadata);
         });
         m_saveThread.Start();
     }
 }
Beispiel #15
0
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");

        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        if (kb.done)
        {
            // Disable interaction before saving.
            m_initialized = false;
            m_savingText.gameObject.SetActive(true);
            if (m_tangoApplication.m_areaDescriptionLearningMode)
            {
                m_saveThread = new Thread(delegate()
                {
                    // Start saving process in another thread.
                    m_curAreaDescription = AreaDescription.SaveCurrent();
                    AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
                    metadata.m_name = kb.text;
                    m_curAreaDescription.SaveMetadata(metadata);
                });
                m_saveThread.Start();
            }
            else
            {
                _SaveMarkerToDisk();
                #pragma warning disable 618
                Application.LoadLevel(Application.loadedLevel);
                #pragma warning restore 618
            }
        }
    }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard touchScreenKeyboard = TouchScreenKeyboard.Open("Unnamed");

        while (!touchScreenKeyboard.done && !touchScreenKeyboard.wasCanceled)
        {
            yield return(null);
        }

        bool saveConfirmed = touchScreenKeyboard.done;

        if (saveConfirmed)
        {
            // Disable interaction before saving by removing PanelScanMenu.
            m_buttonSaveScan.interactable = false;

            // Check if Area Description Learning mode was ON (it should be)
            if (m_tangoApplication.m_areaDescriptionLearningMode)
            {
                m_saveThread = new Thread(delegate()
                {
                    // Start saving process in another thread.
                    m_areaDescription = AreaDescription.SaveCurrent();
                    AreaDescription.Metadata metadata = m_areaDescription.GetMetadata();
                    metadata.m_name = touchScreenKeyboard.text;
                    m_areaDescription.SaveMetadata(metadata);
                });
                m_saveThread.Start();
            }
        }
    }
    // <summary>
    // Actually do the Area Description save.
    // </summary>
    // <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
        //MobileNativeMessage msg = new MobileNativeMessage("Test", "saving objects");
#if UNITY_EDITOR
        // Work around lack of on-screen keyboard in editor:
        if (m_displayGuiTextInput || m_saveThread != null)
        {
            yield break;
        }

        m_displayGuiTextInput  = true;
        m_guiTextInputContents = "Unnamed";
        while (m_displayGuiTextInput)
        {
            yield return(null);
        }

        bool saveConfirmed = m_guiTextInputResult;
#else
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");
        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        bool saveConfirmed = kb.done;
#endif
        if (saveConfirmed)
        {
            Debug.Log("saving confirmed");

            // Disable interaction before saving.
            m_initialized = false;
            Debug.Log("1111111111111111111111");

            m_savingText.gameObject.SetActive(true);
            Debug.Log(m_tangoApplication.m_areaDescriptionLearningMode);

            if (m_tangoApplication.m_areaDescriptionLearningMode)
            {
                Debug.Log("learningmode on");

                m_saveThread = new Thread(delegate()
                {
                    // Start saving process in another thread.
                    m_curAreaDescription = AreaDescription.SaveCurrent();
                    AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
#if UNITY_EDITOR
                    metadata.m_name = m_guiTextInputContents;
#else
                    metadata.m_name = kb.text;
#endif
                    m_curAreaDescription.SaveMetadata(metadata);
                });
                m_saveThread.Start();
            }
            else
            {
                _SaveObjectToDisk();
#pragma warning disable 618
                Application.LoadLevel(Application.loadedLevel);
#pragma warning restore 618
            }
        }
    }
    /// <summary>
    /// Actually do the Area Description save.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    private IEnumerator _DoSaveCurrentAreaDescription()
    {
#if UNITY_EDITOR
        // Work around lack of on-screen keyboard in editor:
        if (m_displayGuiTextInput || m_saveThread != null)
        {
            yield break;
        }

        m_displayGuiTextInput  = true;
        m_guiTextInputContents = "Unnamed";
        while (m_displayGuiTextInput)
        {
            yield return(null);
        }

        bool saveConfirmed = m_guiTextInputResult;
#elif UNITY_ANDROID
        if (TouchScreenKeyboard.visible || m_saveThread != null)
        {
            yield break;
        }

        TouchScreenKeyboard kb = TouchScreenKeyboard.Open("Unnamed");
        while (!kb.done && !kb.wasCanceled)
        {
            yield return(null);
        }

        bool saveConfirmed = kb.done;
#endif
#if UNITY_ANDROID || UNITY_EDITOR
        if (saveConfirmed)
        {
            // Disable interaction before saving.
            m_initialized = false;
            m_savingText.gameObject.SetActive(true);
            if (m_tangoApplication.m_areaDescriptionLearningMode)
            {
                // The keyboard is not readable if you are not in the Unity main thread. Cache the value here.
                string name;
#if UNITY_EDITOR
                name = m_guiTextInputContents;
#else
                name = kb.text;
#endif

                m_saveThread = new Thread(delegate()
                {
                    // Start saving process in another thread.
                    m_curAreaDescription = AreaDescription.SaveCurrent();
                    AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
                    metadata.m_name = name;
                    m_curAreaDescription.SaveMetadata(metadata);
                });
                m_saveThread.Start();
            }
            else
            {
                _SaveMarkerToDisk();
                #pragma warning disable 618
                Application.LoadLevel(Application.loadedLevel);
                #pragma warning restore 618
            }
        }
#else
        yield return(null);
#endif
    }
Beispiel #19
0
        // Unity function
        void Start()
        {
            tango = FindObjectOfType <TangoApplication>();

            tango.Register(this);

            if (saveAdfButton)
            {
                saveAdfButton.onClick.AddListener(() => {
                    SaveCurrentADF();
                });
            }

            if (connectServiceButton)
            {
                connectServiceButton.onClick.AddListener(() => {
                    ConnectService();
                });
            }

            if (disconnectServiceButton)
            {
                disconnectServiceButton.onClick.AddListener(() => {
                    DisconnectService();
                });
            }

            if (learningAreaToggle)
            {
                learningAreaToggle.isOn = tango.m_enableAreaDescriptions;
                learningAreaToggle.onValueChanged.AddListener(shouldLearn => {
                    // Note that this won't change learning mode of (currently) running service.
                    // This will be applied to service from the next connection.
                    tango.m_areaDescriptionLearningMode = shouldLearn;
                });
            }

            if (requestPermissionsButton)
            {
                requestPermissionsButton.onClick.AddListener(() => {
                    Debug.Log("Requesting permissions...");
                    tango.RequestPermissions();
                    Debug.Log("Requested permissions.");
                });
            }

            if (selectAdfUI)
            {
                selectAdfUI.onAdfSelected += (adf) => {
                    selectedADF = adf;

                    // selectedADF may be null if creating a new ADF.
                    if (adfNameText)
                    {
                        if (selectedADF == null)
                        {
                            // If no ADF is currently selected, blank out the text field.
                            adfNameText.text = "";
                        }
                        else
                        {
                            // If an ADF is selected, reflect the name to the text field.
                            adfNameText.text = selectedADF.GetMetadata().m_name;
                        }
                    }
                };
            }
        }
Beispiel #20
0
        IEnumerator _ReloadList()
        {
            if (reloading)
            {
                // Don't reload twice at the same time
                yield break;
            }

            try {
                Debug.Log("Loading ADF list...");

                reloading = true;

                loadingScreen.SetActive(true);

                // Make sure loading screen is displayed
                yield return(new WaitForSeconds(0.5f));

                // clear the list
                foreach (var item in GetListedItems())
                {
                    if (item != itemPrototype)
                    {
                        Destroy(item.gameObject);
                    }
                }

                // the first item is "null" that means to create a new ADF
                {
                    TangoAdfListItem item = AddNewItem();

                    item.SetName("(Create a new ADF)");

                    item.OnSelected(() => onAdfSelected(null));
                }

                // construct items from existing ADFs
                foreach (var _adf in GetAllSortedADFs())
                {
                    // foreach is stupid
                    AreaDescription adf = _adf;

                    // spawn an item in the list
                    TangoAdfListItem item = AddNewItem();

                    // construct UI of item
                    item.SetUUID(adf.m_uuid);
                    item.SetName(adf.GetMetadata().m_name);
                    item.SetTime(adf.GetMetadata().m_dateTime);

                    // when item is clicked, adf will be selected.
                    item.OnSelected(() => onAdfSelected(adf));
                }
            } finally {
                reloading = false;

                loadingScreen.SetActive(false);

                Debug.Log("Finished loading ADF list...");
            }
        }