private async void OnEnable()
        {
            Texture2D tex = new Texture2D(1, 1);

            tex.hideFlags = HideFlags.HideAndDontSave;
            tex.SetPixels(new Color[] { new Color(1, 1, 1, 0) });
            tex.Apply();

            previewStyle = new GUIStyle();
            previewStyle.normal.background = tex;

            cam = new CameraCaptureWebcam(null, Camera.main.fieldOfView);

            CameraResolution resolution = new CameraResolution();

            resolution.nativeResolution = NativeResolutionMode.Largest;
            resolution.resize           = ResizeWhen.Never;

            await cam.InitializeAsync(true, resolution);
        }
        private void Awake()
        {
            // Save initial settings in case we wish to restore them
            startSky = RenderSettings.skybox;

            // Pick camera based on platform
                        #if WINDOWS_UWP && !UNITY_EDITOR
            captureCamera = new CameraCaptureUWP();
                        #elif (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            captureCamera = new CameraCaptureARFoundation();
                        #else
            // On a desktop computer, or certain laptops, we may not have access to any cameras.
            if (WebCamTexture.devices.Length <= 0)
            {
                // Alternatively, you can simulate a camera by taking screenshots instead.
                // captureCamera = new CameraCaptureScreen(Camera.main);

                // When disabling and returning immediately, OnDisable will be called without
                // OnEnable ever getting called.
                enabled = false;
                return;
            }
            else
            {
                captureCamera = new CameraCaptureWebcam(Camera.main.transform, Camera.main.fieldOfView);
            }
                        #endif

            // Make sure we have access to a probe in the scene
            if (probe == null)
            {
                probe = FindObjectOfType <ReflectionProbe>();
            }
            if (probe == null)
            {
                GameObject probeObj = new GameObject("_LightCaptureProbe", typeof(ReflectionProbe));
                probeObj.transform.SetParent(transform, false);
                probe = probeObj.GetComponent <ReflectionProbe>();

                probe.size          = Vector3.one * 10000;
                probe.boxProjection = false;
            }

            // Same with a camera object
            if (cameraOrientation == null)
            {
                cameraOrientation = Camera.main.transform;
            }

            // And check for a directional light in the scene
            if (useDirectionalLight && directionalLight == null)
            {
                Light[] lights = FindObjectsOfType <Light>();
                for (int i = 0; i < lights.Length; i++)
                {
                    if (lights[i].type == LightType.Directional)
                    {
                        directionalLight = lights[i];
                        break;
                    }
                }
                if (directionalLight == null)
                {
                    GameObject lightObj = new GameObject("_DirectionalLight", typeof(Light));
                    lightObj.transform.SetParent(transform, false);
                    directionalLight      = lightObj.GetComponent <Light>();
                    directionalLight.type = LightType.Directional;
                }
            }

            // Save initial light settings
            if (directionalLight != null)
            {
                startLightColor      = directionalLight.color;
                startLightRot        = directionalLight.transform.rotation;
                startLightBrightness = directionalLight.intensity;
            }
        }