Beispiel #1
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;
     }
 }
Beispiel #4
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;
            }
        }
    }
Beispiel #5
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;
            }
        }
    }
Beispiel #7
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;
        }
    }