void Update()
    {
        //Directions obtained from CC_CANOE class. We use the Right wand and Head for orientation.
        //Where the right wand is pointed is the direction the player will move
        Vector3 forwardDir = CC_CANOE.WandGameObject(Wand.Right).transform.forward;
        Vector3 rightDir   = CC_CANOE.HeadGameObject().transform.right;

        rightDir = Vector3.Normalize(Vector3.ProjectOnPlane(rightDir, Vector3.up));
        Vector3 upDir = Vector3.up;

        //The input from the trigger axis of the left wand
        float forward = CC_INPUT.GetAxis(Wand.Right, WandAxis.Trigger);

        //Move the CharacterController attached to the CC_CANOE.
        Vector3 movement = forwardDir * forward;

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

        //The input from the X and Y axis of the right wand joystick.
        yAxisChange += CC_INPUT.GetAxis(Wand.Right, WandAxis.XAxis) * Time.deltaTime * lookSpeed;
        yAxisChange  = yAxisChange % 360.0f;
        xAxisChange += CC_INPUT.GetAxis(Wand.Right, WandAxis.YAxis) * Time.deltaTime * lookSpeed;
        xAxisChange  = Mathf.Clamp(xAxisChange, -maxPitch, maxPitch);

        //Change the direction the CharacterController is facing.
        charCont.transform.rotation = Quaternion.identity;
        charCont.transform.RotateAround(CC_CANOE.CanoeGameObject().transform.position, Vector3.up, yAxisChange);
        charCont.transform.RotateAround(CC_CANOE.CanoeGameObject().transform.position, rightDir, xAxisChange);
    }
 // Update is called once per frame
 void Update()
 {
     if (CC_INPUT.GetButtonDown(wand, WandButton.Menu))
     {
         transform.GetChild(childIndex).gameObject.SetActive(false);
         childIndex = (childIndex + 1) % transform.childCount;
         transform.GetChild(childIndex).gameObject.SetActive(true);
     }
 }
示例#3
0
    /// <summary>
    /// Updates the values for the x, y, and angle variables using the GetAxis methods.
    /// </summary>
    private void updateTrackpad()
    {
        x     = CC_INPUT.GetAxis(Wand.Left, WandAxis.XAxis) / 2;
        y     = CC_INPUT.GetAxis(Wand.Left, WandAxis.YAxis) / 2;
        angle = Mathf.Atan2(y, x);

        if (angle < 0)
        {
            angle += (2 * Mathf.PI);
        }
    }
    // Update is called once per frame
    void Update()
    {
        projectile.transform.position = new Vector3(wandTransform.position.x,
                                                    wandTransform.position.y,
                                                    wandTransform.position.z);
        permanentTrail.transform.position = projectile.transform.position;

        if (CC_INPUT.GetButtonDown(wand, WandButton.Trigger))
        {
            GameObject tempProjectile = Instantiate(projectile);
            tempProjectile.AddComponent <DestroyProjectile>();
            tempProjectile.GetComponent <Rigidbody>().isKinematic = false;
            tempProjectile.GetComponent <Rigidbody>().AddForce(CC_CANOE.WandGameObject(wand).transform.forward *projectileForce);
        }
    }
示例#5
0
    private void updateText(Wand wand, TextMesh mesh)
    {
        mesh.text = wand.ToString() + " Info\npos: " + tracker.GetWandPosition((int)wand)
                    + "\nrot: " + tracker.GetWandRotation((int)wand);

        mesh.text += "\nmenu clicked ? " + CC_INPUT.GetButtonPress(wand, WandButton.Menu);
        mesh.text += "\ngrip clicked ? " + CC_INPUT.GetButtonPress(wand, WandButton.Grip);

        mesh.text += "\nx = " + CC_INPUT.GetAxis(wand, WandAxis.XAxis).ToString("0.00")
                     + "\ny = " + CC_INPUT.GetAxis(wand, WandAxis.YAxis).ToString("0.00")
                     + "\nclicked ? " + CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick);

        mesh.text += "\ntrigger axis = " + CC_INPUT.GetAxis(wand, WandAxis.Trigger).ToString("0.00")
                     + "\ntrigger pulled ? " + CC_INPUT.GetButtonPress(wand, WandButton.Trigger);
    }
    // Update is called once per frame
    void Update()
    {
        float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis));

        if (angle < 0f)
        {
            angle += 2 * Mathf.PI;
        }

        angle = angle * (180f / Mathf.PI);

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            if ((angle >= 45f) && (angle <= 135f))
            {
                Debug.Log("Up object selected");
                chosenParticles = upParticles;
            }
            else if ((angle >= 225f) && (angle <= 315f))
            {
                Debug.Log("Down object selected");
                chosenParticles = downParticles;
            }
            else if ((angle > 135f) && (angle < 225f))
            {
                Debug.Log("Left object selected");
                chosenParticles = leftParticles;
            }
            else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f)))
            {
                Debug.Log("Right object selected");
                chosenParticles = rightParticles;
            }
            tempParticles = Instantiate(chosenParticles, wandTransform.position, wandTransform.rotation);
        }
        if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick))
        {
            tempParticles.transform.position = wandTransform.position;
        }

        if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick))
        {
            tempParticles.AddComponent <DestroyProjectile>();
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (CC_INPUT.GetButtonDown(wandToFollow, spawnButton))
     {
         fireballInstance = Instantiate(fireball, null);
     }
     if (CC_INPUT.GetButtonPress(wandToFollow, spawnButton))
     {
         fireballInstance.transform.position = new Vector3(wandTransform.position.x + positionOffset.x,
                                                           wandTransform.position.y + positionOffset.y,
                                                           wandTransform.position.z + positionOffset.z);
         Debug.Log(fireballInstance.transform.position);
     }
     if (CC_INPUT.GetButtonUp(wandToFollow, spawnButton))
     {
         fireballInstance.GetComponent <Rigidbody>().AddForce(wandTransform.forward * launchForce);
         //fireballInstance.GetComponent<DestroyFireball>().enabled = true;
     }
 }
示例#8
0
    public override void OnInspectorGUI()
    {
        //Disconnect the prefab instance from the original prefab
        bool isPrefabOriginal = (PrefabUtility.GetPrefabParent(target) == null) && (PrefabUtility.GetPrefabObject(target) != null);

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

        EditorGUI.BeginChangeCheck();

        GUILayout.Space(10);
        EditorGUILayout.LabelField("Grabber Settings", EditorStyles.boldLabel);

        bool enableGrabbing = EditorGUILayout.Toggle(new GUIContent("Enable Grabbing", "Toggles grabbing using the specified wand."), grabTarget.enableGrabbing);

        //Disable grabbing if enable grabbin is false
        EditorGUI.BeginDisabledGroup(!enableGrabbing);

        bool grabWithTrigger = EditorGUILayout.Toggle(new GUIContent("Grab With Trigger", "Toggles navigation with trigger. Overrides Grab Button."), grabTarget.grabWithTrigger);

        //Disable grab button if grab with trigger is true
        EditorGUI.BeginDisabledGroup(grabWithTrigger);

        WandButton validGrabButton = grabTarget.grabButton;
        WandButton grabButton      = (WandButton)EditorGUILayout.EnumPopup(new GUIContent("Grab Button", "Select button to be used to grab."), grabTarget.grabButton);

        //End grab button disabled group
        EditorGUI.EndDisabledGroup();

        //End grabber disabled group
        EditorGUI.EndDisabledGroup();

        GUILayout.Space(20);

        EditorGUI.EndChangeCheck();

        Undo.RecordObject(grabTarget, "Updated Grabber Settings");
        canoe = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>();

        //GRABBER STARTS
        grabTarget.enableGrabbing  = enableGrabbing;
        grabTarget.grabWithTrigger = grabWithTrigger;

        string location = "CCaux_Grabber on " + grabTarget.gameObject.name + "/\"Grabber Settings\"/\"Grab Button\"";

        //Button logic to keep user from selecting incorrect input for grab button
        if (canoe.isVive() && !CC_INPUT.IsViveInput(grabButton))
        {
            if (!CC_INPUT.IsEnumSeparator(grabButton))
            {
                if (!CC_INPUT.IsViveInput(validGrabButton))
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not Vive input. Defaulting to \"Menu\" button.");
                    grabButton = grabTarget.grabButton = WandButton.Menu;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not Vive input.");
                    grabButton = grabTarget.grabButton = validGrabButton;
                }
            }
            throw new ExitGUIException();
        }
        else if (canoe.isOptiTrack() && !CC_INPUT.IsOptiTrackInput(grabButton))
        {
            if (!CC_INPUT.IsEnumSeparator(grabButton))
            {
                if (!CC_INPUT.IsOptiTrackInput(validGrabButton))
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not OptiTrack input. Defaulting to \"X\" button.");
                    grabButton = grabTarget.grabButton = WandButton.X;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not OptiTrack input.");
                    grabButton = grabTarget.grabButton = validGrabButton;
                }
            }
            throw new ExitGUIException();
        }
        else
        {
            grabTarget.grabButton = grabButton;
        }
        //Button logic end

        //GRABBER ENDS
    }
示例#9
0
    void LateUpdate()
    {
        if (drawWithLeft)
        {
            //Draw line for left wand.
            if (CC_INPUT.GetButtonPress(Wand.Left, WandButton.Down))
            {
                //If lineCount is zero then we are starting a new line.
                if (lineCount1 == 0)
                {
                    newLine1 = Instantiate(line1, CC_CANOE.WandTransform(Wand.Left).position, CC_CANOE.WandTransform(Wand.Right).rotation);
                }

                lineCount1++;
                newLine1.positionCount = lineCount1;
                newLine1.SetPosition(lineCount1 - 1, CC_CANOE.WandTransform(Wand.Left).position);
            }
            else
            {
                lineCount1 = 0;
            }
            //Color pick for left wand.
            if (CC_INPUT.GetButtonPress(Wand.Left, WandButton.Up))
            {
                getColor(Wand.Left);
            }
            else
            {
                //Erase the line pointer.
                linePointer1.positionCount = 0;
            }
        }

        if (drawWithRight)
        {
            //Draw line for right wand.
            if (CC_INPUT.GetButtonPress(Wand.Right, WandButton.Down))
            {
                //If lineCount is zero then we are starting a new line.
                if (lineCount2 == 0)
                {
                    newLine2 = Instantiate(line2, CC_CANOE.WandTransform(Wand.Right).position, CC_CANOE.WandTransform(Wand.Right).rotation);
                }

                lineCount2++;
                newLine2.positionCount = lineCount2;
                newLine2.SetPosition(lineCount2 - 1, CC_CANOE.WandTransform(Wand.Right).position);
            }
            else
            {
                lineCount2 = 0;
            }
            //Color pick for right wand.
            if (CC_INPUT.GetButtonPress(Wand.Right, WandButton.Up))
            {
                getColor(Wand.Right);
            }
            else
            {
                //Erase the line pointer.
                linePointer2.positionCount = 0;
            }
        }
    }
示例#10
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();
                }
            }
        }
    }
    void Update()
    {
        //Set grab setting
        grab = false;
        if (enableGrabbing)
        {
            if (grabWithTrigger)
            {
                if (CC_INPUT.GetAxis(wand, WandAxis.Trigger) > 0.0f)
                {
                    grab = true;
                }
                else
                {
                    grab = false;
                }
            }
            else
            {
                grab = CC_INPUT.GetButtonPress(wand, grabButton);
            }
        }

        if (grab)
        {
            if (grabbedObject == null)
            {
                if (currentObject != null)
                {
                    grabbedObject = currentObject;
                    // If object had a rigidbody, grabbed save the rigidbody's kinematic state
                    // so it can be restored on release of the object
                    Rigidbody body = null;
                    body = grabbedObject.GetComponent <Rigidbody>();
                    if (body != null)
                    {
                        wasKinematic     = body.isKinematic;
                        body.isKinematic = true;
                    }

                    // Save away to original parentage of the grabbed object
                    grabbedObjectParent = grabbedObject.transform.parent;

                    // Make the grabbed object a child of the wand
                    grabbedObject.transform.parent = CC_CANOE.WandGameObject(wand).transform;
                    currentObject = null;

                    // Disable collision between yourself and the grabbed object so that the grabbed object
                    // does not apply its physics to you and push you off the world
                    Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), true);
                }
            }
        }
        else
        {
            if (grabbedObject != null)
            {
                // Restore the original parentage of the grabbed object
                grabbedObject.transform.parent = grabbedObjectParent;

                // If object had a rigidbody, restore its kinematic state
                Rigidbody body = null;
                body = grabbedObject.GetComponent <Rigidbody>();
                if (body != null)
                {
                    body.isKinematic = wasKinematic;
                }

                //Re-enstate collision between self and object
                Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), false);

                grabbedObject = null;
                currentObject = null;
            }
        }
    }
    public override void OnInspectorGUI()
    {
        //Get This Target
        navTarget = (CCaux_OmniNavigator)target;
        canoe     = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>();
        //Disconnect the prefab instance from the original prefab
        bool isPrefabOriginal = (PrefabUtility.GetPrefabParent(target) == null) && (PrefabUtility.GetPrefabObject(target) != null);

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

        EditorGUI.BeginChangeCheck();

        //NAVIGATION STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Navigation Settings", EditorStyles.boldLabel);
        bool enableNavigation = EditorGUILayout.Toggle(new GUIContent("Enable Navigation", "Toggle navigation using navigation input (default is trigger)."), navTarget.enableNavigation);

        //Disable navigation if enable navigation is false
        EditorGUI.BeginDisabledGroup(!enableNavigation);

        bool disableNavigationX = EditorGUILayout.Toggle(new GUIContent("Disable X-Axis Movement", "Toggle movement in the X-axis while navigating."), navTarget.disableNavigationX);
        bool disableNavigationY = EditorGUILayout.Toggle(new GUIContent("Disable Y-Axis Movement", "Toggle movement in the Y-axis while navigating."), navTarget.disableNavigationY);
        bool disableNavigationZ = EditorGUILayout.Toggle(new GUIContent("Disable Z-Axis Movement", "Toggle movement in the Z-axis while navigating."), navTarget.disableNavigationZ);

        CCaux_OmniNavigator.rotationLock lockRotation = (CCaux_OmniNavigator.rotationLock)EditorGUILayout.EnumPopup(new GUIContent("Lock Rotation Around Axis", "Select an axis to lock rotation around."), navTarget.lockRotation);
        Wand wandToUse      = (Wand)EditorGUILayout.EnumPopup(new GUIContent("Navigation Wand", "Select wand to use for navigation."), navTarget.wandToUse);
        bool navWithTrigger = EditorGUILayout.Toggle(new GUIContent("Navigate with Trigger", "Toggles navigation with trigger. Overrides Navigation Button."), navTarget.navWithTrigger);

        //Disable navigation button selection if trigger is used for navigation
        EditorGUI.BeginDisabledGroup(navWithTrigger);
        WandButton validNavButton = navTarget.navButton;
        WandButton navButton      = (WandButton)EditorGUILayout.EnumPopup(new GUIContent("Navigation Button", "Select button to use for navigation."), navTarget.navButton);

        //End navigation button disabled group
        EditorGUI.EndDisabledGroup();

        float moveSpeed   = EditorGUILayout.FloatField(new GUIContent("Movement Speed", "Set navigation movement speed."), navTarget.moveSpeed);
        float rotateSpeed = EditorGUILayout.FloatField(new GUIContent("Rotation Speed", "Set navigation rotation speed."), navTarget.rotateSpeed);

        //NAVIGATION ENDS

        //RESET STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Reset Settings", EditorStyles.boldLabel);
        WandButton validResetButton = navTarget.resetButton;
        WandButton resetButton      = (WandButton)EditorGUILayout.EnumPopup(new GUIContent("Reset Button", "Select button to reset CANOE position."), navTarget.resetButton);
        float      resetSpeed       = EditorGUILayout.FloatField(new GUIContent("Reset Speed", "Set the CANOE's speed when returning to its reset position."), navTarget.resetSpeed);
        Vector3    resetPosition    = EditorGUILayout.Vector3Field(new GUIContent("Reset Position", "Set the CANOE's reset position."), navTarget.resetPosition);
        Vector3    resetRotation    = EditorGUILayout.Vector3Field(new GUIContent("Reset Rotation", "Set the CANOE's reset rotation."), navTarget.resetRotation);

        //RESET ENDS

        //MISC STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Misc Settings", EditorStyles.boldLabel);
        GameObject cursor = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Cursor Object", "Set object to display while navigating."), navTarget.cursor, typeof(Object), true);

        //MISC ENDS

        //End navigation disabled group
        EditorGUI.EndDisabledGroup();

        GUILayout.Space(20);

        EditorGUI.EndChangeCheck();

        Undo.RecordObject(navTarget, "Updated Navigator Settings");
        canoe = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>();

        //NAVIGATION STARTS
        navTarget.enableNavigation   = enableNavigation;
        navTarget.disableNavigationX = disableNavigationX;
        navTarget.disableNavigationY = disableNavigationY;
        navTarget.disableNavigationZ = disableNavigationZ;

        navTarget.lockRotation   = lockRotation;
        navTarget.wandToUse      = wandToUse;
        navTarget.navWithTrigger = navWithTrigger;

        string location = "CCaux_OmniNavigator/\"Navigation Settings\"/\"Navigation Button\"";

        //Button logic to keep user from selecting incorrect input for navigation button
        if (canoe.isVive() && !CC_INPUT.IsViveInput(navButton))
        {
            if (!CC_INPUT.IsEnumSeparator(navButton))
            {
                if (!CC_INPUT.IsViveInput(validNavButton))
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not Vive input. Defaulting to \"Menu\" button.");
                    navButton = navTarget.navButton = WandButton.Menu;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not Vive input.");
                    navButton = navTarget.navButton = validNavButton;
                }
            }
            throw new ExitGUIException();
        }
        else if (canoe.isOptiTrack() && !CC_INPUT.IsOptiTrackInput(navButton))
        {
            if (!CC_INPUT.IsEnumSeparator(navButton))
            {
                if (!CC_INPUT.IsOptiTrackInput(validNavButton))
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not OptiTrack input. Defaulting to \"X\" button.");
                    navButton = navTarget.navButton = WandButton.X;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not OptiTrack input.");
                    navButton = navTarget.navButton = validNavButton;
                }
            }
            throw new ExitGUIException();
        }
        else
        {
            navTarget.navButton = navButton;
        }
        //Button logic end

        navTarget.moveSpeed   = moveSpeed;
        navTarget.rotateSpeed = rotateSpeed;
        //NAVIGATION ENDS

        //RESET STARTS
        location = "CCaux_OmniNavigator/\"Reset Settings\"/\"Reset Button\"";

        //Button logic to keep user from selecting incorrect input for reset button
        if (canoe.isVive() && !CC_INPUT.IsViveInput(resetButton))
        {
            if (!CC_INPUT.IsEnumSeparator(resetButton))
            {
                if (!CC_INPUT.IsViveInput(validResetButton))
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not Vive input. Defaulting to \"Menu\" button.");
                    resetButton = navTarget.resetButton = WandButton.Menu;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not Vive input.");
                    resetButton = navTarget.resetButton = validResetButton;
                }
            }
            throw new ExitGUIException();
        }
        else if (canoe.isOptiTrack() && !CC_INPUT.IsOptiTrackInput(resetButton))
        {
            if (!CC_INPUT.IsEnumSeparator(resetButton))
            {
                if (!CC_INPUT.IsOptiTrackInput(validResetButton))
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not OptiTrack input. Defaulting to \"X\" button.");
                    resetButton = navTarget.resetButton = WandButton.X;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not OptiTrack input.");
                    resetButton = navTarget.resetButton = validResetButton;
                }
            }
            throw new ExitGUIException();
        }
        else
        {
            navTarget.resetButton = resetButton;
        }
        //Button logic end

        navTarget.resetSpeed    = resetSpeed;
        navTarget.resetPosition = resetPosition;
        navTarget.resetRotation = resetRotation;
        //RESET ENDS

        //MISC STARTS
        navTarget.cursor = cursor;
        //MISC ENDS
    }
示例#13
0
    // Update is called once per frame
    void Update()
    {
        //Default color
        Color color = Color.white;

        updateModel();
        updateTrackpad();

        //On the first frame of the click, instantiate a projectile at the position of the trackpad click
        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.TrackpadClick))
        {
            Debug.Log("trackpad just clicked");
            //Color is calculated using the angle of the click
            color            = new Color(Mathf.Cos(angle), Mathf.Cos(angle + (3 * Mathf.PI / 4)), Mathf.Cos(angle - (3 * Mathf.PI / 4)));
            controlledObject = Instantiate(projectile, new Vector3(x, y + transform.position.y, transform.position.z), Quaternion.identity);
            controlledObject.GetComponent <Renderer>().material.color = color;
            controlledObject.name = "obj_" + projectileIncrement;
            projectileIncrement   = (projectileIncrement + 1) % projectileLimit;
            //When the trackpad is held, the projectile follows the position of the trackpad click and its color is updated
            //to match the new angle
        }
        else if (CC_INPUT.GetButtonPress(Wand.Left, WandButton.TrackpadClick) && (controlledObject != null))
        {
            Debug.Log("trackpad being held");
            controlledObject.transform.position = new Vector3(x, y + transform.position.y, transform.position.z);
            color = new Color(Mathf.Cos(angle), Mathf.Cos(angle + (3 * Mathf.PI / 4)), Mathf.Cos(angle - (3 * Mathf.PI / 4)));
            controlledObject.GetComponent <Renderer>().material.color = color;
            //When the trackpad is released, the force is added to the projectile at the angle it was released at
        }
        else if (CC_INPUT.GetButtonUp(Wand.Left, WandButton.TrackpadClick))
        {
            Debug.Log("trackpad just released");
            //A random z-axis force is applied to the projectile
            float force = (float)forceEnum * forceFactor + forceFactor;
            zForce = CC_CANOE.RandomRange(0f, 1f) * force;
            if (CC_CANOE.RandomRange(0, 1) == 0)
            {
                zForce = -zForce;
            }
            //Force is added to the projectile
            if (controlledObject != null)
            {
                controlledObject.GetComponent <Rigidbody>().AddForce(new Vector3(Mathf.Cos(angle) * force, Mathf.Sin(angle) * force, zForce));
            }
            //If an object of the same name exists, destroy it. This enforces the number of projectiles allowed at once.
            if (GameObject.Find("obj_" + projectileIncrement) != null)
            {
                Destroy(GameObject.Find("obj_" + projectileIncrement));
            }
        }

        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.Trigger))
        {
            forceEnum = (Force)(((int)(forceEnum) + 1) % System.Enum.GetValues(typeof(Force)).Length);
        }

        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.Grip))
        {
            modelEnum = (Model)(((int)(modelEnum) + 1) % System.Enum.GetValues(typeof(Model)).Length);
            switch (modelEnum)
            {
            case Model.Orb:
                projectile = orbObject;
                break;

            case Model.Cube:
                projectile = cubeObject;
                break;

            default:
                break;
            }
        }

        //Press the left Menu button to delete all existing projectiles
        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.Menu))
        {
            for (int i = 0; i < projectileLimit; i++)
            {
                if (GameObject.Find("obj_" + i) != null)
                {
                    Destroy(GameObject.Find("obj_" + i));
                    audioSource.Play();
                }
            }
        }

        toggleInfo.text = "Newly spawned projectiles"
                          + "\nwill be " + modelEnum + "s with " + forceEnum + " force";
    }
    // Update is called once per frame
    void Update()
    {
        Transform wandTransform = CC_CANOE.WandTransform(wand);
        Vector3   offset        = new Vector3(wandTransform.position.x,
                                              wandTransform.position.y + verticalOffset,
                                              wandTransform.position.z);

        float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis));

        if (angle < 0f)
        {
            angle += 2 * Mathf.PI;
        }

        angle = angle * (180f / Mathf.PI);

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            if ((angle >= 45f) && (angle <= 135f))
            {
                Debug.Log("Up object selected");
                lanternObj   = upObject;
                chosenButton = WandButton.Up;
            }
            else if ((angle >= 225f) && (angle <= 315f))
            {
                Debug.Log("Down object selected");
                lanternObj   = downObject;
                chosenButton = WandButton.Down;
            }
            else if ((angle > 135f) && (angle < 225f))
            {
                Debug.Log("Left object selected");
                lanternObj   = leftObject;
                chosenButton = WandButton.Left;
            }
            else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f)))
            {
                Debug.Log("Right object selected");
                lanternObj   = rightObject;
                chosenButton = WandButton.Right;
            }
        }

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            lanternObj.transform.localScale = Vector3.zero;
            Vector3    rotation = lanternObj.transform.eulerAngles;
            Quaternion quat     = Quaternion.identity;
            lantern = Instantiate(lanternObj, offset, quat);
            lantern.gameObject.SetActive(true);
            lantern.transform.position = offset;
        }
        else if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick))
        {
            lantern.transform.position = offset;
        }
        else if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick))
        {
            lantern.GetComponent <Rigidbody>().isKinematic = false;
            lantern.GetComponent <Rigidbody>().AddForce(new Vector3(0, releaseForce, 0));
            lantern.GetComponent <Lantern>().startExpiring = true;
        }
    }