public void ForceLast() { if (values != null) { // Restore values on new instance foreach (DictionaryEntry entry in values) { var f = entry.Key as FieldInfo; f.SetValue(this, entry.Value); } values = null; } else { // Make sure it's the last component var components = GetComponents <Component>(); // But first make sure there aren't any other SteamVR_Cameras on this object. for (int i = 0; i < components.Length; i++) { var c = components[i] as SteamVR_Camera; if (c != null && c != this) { if (c.flip != null) { Object.DestroyImmediate(c.flip); } Object.DestroyImmediate(c); } } components = GetComponents <Component>(); if (this != components[components.Length - 1] || flip == null) { var go = gameObject; if (flip == null) { flip = go.AddComponent <SteamVR_CameraFlip>(); } // Store off values to be restored on new instance values = new Hashtable(); var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (var f in fields) { if (f.IsPublic || f.IsDefined(typeof(SerializeField), true)) { values[f] = f.GetValue(this); } } GameObject.DestroyImmediate(this); go.AddComponent <SteamVR_Camera>().ForceLast(); } } }
public void ForceLast() { if (SteamVR_Camera.values != null) { foreach (DictionaryEntry dictionaryEntry in SteamVR_Camera.values) { FieldInfo fieldInfo = dictionaryEntry.Key as FieldInfo; fieldInfo.SetValue(this, dictionaryEntry.Value); } SteamVR_Camera.values = null; } else { Component[] components = base.GetComponents <Component>(); for (int i = 0; i < components.Length; i++) { SteamVR_Camera steamVR_Camera = components[i] as SteamVR_Camera; if (steamVR_Camera != null && steamVR_Camera != this) { if (steamVR_Camera.flip != null) { UnityEngine.Object.DestroyImmediate(steamVR_Camera.flip); } UnityEngine.Object.DestroyImmediate(steamVR_Camera); } } components = base.GetComponents <Component>(); if (this != components[components.Length - 1] || this.flip == null) { if (this.flip == null) { this.flip = base.gameObject.AddComponent <SteamVR_CameraFlip>(); } SteamVR_Camera.values = new Hashtable(); FieldInfo[] fields = base.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] array = fields; for (int j = 0; j < array.Length; j++) { FieldInfo fieldInfo2 = array[j]; if (fieldInfo2.IsPublic || fieldInfo2.IsDefined(typeof(SerializeField), true)) { SteamVR_Camera.values[fieldInfo2] = fieldInfo2.GetValue(this); } } GameObject gameObject = base.gameObject; UnityEngine.Object.DestroyImmediate(this); gameObject.AddComponent <SteamVR_Camera>().ForceLast(); } } }
public void ForceLast() { if (values != null) { // Restore values on new instance foreach (DictionaryEntry entry in values) { var f = entry.Key as FieldInfo; f.SetValue(this, entry.Value); } values = null; } else { // Make sure it's the last component var components = GetComponents<Component>(); if (this != components[components.Length - 1] || flip == null) { var go = gameObject; if (flip == null) flip = go.AddComponent<SteamVR_CameraFlip>(); // Store off values to be restored on new instance values = new Hashtable(); var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (var f in fields) if (f.IsPublic || f.IsDefined(typeof(SerializeField), true)) values[f] = f.GetValue(this); GameObject.DestroyImmediate(this); go.AddComponent<SteamVR_Camera>().ForceLast(); } } }
void OnEnable() { // Bail if no hmd is connected var vr = SteamVR.instance; if (vr == null) { if (head != null) { head.GetComponent <SteamVR_GameView>().enabled = false; head.GetComponent <SteamVR_TrackedObject>().enabled = false; } if (flip != null) { flip.enabled = false; } enabled = false; return; } #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) // Convert camera rig for native OpenVR integration. var t = transform; if (head != t) { Expand(); t.parent = origin; while (head.childCount > 0) { head.GetChild(0).parent = t; } // Keep the head around, but parent to the camera now since it moves with the hmd // but existing content may still have references to this object. head.parent = t; head.localPosition = Vector3.zero; head.localRotation = Quaternion.identity; head.localScale = Vector3.one; head.gameObject.SetActive(false); _head = t; } if (flip != null) { DestroyImmediate(flip); flip = null; } #else // Ensure rig is properly set up Expand(); if (blitMaterial == null) { blitMaterial = new Material(Shader.Find("Custom/SteamVR_Blit")); } // Set remaining hmd specific settings var camera = GetComponent <Camera>(); camera.fieldOfView = vr.fieldOfView; camera.aspect = vr.aspect; camera.eventMask = 0; // disable mouse events camera.orthographic = false; // force perspective camera.enabled = false; // manually rendered by SteamVR_Render if (camera.actualRenderingPath != RenderingPath.Forward && QualitySettings.antiAliasing > 1) { Debug.LogWarning("MSAA only supported in Forward rendering path. (disabling MSAA)"); QualitySettings.antiAliasing = 0; } // Ensure game view camera hdr setting matches var headCam = head.GetComponent <Camera>(); if (headCam != null) { headCam.hdr = camera.hdr; headCam.renderingPath = camera.renderingPath; } #endif if (ears == null) { var e = transform.GetComponentInChildren <SteamVR_Ears>(); if (e != null) { _ears = e.transform; } } if (ears != null) { ears.GetComponent <SteamVR_Ears>().vrcam = this; } SteamVR_Render.Add(this); }
void OnEnable() { try { #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_5) // Convert camera rig for native OpenVR integration. var t = transform; if (head != t) { Expand(); t.parent = origin; while (head.childCount > 0) { head.GetChild(0).parent = t; } DestroyImmediate(head.gameObject); _head = t; } if (flip != null) { DestroyImmediate(flip); flip = null; } if (!SteamVR.usingNativeSupport) { enabled = false; return; } #else System.Console.WriteLine("OK"); // Bail if no hmd is connected var vr = SteamVR.instance; if (vr == null) { if (head != null) { head.GetComponent <SteamVR_GameView>().enabled = false; head.GetComponent <SteamVR_TrackedObject>().enabled = false; } if (flip != null) { flip.enabled = false; } enabled = false; return; } // Ensure rig is properly set up Expand(); System.Console.WriteLine("OK2"); if (blitMaterial == null) { System.Console.WriteLine("OK3"); blitMaterial = new Material(UnityHelper.GetShader("SteamVR_Blit")); System.Console.WriteLine("OK4" + blitMaterial == null); } // Set remaining hmd specific settings var camera = GetComponent <Camera>(); camera.fieldOfView = vr.fieldOfView; camera.aspect = vr.aspect; camera.eventMask = 0; // disable mouse events camera.orthographic = false; // force perspective camera.enabled = false; // manually rendered by SteamVR_Render System.Console.WriteLine("OK5"); if (camera.actualRenderingPath != RenderingPath.Forward && QualitySettings.antiAliasing > 1) { Console.WriteLine("MSAA only supported in Forward rendering path. (disabling MSAA)"); QualitySettings.antiAliasing = 0; } // Ensure game view camera hdr setting matches var headCam = head.GetComponent <Camera>(); if (headCam != null) { headCam.hdr = camera.hdr; headCam.renderingPath = camera.renderingPath; } #endif System.Console.WriteLine("OK6"); try { ears.GetComponent <SteamVR_Ears>().vrcam = this; } catch (System.Exception e) { Logger.Info("Ears not found"); } System.Console.WriteLine("OK7"); SteamVR_Render.Add(this); System.Console.WriteLine("OK8"); } catch (Exception e2) { Console.WriteLine(e2); } }
void OnEnable() { // Bail if no hmd is connected var vr = SteamVR.instance; if (vr == null) { if (head != null) { head.GetComponent<SteamVR_GameView>().enabled = false; head.GetComponent<SteamVR_TrackedObject>().enabled = false; } if (flip != null) flip.enabled = false; enabled = false; return; } #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) // Convert camera rig for native OpenVR integration. var t = transform; if (head != t) { Expand(); t.parent = origin; while (head.childCount > 0) head.GetChild(0).parent = t; // Keep the head around, but parent to the camera now since it moves with the hmd // but existing content may still have references to this object. head.parent = t; head.localPosition = Vector3.zero; head.localRotation = Quaternion.identity; head.localScale = Vector3.one; head.gameObject.SetActive(false); _head = t; } if (flip != null) { DestroyImmediate(flip); flip = null; } #else // Ensure rig is properly set up Expand(); if (blitMaterial == null) { blitMaterial = new Material(Shader.Find("Custom/SteamVR_Blit")); } // Set remaining hmd specific settings var camera = GetComponent<Camera>(); camera.fieldOfView = vr.fieldOfView; camera.aspect = vr.aspect; camera.eventMask = 0; // disable mouse events camera.orthographic = false; // force perspective camera.enabled = false; // manually rendered by SteamVR_Render if (camera.actualRenderingPath != RenderingPath.Forward && QualitySettings.antiAliasing > 1) { Debug.LogWarning("MSAA only supported in Forward rendering path. (disabling MSAA)"); QualitySettings.antiAliasing = 0; } // Ensure game view camera hdr setting matches var headCam = head.GetComponent<Camera>(); if (headCam != null) { headCam.hdr = camera.hdr; headCam.renderingPath = camera.renderingPath; } #endif if (ears == null) { var e = transform.GetComponentInChildren<SteamVR_Ears>(); if (e != null) _ears = e.transform; } if (ears != null) ears.GetComponent<SteamVR_Ears>().vrcam = this; SteamVR_Render.Add(this); }
public void ForceLast() { if (values != null) { // Restore values on new instance foreach (DictionaryEntry entry in values) { var f = entry.Key as FieldInfo; f.SetValue(this, entry.Value); } values = null; } else { // Make sure it's the last component var components = GetComponents<Component>(); // But first make sure there aren't any other SteamVR_Cameras on this object. for (int i = 0; i < components.Length; i++) { var c = components[i] as SteamVR_Camera; if (c != null && c != this) { if (c.flip != null) DestroyImmediate(c.flip); DestroyImmediate(c); } } components = GetComponents<Component>(); #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) if (this != components[components.Length - 1]) { #else if (this != components[components.Length - 1] || flip == null) { if (flip == null) flip = gameObject.AddComponent<SteamVR_CameraFlip>(); #endif // Store off values to be restored on new instance values = new Hashtable(); var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (var f in fields) if (f.IsPublic || f.IsDefined(typeof(SerializeField), true)) values[f] = f.GetValue(this); var go = gameObject; DestroyImmediate(this); go.AddComponent<SteamVR_Camera>().ForceLast(); } } }
void OnEnable() { #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) // Convert camera rig for native OpenVR integration. var t = transform; if (head != t) { Expand(); t.parent = origin; while (head.childCount > 0) head.GetChild(0).parent = t; DestroyImmediate(head.gameObject); _head = t; } if (flip != null) { DestroyImmediate(flip); flip = null; } if (!SteamVR.usingNativeSupport) { enabled = false; return; } #else // Bail if no hmd is connected var vr = SteamVR.instance; if (vr == null) { if (head != null) { head.GetComponent<SteamVR_GameView>().enabled = false; head.GetComponent<SteamVR_TrackedObject>().enabled = false; } if (flip != null) flip.enabled = false; enabled = false; return; } // Ensure rig is properly set up Expand(); if (blitMaterial == null) { blitMaterial = new Material(Shader.Find("Custom/SteamVR_Blit")); } // Set remaining hmd specific settings var camera = GetComponent<Camera>(); camera.fieldOfView = vr.fieldOfView; camera.aspect = vr.aspect; camera.eventMask = 0; // disable mouse events camera.orthographic = false; // force perspective camera.enabled = false; // manually rendered by SteamVR_Render if (camera.actualRenderingPath != RenderingPath.Forward && QualitySettings.antiAliasing > 1) { Debug.LogWarning("MSAA only supported in Forward rendering path. (disabling MSAA)"); QualitySettings.antiAliasing = 0; } // Ensure game view camera hdr setting matches var headCam = head.GetComponent<Camera>(); if (headCam != null) { headCam.hdr = camera.hdr; headCam.renderingPath = camera.renderingPath; } #endif ears.GetComponent<SteamVR_Ears>().vrcam = this; SteamVR_Render.Add(this); }
void OnEnable() { #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) // Convert camera rig for native OpenVR integration. var t = transform; if (head != t) { Expand(); t.parent = origin; while (head.childCount > 0) { head.GetChild(0).parent = t; } DestroyImmediate(head.gameObject); _head = t; } if (flip != null) { DestroyImmediate(flip); flip = null; } if (!SteamVR.usingNativeSupport) { enabled = false; return; } #else // Bail if no hmd is connected var vr = SteamVR.instance; if (vr == null) { if (head != null) { head.GetComponent <SteamVR_GameView>().enabled = false; head.GetComponent <SteamVR_TrackedObject>().enabled = false; } if (flip != null) { flip.enabled = false; } enabled = false; return; } // Ensure rig is properly set up Expand(); if (blitMaterial == null) { blitMaterial = new Material(Shader.Find("Custom/SteamVR_Blit")); } // Set remaining hmd specific settings var camera = GetComponent <Camera>(); camera.fieldOfView = vr.fieldOfView; camera.aspect = vr.aspect; camera.eventMask = 0; // disable mouse events camera.orthographic = false; // force perspective camera.enabled = false; // manually rendered by SteamVR_Render if (camera.actualRenderingPath != RenderingPath.Forward && QualitySettings.antiAliasing > 1) { Debug.LogWarning("MSAA only supported in Forward rendering path. (disabling MSAA)"); QualitySettings.antiAliasing = 0; } // Ensure game view camera hdr setting matches var headCam = head.GetComponent <Camera>(); if (headCam != null) { headCam.hdr = camera.hdr; headCam.renderingPath = camera.renderingPath; } #endif ears.GetComponent <SteamVR_Ears>().vrcam = this; SteamVR_Render.Add(this); }