Permalink
Browse files

fix(Examples): automatically repair broken Oculus prefab instances

The example scenes all have broken Oculus prefab instances unless the
specific version of the Oculus SDK is used. This fix uses a script to
attempt to repair the prefab by recreating the setup automatically.
  • Loading branch information...
thestonefox committed Sep 25, 2018
1 parent d88c9ea commit c6062d3984b10e3767747721aa47e72b2136ae29
View
@@ -9,6 +9,8 @@
/[Aa]ssets/[Ss]team[Vv][Rr].meta
/[Aa]ssets/[Oo][Vv][Rr]/*
/[Aa]ssets/[Oo][Vv][Rr].meta
/[Aa]ssets/[Oo]culus/*
/[Aa]ssets/[Oo]culus.meta
/[Aa]ssets/[Oo]culus[Pp]latform/*
/[Aa]ssets/[Oo]culus[Pp]latform.meta
/[Aa]ssets/[Oo][Vv][Rr][Aa]vatar/*

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,20 @@
namespace VRTK.Examples.Utilities
{
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(VRTKExample_FixSetup))]
public class VRTKExample_FixSetupEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
VRTKExample_FixSetup myScript = (VRTKExample_FixSetup)target;
if (GUILayout.Button("Fix SDK Setups"))
{
myScript.ApplyFixes();
}
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,74 @@
#if UNITY_EDITOR
namespace VRTK.Examples.Utilities
{
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class VRTKExample_FixSetup : MonoBehaviour
{
public virtual void ApplyFixes()
{
FixOculus();
}
protected virtual void Awake()
{
ApplyFixes();
}
protected virtual void FixOculus()
{
#if VRTK_DEFINE_SDK_OCULUS
string oculusPath = "[VRTK_SDKManager]/[VRTK_SDKSetups]/Oculus";
GameObject oculusSDK = GameObject.Find(oculusPath);
GameObject currentRig = GameObject.Find(oculusPath + "/OVRCameraRig");
GameObject currentAvatar = GameObject.Find(oculusPath + "/LocalAvatar");
VRTK_SDKSetup oculusSetup = oculusSDK.GetComponent<VRTK_SDKSetup>();
if (currentRig != null)
{
DestroyImmediate(currentRig);
}
if (currentAvatar != null)
{
DestroyImmediate(currentAvatar);
}
GameObject ovrCameraRig = PrefabUtility.InstantiatePrefab((GameObject)AssetDatabase.LoadAssetAtPath("Assets/Oculus/VR/Prefabs/OVRCameraRig.prefab", typeof(GameObject))) as GameObject;
if (ovrCameraRig != null)
{
ovrCameraRig.transform.SetParent(oculusSDK.transform);
ovrCameraRig.SetActive(false);
oculusSetup.actualBoundaries = ovrCameraRig;
oculusSetup.actualHeadset = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/CenterEyeAnchor");
oculusSetup.actualLeftController = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/LeftHandAnchor");
oculusSetup.actualRightController = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/RightHandAnchor");
OVRManager ovrManager = ovrCameraRig.GetComponent<OVRManager>();
ovrManager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel;
Debug.Log("Successfully repaired Oculus OVRCameraRig prefab");
}
GameObject ovrAvatar = PrefabUtility.InstantiatePrefab((GameObject)AssetDatabase.LoadAssetAtPath("Assets/Oculus/Avatar/Content/Prefabs/LocalAvatar.prefab", typeof(GameObject))) as GameObject;
if (ovrAvatar == null)
{
//legacy location
ovrAvatar = PrefabUtility.InstantiatePrefab((GameObject)AssetDatabase.LoadAssetAtPath("Assets/OvrAvatar/Content/Prefabs/LocalAvatar.prefab", typeof(GameObject))) as GameObject;
}
if (ovrAvatar != null)
{
ovrAvatar.transform.SetParent(oculusSDK.transform);
ovrAvatar.SetActive(false);
oculusSetup.modelAliasLeftController = GameObject.Find(oculusPath + "/LocalAvatar/controller_left");
oculusSetup.modelAliasRightController = GameObject.Find(oculusPath + "/LocalAvatar/controller_right");
GameObject.Find(oculusPath + "/LocalAvatar/hand_left").SetActive(false);
GameObject.Find(oculusPath + "/LocalAvatar/hand_right").SetActive(false);
VRTK_TransformFollow transformFollow = ovrAvatar.AddComponent<VRTK_TransformFollow>();
transformFollow.gameObjectToFollow = ovrCameraRig;
Debug.Log("Successfully repaired Oculus LocalAvatar prefab");
}
#endif
}
}
}
#endif

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -42,7 +42,7 @@ RenderSettings:
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
@@ -54,7 +54,7 @@ LightmapSettings:
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 8
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
@@ -89,7 +89,7 @@ LightmapSettings:
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_LightingDataAsset: {fileID: 0}
m_ShadowMaskMode: 2
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
@@ -201,6 +201,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 0
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &45327575
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -442,6 +443,7 @@ GameObject:
m_Component:
- component: {fileID: 101641546}
- component: {fileID: 101641545}
- component: {fileID: 101641547}
m_Layer: 0
m_Name: '[VRTK_SDKManager]'
m_TagString: Untagged
@@ -491,6 +493,17 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &101641547
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 101641544}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dbd363faecdfb6d4da2d9cdab9de34f8, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &109582311
GameObject:
m_ObjectHideFlags: 0
@@ -1160,6 +1173,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &437062054
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1326,6 +1340,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &516690990
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1736,15 +1751,15 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 22406496, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
value: -25
objectReference: {fileID: 0}
- target: {fileID: 22406496, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_SizeDelta.x
value: 315
objectReference: {fileID: 0}
- target: {fileID: 22406496, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_SizeDelta.y
value: 0
value: 50
objectReference: {fileID: 0}
- target: {fileID: 22435444, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_AnchorMin.y
@@ -1760,23 +1775,23 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 22435444, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_AnchoredPosition.y
value: 0
value: -25
objectReference: {fileID: 0}
- target: {fileID: 22435444, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_SizeDelta.x
value: 325
objectReference: {fileID: 0}
- target: {fileID: 22435444, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_SizeDelta.y
value: 0
value: 50
objectReference: {fileID: 0}
- target: {fileID: 22435580, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_SizeDelta.x
value: 59
objectReference: {fileID: 0}
- target: {fileID: 22435580, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_SizeDelta.y
value: 0
value: 16
objectReference: {fileID: 0}
- target: {fileID: 11440894, guid: 6b9dbb125b47726449ffe47a4110f342, type: 2}
propertyPath: m_Size
@@ -2557,6 +2572,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 0
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &911137776
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -3278,6 +3294,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &1101259493
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -5661,6 +5678,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &1703159951
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -42,7 +42,7 @@ RenderSettings:
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
@@ -54,7 +54,7 @@ LightmapSettings:
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 8
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
@@ -89,7 +89,7 @@ LightmapSettings:
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_LightingDataAsset: {fileID: 0}
m_ShadowMaskMode: 2
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
@@ -752,6 +752,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &243141330
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1129,6 +1130,7 @@ GameObject:
m_Component:
- component: {fileID: 315727735}
- component: {fileID: 315727734}
- component: {fileID: 315727736}
m_Layer: 0
m_Name: '[VRTK_SDKManager]'
m_TagString: Untagged
@@ -1178,6 +1180,17 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &315727736
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 315727733}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dbd363faecdfb6d4da2d9cdab9de34f8, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &324413262
GameObject:
m_ObjectHideFlags: 0
@@ -1762,6 +1775,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 0
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &615878202
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -3940,6 +3954,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &1208192149
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -6224,6 +6239,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 0
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &1939791525
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -6346,6 +6362,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &1959794856
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -6741,6 +6758,7 @@ MonoBehaviour:
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &2044667786
MonoBehaviour:
m_ObjectHideFlags: 0
Oops, something went wrong.

0 comments on commit c6062d3

Please sign in to comment.