Beispiel #1
0
    void FixedUpdate()
    {
        if (!enableNavigation)
        {
            return;
        }

        //Save wand model
        savedWandModel = canoe.wandModel;

        //If we are using the trigger button to navigate check if it is pressed.
        if (navWithTrigger)
        {
            if (CC_INPUT.GetAxis(wandToUse, WandAxis.Trigger) > 0.0f)
            {
                doNav         = true;
                endNavUpdated = false;
            }
            else
            {
                doNav = false;
            }
        }
        else
        {
            //Otherwise check the chosen wand button
            doNav         = CC_INPUT.GetButtonPress(wandToUse, navButton);
            endNavUpdated = false;
        }

        if ((resetButton == navButton) && (!navWithTrigger))
        {
            print("CCaux_OmniNavigator Warning: Chosen Navigation and Reset Navigation buttons are the same.");
        }

        //Gradually resets canoe position and rotation
        if (CC_INPUT.GetButtonPress(wandToUse, resetButton))
        {
            charCont.transform.position = Vector3.Slerp(charCont.transform.position, resetPosition, resetSpeed * Time.deltaTime);
            charCont.transform.rotation = Quaternion.Slerp(charCont.transform.rotation, resetAngle, resetSpeed * Time.deltaTime);
        }

        //Disables the cursor and re-enables the wand models ONCE
        if (!doNav && !endNavUpdated)
        {
            doneNav         = false;
            canoe.wandModel = savedWandModel;
            cursor.SetActive(false);
            canoe.UpdateWandModels();
            endNavUpdated = true;
        }

        if (doNav)
        {
            // If wand button pressed the first time then record the starting position and orientation of the wand
            if (doneNav == false)
            {
                startPosition = CC_CANOE.WandGameObject(wandToUse).transform.localPosition;

                doneNav       = true;
                startRotation = CC_CANOE.WandGameObject(wandToUse).transform.localRotation;
            }
            else
            {
                // Then at each time check the difference between new and old wand position as well as new and old wand orientation.
                // Apply that difference to the character controller to effect navigation.
                Vector3 movement = CC_CANOE.WandGameObject(wandToUse).transform.localPosition - startPosition;

                // If disable navigation in a particular axis is enabled then set movement values to zero.
                if (disableNavigationX)
                {
                    movement.x = 0;
                }
                if (disableNavigationY)
                {
                    movement.y = 0;
                }
                if (disableNavigationZ)
                {
                    movement.z = 0;
                }

                movement = gameObject.transform.localRotation * movement; // Movement must take into account current orientation of CyberCANOE

                charCont.Move(movement * Time.deltaTime * moveSpeed);

                Quaternion newRotation = CC_CANOE.WandGameObject(wandToUse).transform.localRotation;

                // Check if a rotation lock is enabled and handle it
                float      axisLockAngle;
                Quaternion rotator = new Quaternion();

                switch (lockRotation)
                {
                case rotationLock.X:
                    axisLockAngle             = newRotation.eulerAngles.x;
                    rotator.eulerAngles       = new Vector3(axisLockAngle, 0, 0);
                    startRotation.eulerAngles = new Vector3(startRotation.eulerAngles.x, 0, 0);
                    break;

                case rotationLock.Y:
                    axisLockAngle             = newRotation.eulerAngles.y;
                    rotator.eulerAngles       = new Vector3(0, axisLockAngle, 0);
                    startRotation.eulerAngles = new Vector3(0, startRotation.eulerAngles.y, 0);
                    break;

                case rotationLock.Z:
                    axisLockAngle             = newRotation.eulerAngles.z;
                    rotator.eulerAngles       = new Vector3(0, 0, axisLockAngle);
                    startRotation.eulerAngles = new Vector3(0, 0, startRotation.eulerAngles.z);
                    break;

                default:
                    rotator = newRotation;
                    break;
                }

                charCont.transform.localRotation = charCont.transform.localRotation * Quaternion.Slerp(Quaternion.identity, Quaternion.Inverse(startRotation * Quaternion.Inverse(rotator)), Time.deltaTime * rotateSpeed);

                // If there is a cursor object then orient it with the wand position.
                if (cursor)
                {
                    cursor.SetActive(true);
                    cursor.transform.position = CC_CANOE.WandGameObject(wandToUse).transform.position;
                    cursor.transform.rotation = CC_CANOE.WandGameObject(wandToUse).transform.rotation;
                    canoe.DeactivateModels();
                }
            }
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        //Get This Target
        canoeTarget = (CC_CANOE)target;
        //Disconnect the CC_CANOE prefab instance from the original prefab
        bool isPrefabOriginal = (PrefabUtility.GetPrefabParent(target) == null) && (PrefabUtility.GetPrefabObject(target) != null);

        if (!isPrefabOriginal)
        {
            PrefabUtility.DisconnectPrefabInstance(target);
        }

        EditorGUI.BeginChangeCheck();

        //TRACKING STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Tracking Settings", EditorStyles.boldLabel);
        bool vive      = EditorGUILayout.Toggle(new GUIContent("Vive Tracking", "Use the HTC Vive tracking system."), canoeTarget.vive);
        bool optitrack = EditorGUILayout.Toggle(new GUIContent("OptiTrack Tracking", "Use the OptiTrack tracking system."), canoeTarget.optitrack);

        //TRACKING ENDS

        //CAMERA STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Camera Settings", EditorStyles.boldLabel);
        selCamera       = (CC_CAMERA.SelectedCamera)EditorGUILayout.EnumPopup(new GUIContent("Selected Camera", "Select which camera to use. Keyboard Shortcut: 'P'"), GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().selectCamera);
        enableStereo    = EditorGUILayout.Toggle(new GUIContent("Enable Stereo", "Enable/Disable stereoscopic. Keyboard Shortcut: '9'"), GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().enableStereo);
        interaxial      = EditorGUILayout.IntField(new GUIContent("Interaxial", "Interaxial distance in millimeters.Keyboard Shortcut: '-' and '+'"), GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().interaxial);
        destCameraIndex = (int)EditorGUILayout.Slider(new GUIContent("Destiny Camera Index", "Change the view to different cameras of Destiny. Keyboard Shortcut: '[' and ']'"), GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().destinyCameraIndex, 0, 7);
        float cameraForwartTilt = EditorGUILayout.Slider(new GUIContent("Camera Forward Tilt", "Change the foward tilt of the camera."), canoeTarget.cameraForwardTilt, -90f, 90f);

        //CAMERA ENDS

        //WANDS STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Wand Settings", EditorStyles.boldLabel);
        Wand simulatorActiveWand = (Wand)EditorGUILayout.EnumPopup(new GUIContent("Selected Wand", "The currently active simulator wand."), canoeTarget.simulatorActiveWand);

        CC_CANOE.WandModel wandModel = (CC_CANOE.WandModel)EditorGUILayout.EnumPopup(new GUIContent("Wand Model", "The wand model you wish to be visible. Keyboard Shortcut: '5'"), canoeTarget.wandModel);
        if (canoeTarget.isVive())
        {
            dpadType         = (DpadType)EditorGUILayout.EnumPopup(new GUIContent("Dpad Type", "The Dpad configuration (4 directions or 8 directions) you wish to use."), canoeTarget.dpadType);
            centerClickRange = EditorGUILayout.Slider(new GUIContent("Center Click Range", "Change the range of the Dpad center click."), canoeTarget.centerClickRange, 0.1f, 0.9f);
        }
        //WAND ENDS

        //SIM NAV STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Simulator Navigation Settings", EditorStyles.boldLabel);
        float navigationSpeed         = EditorGUILayout.FloatField(new GUIContent("Movement Speed", "Navigation speed of the simulator controls. (Only affects WASD key movement)"), canoeTarget.navigationSpeed);
        float navigationRotationSpeed = EditorGUILayout.FloatField(new GUIContent("Rotational Speed", "Rotational speed of the simulator controls. (Only affects WASD key movement)"), canoeTarget.navigationRotationSpeed);

        //SIM NAV ENDS

        //MISC STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Misc Settings", EditorStyles.boldLabel);
        CC_CANOE.ShowScreen showScreen = (CC_CANOE.ShowScreen)EditorGUILayout.EnumPopup(new GUIContent("Show Screen", "Enable/Disable the visibility of the CyberCANOE's Screens. Typically you want this set to none unless you are debugging in the editor. Keyboard Shortcut: '6'"), canoeTarget.showScreen);
        bool applyGravity = EditorGUILayout.Toggle(new GUIContent("Apply Gravity", "Enable or disable gravity the Canoe/Player experiences. Does not affect other objects in the scene."), canoeTarget.applyGravity);
        bool kbcont       = EditorGUILayout.Toggle(new GUIContent("Keyboard Controls", "Enable or disable the keyboard controls. This affects the simualtor, camera, and canoe controls."), canoeTarget.kbcont);

        //MISC ENDS

        EditorGUI.EndChangeCheck();

        GUILayout.Space(20);
        GUIStyle style = new GUIStyle(GUI.skin.button);

        style.fontSize  = 12;
        style.fontStyle = FontStyle.Bold;

        if (GUI.changed)
        {
            try {
                Undo.RecordObject(canoeTarget, "Updated Canoe Settings");
                //TRACKING STARTS
                if (vive && !canoeTarget.vive)
                {
                    canoeTarget.vive      = true;
                    canoeTarget.optitrack = false;
                }
                else if (optitrack && !canoeTarget.optitrack)
                {
                    canoeTarget.vive      = false;
                    canoeTarget.optitrack = true;
                }
                //TRACKING ENDS

                //CAMERA STARTS
                GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().selectCamera       = selCamera;
                GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().enableStereo       = enableStereo;
                GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().destinyCameraIndex = destCameraIndex;
                GameObject.Find("CC_HEAD").GetComponent <CC_CAMERA>().interaxial         = interaxial;
                canoeTarget.cameraForwardTilt = cameraForwartTilt;
                //CAMERA ENDS

                //WAND STARTS
                canoeTarget.simulatorActiveWand = simulatorActiveWand;
                canoeTarget.wandModel           = wandModel;
                canoeTarget.dpadType            = dpadType;
                canoeTarget.centerClickRange    = centerClickRange;
                //WAND ENDS

                //SIM NAV STARTS
                canoeTarget.navigationSpeed         = navigationSpeed;
                canoeTarget.navigationRotationSpeed = navigationRotationSpeed;
                //SIM NAV ENDS

                //MISC STARTS
                canoeTarget.showScreen   = showScreen;
                canoeTarget.applyGravity = applyGravity;
                canoeTarget.kbcont       = kbcont;
                //MISC ENDS
            }
            catch (System.NullReferenceException) {
                Debug.Log("CC_HEAD can't be found. CC_HEAD should be a child of CC_CANOE.");
            }
        }
    }