public override void OnInspectorGUI() { serializedObject.Update(); s_head = serializedObject.FindProperty("s_head"); s_handLeft = serializedObject.FindProperty("s_handLeft"); s_handRight = serializedObject.FindProperty("s_handRight"); VRLocomotionRig vrLocoRig = (VRLocomotionRig)target; if (GUILayout.Button(new GUIContent("Auto Detect", "Press Auto Detect to automatically fill in the needed variables from the camera rig"))) { vrLocoRig.AutoSetup(); } EditorGUILayout.PropertyField(s_head, new GUIContent("Head", "the head transform on the VR camera rig")); EditorGUILayout.PropertyField(s_handLeft, new GUIContent("Hand Left", "the left hand transform on the VR camera rig")); EditorGUILayout.PropertyField(s_handRight, new GUIContent("Hand Right", "the right hand transform on the VR camera rig")); serializedObject.ApplyModifiedProperties(); }
private void AddLocomotionRig(out VRLocomotionRig a_vrLR) { a_vrLR = m_rig.AddComponent <VRLocomotionRig>(); a_vrLR.AutoSetup(); }
private void ShowSettingsTab() { EditorGUILayout.Separator(); SerializedProperty vrType = SerializedObject.FindProperty("vrType"); SerializedProperty movementType = SerializedObject.FindProperty("movementType"); SerializedProperty startMoveSpeed = SerializedObject.FindProperty("startMoveSpeed"); SerializedProperty rigAlreadyInScene = SerializedObject.FindProperty("haveRigPrefab"); SerializedProperty vrRig = SerializedObject.FindProperty("vrRig"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(vrType); if (EditorGUI.EndChangeCheck()) { Utility.ChangeVRType((Utility.eVRType)vrType.enumValueIndex); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(movementType); if (EditorGUI.EndChangeCheck()) { Utility.ChangeMovementType((Utility.eMovementType)movementType.enumValueIndex); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Start Movement Speed"); LocomotionSettings.startMoveSpeed = (float)EditorGUILayout.Slider((float)startMoveSpeed.floatValue, 1.0f, 4.0f); EditorGUILayout.EndHorizontal(); if (!Utility.RigInScene) { EditorGUILayout.PropertyField(vrRig); Utility.BUTTON_TEXT = "Find & Setup Locomotion"; } else { Utility.BUTTON_TEXT = "Update Rig In Scene"; } if (GUILayout.Button(Utility.BUTTON_TEXT)) { if (Utility.BUTTON_TEXT.Equals("Find & Setup Locomotion") && !Utility.RigInScene) { try { LocomotionSettings.vrRig = PrefabUtility.GetPrefabParent(FindObjectOfType <SteamVR_ControllerManager>().gameObject) as GameObject; } catch { Debug.LogError("SETUP ERROR: 'missing camera rig' Please drag in the [CameraRig] prefab provided by SteamVR and try again!"); return; } VRLocomotionRig vrLR; FindAndDisableRig(); // finds and disables the steamVR rig CreateLocoRig("[Camera Rig] - LOCO"); // Instantiating a custom rig called "[Camera Rig] - LOCO" AddNavMesh(0.5f, 1.5f); // Adding the nav mesh component and setting its height and radius AddLocomotionRig(out vrLR); // Adding the VRLocomotionRig and running the AutoSetup method to attach all the needed components AddCapsuleCollider(0.5f, 1.5f, new Vector3(0, 0.68f, 0)); // Adding the capsule collider component and setting up its radius, height, and center offset AddRigidbody(false, true); // Adding the rigidbody component and setting gravity to false and kinimetic to true AddVrCharController(); // Adds the VR character controller to allow for realtime switching AddMovementComponents(vrLR); // Adds the required movement logic for HeadBob, ArmSwing and Pulley vrLR.s_handLeft.gameObject.AddComponent <VRBasicController>(); vrLR.s_handRight.gameObject.AddComponent <VRBasicController>(); //----------------------------------------------------------------------------------------------------- // Enables the appropriate movement logic, based on your settings //----------------------------------------------------------------------------------------------------- switch (LocomotionSettings.movementType) { case Utility.eMovementType.BOBBING: m_headBob.enabled = true; m_armSwing.enabled = false; m_pulley.enabled = false; break; case Utility.eMovementType.ARM_SWING: m_headBob.enabled = false; m_armSwing.enabled = true; m_pulley.enabled = false; m_armSwing.motionType = ArmSwing.eMotionType.ARM_SWING; break; case Utility.eMovementType.BREAST_STROKE: m_headBob.enabled = false; m_armSwing.enabled = true; m_pulley.enabled = false; m_armSwing.motionType = ArmSwing.eMotionType.BREAST_STROKE; break; case Utility.eMovementType.SKIING: m_headBob.enabled = false; m_armSwing.enabled = true; m_pulley.enabled = false; m_armSwing.motionType = ArmSwing.eMotionType.SKIING; break; case Utility.eMovementType.PULLEY: m_headBob.enabled = false; m_armSwing.enabled = false; m_pulley.enabled = true; break; // DEVELOPER: IF YOU ADD YOUR OWN, DONT FORGET TO ADD A CASE TO SWITCH IT ON AND OFF } //---------------------------------------------------------------------------------------------------- Utility.RigInScene = true; } else if (Utility.RigInScene) { VRLocomotionRig vrLocoRig = null; if (!m_steamVRrig.activeInHierarchy) { try { vrLocoRig = FindObjectOfType <SteamVR_ControllerManager>().gameObject.GetComponent <VRLocomotionRig>(); } catch { vrLocoRig = null; m_steamVRrig.SetActive(true); } } if (vrLocoRig == null) { Utility.RigInScene = false; LocomotionSettings.vrRig = PrefabUtility.GetPrefabParent(m_steamVRrig.gameObject) as GameObject; //FIXME: add new functions to replace the old redundant code below! GameObject rig = Instantiate(LocomotionSettings.vrRig) as GameObject; rig.name = "[Camera Rig] - LOCO"; UnityEngine.AI.NavMeshAgent ag = rig.AddComponent <UnityEngine.AI.NavMeshAgent>(); ag.radius = 1; ag.height = 1.5f; VRLocomotionRig vrLR = rig.AddComponent <VRLocomotionRig>(); vrLR.AutoSetup(); HeadBob hd = vrLR.s_head.gameObject.AddComponent <HeadBob>(); ArmSwing ar = vrLR.s_head.gameObject.AddComponent <ArmSwing>(); Pulley pl = vrLR.s_head.gameObject.AddComponent <Pulley>(); vrLR.s_head.gameObject.AddComponent <SteamVR_UpdatePoses>(); vrLR.s_handLeft.gameObject.AddComponent <VRBasicController>(); vrLR.s_handRight.gameObject.AddComponent <VRBasicController>(); switch (LocomotionSettings.movementType) { case Utility.eMovementType.BOBBING: hd.enabled = true; ar.enabled = false; pl.enabled = false; break; case Utility.eMovementType.ARM_SWING: hd.enabled = false; ar.enabled = true; pl.enabled = false; break; case Utility.eMovementType.PULLEY: hd.enabled = false; ar.enabled = false; pl.enabled = true; break; } vrLocoRig = rig.GetComponent <VRLocomotionRig>(); m_steamVRrig.SetActive(false); Utility.RigInScene = true; } HeadBob h = vrLocoRig.s_head.gameObject.GetComponent <HeadBob>(); ArmSwing a = vrLocoRig.s_head.gameObject.GetComponent <ArmSwing>(); Pulley p = vrLocoRig.s_head.gameObject.GetComponent <Pulley>(); switch (LocomotionSettings.movementType) { case Utility.eMovementType.BOBBING: h.enabled = true; a.enabled = false; p.enabled = false; break; case Utility.eMovementType.ARM_SWING: h.enabled = false; a.enabled = true; p.enabled = false; break; case Utility.eMovementType.PULLEY: h.enabled = false; a.enabled = false; p.enabled = true; break; } m_steamVRrig.SetActive(false); } } if (GUILayout.Button("Click to reset Settings & Scene")) { Utility.RigInScene = false; try { m_steamVRrig.SetActive(true); //try { GameObject o = GameObject.Find("[Camera Rig] - LOCO"); DestroyImmediate(o); DestroyImmediate(m_steamVRrig); } catch { Debug.LogWarning("WARNING: can't reset! it has already been reset! drag the CameraRig provided by steam VR into your hierarchy and click the button above to get started"); } } }