コード例 #1
0
 private void AddMovementComponents(VRLocomotionRig a_vrLR)
 {
     a_vrLR.s_head.gameObject.AddComponent <SteamVR_UpdatePoses>();
     m_headBob  = a_vrLR.s_head.gameObject.AddComponent <HeadBob>();  // Adds the HeadBob movement logic component
     m_armSwing = a_vrLR.s_head.gameObject.AddComponent <ArmSwing>(); // Adds the ArmSwing movement logic component
     m_pulley   = a_vrLR.s_head.gameObject.AddComponent <Pulley>();   // Adds the Pulley movement logic component
     m_tPad     = a_vrLR.s_head.gameObject.AddComponent <Touchpad>();
     // DEVELOPER: ADD YOUR OWN CUSTOM VR MOVEMENT COMPONENT HERE!
 }
コード例 #2
0
        // DEVELOPER: add a string for your zone tag name! dont forget to create the tag in unity and apply it
        //private const string DevCollisionTag      = "DeveloperZone";

        #endregion

        #region Unity Methods

        void Awake()
        {
            m_locoRig = GetComponent <VRLocomotionRig>();

            source = GetComponent <AudioSource>();

            try {
                m_hbMovement = m_locoRig.s_head.GetComponent <HeadBob>();
                m_asMovement = m_locoRig.s_head.GetComponent <ArmSwing>();
                m_pMovement  = m_locoRig.s_head.GetComponent <Pulley>();
            } catch {
                Debug.LogError("there are no movement components attached to your VR rig! please ensure you did the setup correctly!");
            }
            AutoDetectCurrentMovement();
        }
コード例 #3
0
        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");
                }
            }
        }