Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);
            mSurfaceView           = FindViewById <GLSurfaceView>(Resource.Id.surfaceview);
            mDisplayRotationHelper = new DisplayRotationHelper(this);

            Java.Lang.Exception exception = null;
            string message = null;

            try {
                mSession = new Session(/*context=*/ this);
            } catch (UnavailableArcoreNotInstalledException e) {
                message   = "Please install ARCore";
                exception = e;
            } catch (UnavailableApkTooOldException e) {
                message   = "Please update ARCore";
                exception = e;
            } catch (UnavailableSdkTooOldException e) {
                message   = "Please update this app";
                exception = e;
            } catch (Java.Lang.Exception e) {
                exception = e;
                message   = "This device does not support AR";
            }

            if (message != null)
            {
                Toast.MakeText(this, message, ToastLength.Long).Show();
                return;
            }

            // Create default config, check is supported, create session from that config.
            var config = new Google.AR.Core.Config(mSession);

            if (!mSession.IsSupported(config))
            {
                Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show();
                Finish();
                return;
            }

            mGestureDetector = new Android.Views.GestureDetector(this, new SimpleTapGestureDetector {
                SingleTapUpHandler = (MotionEvent arg) => {
                    onSingleTap(arg);
                    return(true);
                },
                DownHandler = (MotionEvent arg) => true
            });

            mSurfaceView.SetOnTouchListener(this);

            // Set up renderer.
            mSurfaceView.PreserveEGLContextOnPause = true;
            mSurfaceView.SetEGLContextClientVersion(2);
            mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0);             // Alpha used for plane blending.
            mSurfaceView.SetRenderer(this);
            mSurfaceView.RenderMode = Rendermode.Continuously;
        }