コード例 #1
0
        public void Update()
        {
            if (!enableMixedReality && !prevEnableMixedReality)
            {
                return;
            }

            if ((UnityEngine.Object)Camera.main != (UnityEngine.Object)null)
            {
                suppressDisableMixedRealityBecauseOfNoMainCameraWarning = false;

                Camera mainCamera = MainCamera;
                if ((Camera)mainCamera == (UnityEngine.Object)null)
                {
                    Console.Write("mainCamera null");
                    return;
                }

                if (enableMixedReality)
                {
                    if (base.gameObject == null)
                    {
                        Console.Write("base.gameObject is null");
                        return;
                    }

                    System.Object[] parameters = { base.gameObject, mainCamera, oVRManager.compositionMethod, oVRManager.useDynamicLighting, oVRManager.capturingCameraDevice, oVRManager.depthQuality };
                    getUpdateMethod().Invoke(null, parameters);
                    //OVRMixedReality.Update(base.gameObject, MainCamera, OVRManager.CompositionMethod.Sandwich, false, OVRManager.CameraDevice.WebCamera0, OVRManager.DepthQuality.High);

                    // it seems we need to add post processing effects to the final image, as somehow they don't get applied automatically!
                    // for that PostProcess will apply them, but we need to add the HackPostProcess gameobject into the just created camera (which we didn't create)
                    // so we need to get the camera out of the OVRMixedReality package and add the post process hack to them
                    // - is there a better way to do this ?
                    if (!addedPostProcess)
                    {
                        OVRComposition ovrComposition = (OVRComposition)getOvrMixedRealityType().GetField("currentComposition", BindingFlags.Static | BindingFlags.Public).GetValue(null);
                        if (ovrComposition != null)
                        {
                            if (ovrComposition is OVRDirectComposition)
                            {
                                ((OVRDirectComposition)ovrComposition).directCompositionCamera.gameObject.AddComponent <OVRManagerHackPostProcess>();
                            }
                            else if (ovrComposition is OVRExternalComposition)
                            {
                                Camera backgroundCamera = (Camera)ovrComposition.GetType().GetField("backgroundCamera", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ovrComposition);
                                backgroundCamera.gameObject.AddComponent <OVRManagerHackPostProcess>();

                                Camera foregroundCamera = (Camera)ovrComposition.GetType().GetField("foregroundCamera", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ovrComposition);
                                foregroundCamera.gameObject.AddComponent <OVRManagerHackPostProcess>();
                            }
                            else if (ovrComposition is OVRSandwichComposition)
                            {
                                ((OVRSandwichComposition)ovrComposition).bgCamera.gameObject.AddComponent <OVRManagerHackPostProcess>();
                                ((OVRSandwichComposition)ovrComposition).fgCamera.gameObject.AddComponent <OVRManagerHackPostProcess>();
                            }
                        }


                        addedPostProcess = true;
                    }
                }
                if (prevEnableMixedReality && !enableMixedReality)
                {
                    Console.WriteLine("Cleanup!");
                    getCleanupMethod().Invoke(null, null);
                    addedPostProcess = false;
                    //OVRMixedReality.Cleanup();
                }
                prevEnableMixedReality = enableMixedReality;
            }
            else if (!suppressDisableMixedRealityBecauseOfNoMainCameraWarning)
            {
                Debug.LogWarning("x Main Camera is not set, Mixed Reality disabled");
                suppressDisableMixedRealityBecauseOfNoMainCameraWarning = true;
            }
        }