Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
d88c9ea
commit c6062d3
Showing
13 changed files
with
479 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Assets/VRTK/Examples/ExampleResources/SharedResources/Scripts/Editor.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
...TK/Examples/ExampleResources/SharedResources/Scripts/Editor/VRTKExample_FixSetupEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...amples/ExampleResources/SharedResources/Scripts/Editor/VRTKExample_FixSetupEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
Assets/VRTK/Examples/ExampleResources/SharedResources/Scripts/VRTKExample_FixSetup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
12 changes: 12 additions & 0 deletions
12
Assets/VRTK/Examples/ExampleResources/SharedResources/Scripts/VRTKExample_FixSetup.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.