Пример #1
0
        async UniTask DoStart()
        {
            await _privilegeRequester.WaitAllGranted(usingZi : false);

            Debug.Log("Finished Magic Leap privileges");

            _captureDevice = Application.isEditor
                                ? (ICaptureDevice) new EditorCaptureDevice()
                                : (ICaptureDevice) new MLAsyncCaptureDevice();

            _visionTextClient = new GVTextClient(_credentials);
            _textInterpreter  = new TwitterHandleInterpreter();

            _handleList.OnHandleSelected += handle =>
            {
                OnHandleSelected(handle);
            };

            _jpgTexture       = new Texture2D(1, 1);
            _jpgImage.texture = _jpgTexture;

            _captureDevice.Enable();
            _captureImage.texture = _captureDevice.GetPreviewTexture();

            while (this)
            {
                _captureIndicator.SetActive(true);

                DateTime captureStart = DateTime.Now;
                byte[]   image        = await _captureDevice.Capture();

                TimeSpan captureTime = DateTime.Now - captureStart;

                _jpgTexture.LoadImage(image);
                _jpgTexture.Apply();

                _captureIndicator.SetActive(false);
                _annotateIndicator.SetActive(true);

                DateTime annotateStart = DateTime.Now;
                var      annotation    = await _visionTextClient.Annotate(image);

                TimeSpan annotateTime = DateTime.Now - annotateStart;

                Debug.Log($"Capture: {captureTime.TotalSeconds:0.0}, " +
                          $"Annotate: {annotateTime.TotalSeconds:0.0}");

                _annotateIndicator.SetActive(false);

                if (annotation == null)
                {
                    Debug.LogWarning("Received null text annotation");
                    _annotateText.text = "<null>";
                    continue;
                }

                string text = annotation.Description;
                _annotateText.text = text.Replace("\n", " ");

                if (_textInterpreter.Interpret(text))
                {
                    Debug.Log("Found new handle(s)");
                }

                _handleList.SetHandles(_textInterpreter.Handles);
            }
        }