Exemple #1
0
    private void MenuClicked(object sender, ClickedEventArgs e)
    {
        if (AreBothMenuButtonPressed())
        {
            foreach (Transform child in lineA.transform)
            {
                GameObject.Destroy(child.gameObject);
            }
            foreach (Transform child in lineB.transform)
            {
                GameObject.Destroy(child.gameObject);
            }
            GameObject wLine = GameObject.FindGameObjectWithTag("TicTacToeWinnerLine");
            if (wLine)
            {
                GameObject.Destroy(wLine);
            }
            GameObject ticTacToeGrid = GameObject.FindGameObjectWithTag("TicTacToe");
            if (ticTacToeGrid)
            {
                TicTacToeCtrl   controller = ticTacToeGrid.GetComponent <TicTacToeCtrl>();
                TicTacToeCell[] cells      = controller.cells;
                foreach (TicTacToeCell cell in cells)
                {
                    cell.CellValue = 0;
                }
                controller.gameOver = false;
            }
            playerAController.GetComponent <AllowToDraw>().HideArrow();
            playerBController.GetComponent <AllowToDraw>().HideArrow();

            playerAController.GetComponent <AllowToDraw>().PlayerTurn = true;
            playerBController.GetComponent <AllowToDraw>().PlayerTurn = true;
        }
    }
    private IEnumerator HitHaptic()
    {
        for (int i = 0; i < 10; i++)
        {
            SteamVR_Controller.Input((int)controller.GetComponent <SteamVR_TrackedObject>().index).TriggerHapticPulse(1000);

            yield return(new WaitForSeconds(0.01f));
        }
    }
        /**
         * Called when the Object Placement button is hit.
         * Changes the tool on the controller to CreateObjectTool.
         */
        public void OnClickObjectPlacement()
        {
            controller.GetComponent <VRListener>().ChangeTool(typeof(CreateObjectTool));

            var objPlaceColors = objPlaceButton.colors;

            objPlaceColors.normalColor = pressedColor;
            objPlaceButton.colors      = objPlaceColors;

            var objEditColors = objEditButton.colors;

            objEditColors.normalColor = normalColor;
            objEditButton.colors      = objEditColors;
        }
Exemple #4
0
    void SetLaserPointerState(bool state)
    {
        ViveUILaserPointer leftPointer = left.GetComponent <ViveUILaserPointer>();

        leftPointer.SetVisibility(state);
        ViveUILaserPointer rightPointer = right.GetComponent <ViveUILaserPointer>();

        rightPointer.SetVisibility(state);
    }
    void release()
    {
        if (joint.connectedBody == null)
        {
            return;
        }

        Rigidbody rigidBody = joint.connectedBody;

        joint.connectedBody = null;

        var device = SteamVR_Controller.Input((int)trackedController.GetComponent <SteamVR_TrackedObject> ().index);

        rigidBody.velocity        = device.velocity;
        rigidBody.angularVelocity = device.angularVelocity;

        rigidBody.maxAngularVelocity = rigidBody.angularVelocity.magnitude;
    }
Exemple #6
0
    public void SwipeValue(Rigidbody target_rigid)
    {
        float f_velocity_angular         = 0.1f;
        SteamVR_TrackedObject trackedObj = _targethand.GetComponent <SteamVR_TrackedObject>();

        SteamVR_Controller.Device device_left = SteamVR_Controller.Input((int)trackedObj.index);
        var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;

        if (origin != null)
        {
            target_rigid.velocity        = origin.TransformVector(device_left.velocity);
            target_rigid.angularVelocity = origin.TransformVector(device_left.angularVelocity) * f_velocity_angular;
        }
        else
        {
            target_rigid.velocity        = device_left.velocity;
            target_rigid.angularVelocity = device_left.angularVelocity * f_velocity_angular;
        }
        target_rigid.maxAngularVelocity = target_rigid.angularVelocity.magnitude * f_velocity_angular;
    }
Exemple #7
0
    void Start()
    {
        m_controllerLeft  = transform.FindChild("Controller (left)").GetComponent <SteamVR_TrackedController>();
        m_controllerRight = transform.FindChild("Controller (right)").GetComponent <SteamVR_TrackedController>();

        m_teleporter = GetComponentInChildren <TeleportVive>();
        m_teleporter.SetActiveController(m_controllerLeft.GetComponent <SteamVR_TrackedObject>());

        m_controllerLeft.PadClicked   += onPadClickedLeft;          // TP init
        m_controllerLeft.PadUnclicked += onPadUnClickedLeft;        // TP launch

        m_controllerRight.PadClicked += onPadClickedRight;          // Take in inventory

        m_controllerRight.Gripped   += onGrabRight;                 // Take obj
        m_controllerRight.Ungripped += onUnGrabRight;               // Drop obj

        m_controllerLeft.TriggerClicked  += onTriggerClicked;       // interract
        m_controllerRight.TriggerClicked += onTriggerClicked;

        m_controllerLeft.MenuButtonClicked += onMenuClickLeft;      // Main menu
    }
Exemple #8
0
        // Update is called once per frame
        void Update()
        {
            if (selector_type != curr_selector_type)
            {
                {
                    Selector selector = left_controller.GetComponent <Selector>();
                    if (selector)
                    {
                        Destroy(selector);
                    }
                }
                {
                    Selector selector = right_controller.GetComponent <Selector>();
                    if (selector)
                    {
                        Destroy(selector);
                    }
                }
                {
                    Selector selector = head.GetComponent <Selector>();
                    if (selector)
                    {
                        Destroy(selector);
                    }
                }

                switch (selector_type)
                {
                case SelectorType.Direct:
                    left_controller.gameObject.AddComponent <DirectSelector>();
                    right_controller.gameObject.AddComponent <DirectSelector>();
                    break;

                case SelectorType.HandRay:
                    left_controller.gameObject.AddComponent <HandRaySelector>();
                    right_controller.gameObject.AddComponent <HandRaySelector>();
                    break;

                case SelectorType.EyeHandRay:
                    EyeHandRaySelector lselector = left_controller.gameObject.AddComponent <EyeHandRaySelector>();
                    EyeHandRaySelector rselector = right_controller.gameObject.AddComponent <EyeHandRaySelector>();
                    lselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                    rselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                    break;

                case SelectorType.HeadRay:
                    head.gameObject.AddComponent <HeadRaySelector>();
                    break;
                }

                curr_selector_type = selector_type;
            }

            if (curr_dominant_eye != dominant_eye && curr_selector_type == SelectorType.EyeHandRay)
            {
                EyeHandRaySelector lselector = left_controller.gameObject.GetComponent <EyeHandRaySelector>();
                EyeHandRaySelector rselector = right_controller.gameObject.GetComponent <EyeHandRaySelector>();
                if (lselector != null)
                {
                    lselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                }
                if (rselector != null)
                {
                    rselector.isRightEyeDominant = (dominant_eye == DominantEyeType.Righteye);
                }

                curr_dominant_eye = dominant_eye;
            }
        }
Exemple #9
0
    // Initialise.
    private void Start()
    {
        // Hide all menus except the default one.
        this.Menus  = this.gameObject.GetComponentsInChildren <Canvas>(includeInactive: true).ToList();
        currentMenu = this.Menus.SingleOrDefault(x => x == this.DefaultMenu);

        if (currentMenu == null) // Just use the first available canvas, preferably a visible one.
        {
            this.currentMenu = this.Menus.Where(x => x.gameObject.activeSelf).Count() > 0 ? this.Menus.First(x => x.gameObject.activeSelf) : this.Menus.FirstOrDefault();
        }

        // Set visible only the default menu.
        this.Menus.ForEach(x => { x.gameObject.SetActive(false); });
        this.SetCurrentMenu(currentMenu);

        // Initialise boxcollider on each menu, used to detect that the controller is pointed at a menu.
        if (!IgnoreLaser)
        {
            this.Menus.ForEach(menu =>
            {
                // Add collider the size of the menu canvas.
                var collider      = menu.gameObject.AddComponent <BoxCollider>();
                var menuTransform = menu.gameObject.transform;
                var menuRect      = menu.GetComponent <RectTransform>();
                collider.size     = new Vector3(menuRect.sizeDelta.x, menuRect.sizeDelta.y, .1f);

                // Add Menu tag (required for laser to distinguish menus.)
                menu.tag = "Menu";
            });
        }
        else
        {
            this.gameObject.AddComponent <UIIgnoreRaycast>(); // Tells the LaserInputModule to ignore UI elements on this menu.
        }

        // Get controller
        if (Controller == null)
        {
            this.Controller = GetComponentInParent <SteamVR_TrackedController>(); // Attempt to find a controller in parent objects.
        }
        if (Controller != null)                                                   // We have a controller, we can set up the events for it.
        {
            ViveMenuEvents.Active = true;
            var controllerEventSystem = Controller.GetComponent <ControllerEventSystem>();
            if (controllerEventSystem == null)
            {
                controllerEventSystem = Controller.gameObject.AddComponent <ControllerEventSystem>();
            }
            controllerEventSystem.AddViveMenuEvents(ViveMenuEvents);

            // Add controller events that we want to apply to all menus. (only works while the menu is active).
            ViveMenuEvents.MenuButtonClicked.AddListener(() =>
            {
                this.Show(!gameObject.activeSelf);
            });
        }

        if (this.ControlMode == ViveMenuControlMode.Laser)
        {
        }
        else // Controller mode.
        {
            if (Controller == null)
            {
                Debug.Log("Warning: No controller specified for a menu in controller mode.");
            }
            else
            {
                // Add listeners specifically relevant to controlling the menu with the controller.

                ViveMenuEvents.TriggerClicked.AddListener(() =>
                {
                    if (_currentSelectable is Dropdown)
                    {
                        if (_ddCurrent == null) // No dropdown selected.
                        {
                            this._ddCurrent = ((Dropdown)_currentSelectable);
                            _ddCurrent.Show();
                        }
                    }
                    else
                    {
                        _currentSelectable.ViveSelectableInvoke();
                    }
                    var test = _currentSelectable;
                });



                ViveMenuEvents.PadClickUp.AddListener(() =>
                {
                    SelectNextSelectable(Direction.Up);
                });

                ViveMenuEvents.PadClickDown.AddListener(() =>
                {
                    SelectNextSelectable(Direction.Down);
                });

                ViveMenuEvents.PadClickRight.AddListener(() =>
                {
                    if (_currentSelectable is Slider)
                    {
                        var currentvalue    = ((Slider)_currentSelectable).value;
                        var minvalue        = ((Slider)_currentSelectable).minValue;
                        var maxvalue        = ((Slider)_currentSelectable).maxValue;
                        var calculatedvalue = (maxvalue - minvalue) / 10;

                        ((Slider)_currentSelectable).value = currentvalue + calculatedvalue;
                    }
                });

                ViveMenuEvents.PadClickLeft.AddListener(() =>
                {
                    if (_currentSelectable is Slider)
                    {
                        var currentvalue    = ((Slider)_currentSelectable).value;
                        var minvalue        = ((Slider)_currentSelectable).minValue;
                        var maxvalue        = ((Slider)_currentSelectable).maxValue;
                        var calculatedvalue = (maxvalue - minvalue) / 10;

                        ((Slider)_currentSelectable).value = currentvalue - calculatedvalue;
                    }
                });
            }
        }
    }
Exemple #10
0
    // Update is called once per frame
    void Update()
    {
        // finds all of the controllers in contact with the lever that have the trigger pressed
        int     numActive     = 0;
        Vector3 controllerPos = Vector3.zero;

        foreach (Transform t in touchingControllers)
        {
            SteamVR_TrackedController controller = t.GetComponent <SteamVR_TrackedController>();
            if (controller == null)
            {
                Debug.LogWarning("No TrackedController script found!");
            }
            if (controller != null && controller.triggerPressed)
            {
                controllerPos += controller.transform.position;
                numActive++;
            }
        }
        //Debug.Log("Controller Count: " + touchingControllers.Count);

        if (numActive > 0 && AcceptingInput)
        {
            controllerPos /= numActive; // gets average position of touching controllers with pulled trigger
            Vector3 centralAnchor    = (ForwardAnchor.position + RearAnchor.position) / 2;
            Vector3 forwardDirection = (ForwardAnchor.position - RearAnchor.position).normalized;

            //calculates where the controller should be moved to (nearest point to average controller position on line between forward and rear anchors)
            float nextOffset = Mathf.Clamp(Vector3.Dot(controllerPos - centralAnchor, forwardDirection) / maxOffsetDistance, MIN_OFFSET, MAX_OFFSET);

            // vibrates controller if you pass a vibration point on the lever
            bool vibrateController = false;
            if (nextOffset > STOP_MAX || currentOffset > STOP_MAX)
            {
                float distInc = (MAX_OFFSET - STOP_MAX) / NUM_VIB;
                float oldInc  = Mathf.Floor((currentOffset - STOP_MAX) / distInc);
                float newInc  = Mathf.Floor((nextOffset - STOP_MAX) / distInc);
                vibrateController = (oldInc != newInc);
            }
            else if (nextOffset < STOP_MIN || currentOffset < STOP_MIN)
            {
                float distInc = (STOP_MIN - MIN_OFFSET) / NUM_VIB;
                float oldInc  = Mathf.Floor((STOP_MIN - currentOffset) / distInc);
                float newInc  = Mathf.Floor((STOP_MIN - nextOffset) / distInc);
                vibrateController = (oldInc != newInc);
            }

            //updates the lever's positon
            transform.position = Vector3.Lerp(RearAnchor.position, ForwardAnchor.position, nextOffset / 2.0f + 0.5f);
            currentOffset      = nextOffset;

            //vibrates the controller if a vibration point is passed
            if (vibrateController)
            {
                //Debug.Log("Should vibrate here");
                foreach (Transform controller in touchingControllers)
                {
                    SteamVR_Controller.Input((int)controller.GetComponent <SteamVR_TrackedController>().controllerIndex).TriggerHapticPulse(VIB_INTENSITY);
                }
            }
        }

        // updates the speed of the ship if there's a valid orbitManager
        if (orbitManager != null)
        {
            //calculates the desired speed from the lever's positon
            if (currentOffset > STOP_MAX && currentOffset <= MAX_OFFSET + FP_TOLERANCE)
            {
                orbitManager.LinearSpeed = (currentOffset - STOP_MAX) / (MAX_OFFSET - STOP_MAX) * MAX_SPEED;
            }
            else if (currentOffset < STOP_MIN && currentOffset >= MIN_OFFSET - FP_TOLERANCE)
            {
                orbitManager.LinearSpeed = (currentOffset - STOP_MIN) / (STOP_MIN - MIN_OFFSET) * MAX_SPEED;
            }
            else
            {
                orbitManager.LinearSpeed = 0.0f;

                //moves controller to exact center if you let go of it the zone considered 'stop' or '0 speed'
                if (numActive <= 0 && AcceptingInput && Mathf.Abs(currentOffset - (STOP_MAX + STOP_MIN) / 2.0f) > FP_TOLERANCE)
                {
                    SetThrottle(0.0f);
                }
            }

            //updates the speed label
            SetLabel(orbitManager.LinearSpeed);
        }
    }
Exemple #11
0
    // Update is called once per frame
    void Update()
    {
        if (doOnce)
        {
            doOnce      = false;
            WallObjects = GameObject.FindGameObjectsWithTag("PlacementObject");
        }
        if (GameStateManager.GetCurrentState() == GameStateManager.Types.Build && controller1)
        {
            Vector3 point;
            device = SteamVR_Controller.Input((int)controller1.GetComponent <SteamVR_TrackedObject>().index);
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
            {
                var Layers = 1 << 12;
                if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, Layers))
                {
                    var hit = hitInfo.collider.gameObject.GetComponentInParent <Collider>().gameObject;
                    var gx  = hit.GetComponent <Location>().x;
                    var gz  = hit.GetComponent <Location>().y;
                    var gt  = hit.GetComponent <Location>().gridType;
                    if (gt == 0)
                    {
                        LargeUsedSpace[gx, gz] = 0;
                    }
                    else if (gt == 1)
                    {
                        SmallUsedSpace[gx, gz] = 0;
                    }
                    Destroy(hit);
                    radialControllerMenu.DeleteItem(hit.gameObject);
                    recentChange = true;
                }
            }
            // Check for mouse ray collision with this object
            if (getTargetLocation(out point))
            {
                var old = prefabPlacementObject;
                prefabPlacementObject = radialControllerMenu.getSelected();
                var updated = prefabPlacementObject;
                if (old != updated && placementObject)
                {
                    placementObject.transform.position = new Vector3(0, -1, 0);
                    placementObject = null;
                }

                int x = 0;
                int z = 0;
                if (prefabPlacementObject.GetComponent <Location>().gridType == 0)
                {
                    // Transform position is the center point of this object, x and z are grid slots from 0..slots-1
                    x = (int)Math.Round(Math.Round(point.x - transform.position.x + LargeHalfSlots.x - LargeGrid / 2.0f) / LargeGrid);
                    z = (int)Math.Round(Math.Round(point.z - transform.position.z + LargeHalfSlots.z - LargeGrid / 2.0f) / LargeGrid);
                    if (x > LargeSlots.x)
                    {
                        x = (int)LargeSlots.x;
                    }
                    if (x < 0)
                    {
                        x = 0;
                    }
                    if (z > LargeSlots.z)
                    {
                        z = (int)LargeSlots.z;
                    }
                    if (z < 0)
                    {
                        z = 0;
                    }


                    // Calculate the quantized world coordinates on where to actually place the object
                    point.x = (float)(x) * LargeGrid - LargeHalfSlots.x + transform.position.x + LargeGrid / 2.0f;
                    point.z = (float)(z) * LargeGrid - LargeHalfSlots.z + transform.position.z + LargeGrid / 2.0f;
                }
                else if (prefabPlacementObject.GetComponent <Location>().gridType == 1)
                {
                    // Transform position is the center point of this object, x and z are grid slots from 0..slots-1
                    x = (int)Math.Round(Math.Round(point.x - transform.position.x + SmallHalfSlots.x - SmallGrid / 2.0f) / SmallGrid);
                    z = (int)Math.Round(Math.Round(point.z - transform.position.z + SmallHalfSlots.z - SmallGrid / 2.0f) / SmallGrid);
                    if (x > SmallSlots.x)
                    {
                        x = (int)SmallSlots.x;
                    }
                    if (x < 0)
                    {
                        x = 0;
                    }
                    if (z > SmallSlots.z)
                    {
                        z = (int)SmallSlots.z;
                    }
                    if (z < 0)
                    {
                        z = 0;
                    }


                    // Calculate the quantized world coordinates on where to actually place the object
                    point.x = (float)(x) * SmallGrid - SmallHalfSlots.x + transform.position.x + SmallGrid / 2.0f;
                    point.z = (float)(z) * SmallGrid - SmallHalfSlots.z + transform.position.z + SmallGrid / 2.0f;
                }
                // Create an object to show if this area is available for building
                // Re-instantiate only when the slot has changed or the object not instantiated at all
                if (lastPos.x != x || lastPos.z != z || areaObject == null)
                {
                    lastPos.x = x;
                    lastPos.z = z;
                    if (areaObject != null)
                    {
                        areaObject.transform.position = new Vector3(0, 0, 0);
                    }
                    try
                    {
                        var tempPoint = point;

                        if (prefabPlacementObject.GetComponent <Location>().gridType == 0)
                        {
                            tempPoint.y = tempPoint.y + 4;
                            areaObject  = LargeUsedSpace[x, z] == 0 && placementObject.GetComponent <Location>().GetCanPlace() && (prefabPlacementObject.GetComponent <Location>().NumberAllowed > radialControllerMenu.GetNumberPlacedSelectedItem() && solvable) ? prefabOK : prefabFail;
                        }
                        else if (prefabPlacementObject.GetComponent <Location>().gridType == 1)
                        {
                            tempPoint.y = tempPoint.y + 1.2f;
                            areaObject  = SmallUsedSpace[x, z] == 0 && placementObject.GetComponent <Location>().GetCanPlace() && (prefabPlacementObject.GetComponent <Location>().NumberAllowed > radialControllerMenu.GetNumberPlacedSelectedItem()) && solvable ? SmallprefabOK : SmallprefabFail;
                        }
                        areaObject.transform.position = tempPoint;
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(ex.Message);
                    }
                    if (areaObject)
                    {
                        Color color = areaObject.GetComponent <MeshRenderer>().material.color;
                        color.a = 0.3f;
                        areaObject.GetComponent <MeshRenderer>().material.color = color;
                    }
                }



                // Create or move the object
                if (!placementObject && prefabPlacementObject)
                {
                    foreach (GameObject wall in WallObjects)
                    {
                        Debug.Log("PlacementObject" + prefabPlacementObject.name);
                        Debug.Log("WallObject" + wall.name);
                        if (wall.GetComponent <Location>().type == prefabPlacementObject.GetComponent <Location>().type)
                        {
                            placementObject = wall;
                        }
                    }
                    placementObject.GetComponent <Location>().disableNavmeshObst();
                    placementObject.transform.position = point;
                }
                else if (placementObject)
                {
                    placementObject.transform.position = point;
                }


                // On left click, insert the object to the area and mark it as "used"
                if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger) && solvable)
                {
                    if (prefabPlacementObject.GetComponent <Location>().NumberAllowed >
                        radialControllerMenu.GetNumberPlacedSelectedItem())
                    {
                        // Place the object
                        if (prefabPlacementObject.GetComponent <Location>().gridType == 0)
                        {
                            if (LargeUsedSpace[x, z] == 0 && placementObject.GetComponent <Location>().GetCanPlace())
                            {
                                Debug.Log("Placement Position: " + x + ", " + z);
                                LargeUsedSpace[x, z] = 1;


                                // ToDo: place the result somewhere..
                                recentChange = true;
                                var temp = Instantiate(prefabPlacementObject, point, Quaternion.identity);
                                LastObjectPlaced = temp;
                                radialControllerMenu.PlaceItem();
                                temp.transform.rotation          = placementObject.transform.rotation;
                                temp.GetComponent <Location>().x = x;
                                temp.GetComponent <Location>().y = z;
                                temp.layer = LayerMask.NameToLayer("PlacedObjects");
                            }
                        }
                        else if (prefabPlacementObject.GetComponent <Location>().gridType == 1)
                        {
                            if (SmallUsedSpace[x, z] == 0 && placementObject.GetComponent <Location>().GetCanPlace())
                            {
                                Debug.Log("Placement Position: " + x + ", " + z);
                                SmallUsedSpace[x, z] = 1;


                                // ToDo: place the result somewhere..

                                var temp = Instantiate(prefabPlacementObject, point, Quaternion.identity);
                                radialControllerMenu.PlaceItem();
                                LastObjectPlaced                 = temp;
                                temp.transform.rotation          = placementObject.transform.rotation;
                                temp.GetComponent <Location>().x = x;
                                temp.GetComponent <Location>().y = z;
                                temp.layer   = LayerMask.NameToLayer("PlacedObjects");
                                recentChange = true;
                            }
                        }
                    }
                }
                device = SteamVR_Controller.Input((int)controller1.GetComponent <SteamVR_TrackedObject>().index);
                if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    if (device.GetAxis().x != 0)
                    {
                        if (device.GetAxis().x > 0)
                        {
                            placementObject.GetComponent <Location>().RotateRight();
                        }
                        else
                        {
                            placementObject.GetComponent <Location>().RotateLeft();
                        }
                    }
                }
            }
            else
            {
                if (placementObject)
                {
                    placementObject.transform.position = new Vector3(0, -1, 0);
                    placementObject = null;
                }
                if (areaObject)
                {
                    areaObject.transform.position = new Vector3(0, -1, 0);
                    areaObject = null;
                }
            }
        }
        else
        {
            if (placementObject)
            {
                placementObject.transform.position = new Vector3(0, -1, 0);
                placementObject = null;
            }
            if (areaObject)
            {
                areaObject.transform.position = new Vector3(0, -1, 0);
                areaObject = null;
            }
        }
    }
Exemple #12
0
    // Update is called once per frame
    void Update()
    {
        // finds all of the controllers in contact with the lever that have the trigger pressed
        int     numActive = 0;
        Vector3 direction = Vector3.zero; // note: this direction is in the lever's local space

        foreach (Transform t in touchingControllers)
        {
            SteamVR_TrackedController controller = t.GetComponent <SteamVR_TrackedController>();
            if (controller == null)
            {
                Debug.LogWarning("No TrackedController script found!");
            }
            if (controller != null && controller.triggerPressed)
            {
                Vector3 contDir = transform.parent.InverseTransformPoint(t.position) - transform.localPosition;
                contDir.x  = 0;
                direction += contDir.normalized;
                numActive++;
            }
        }
        //Debug.Log("Controller Count: " + touchingControllers.Count);

        if (numActive > 0 && AcceptingInput)
        {
            direction.Normalize();

            //calculates where the controller should be moved to
            float x_rotation = Mathf.Clamp(-Mathf.Atan2(direction.y, direction.z) * Mathf.Rad2Deg, MIN_ROTATION, MAX_ROTATION);
            //Debug.Log("X_Rotation: " + x_rotation);

            bool  vibrateController = false;
            float old_x_rotation    = (transform.localEulerAngles.x <= 180) ? transform.localEulerAngles.x : transform.localEulerAngles.x - 360;

            // vibrates controller if you pass a vibration point on the lever
            if (x_rotation > STOP_MAX || old_x_rotation > STOP_MAX)
            {
                float angleInc = (MAX_ROTATION - STOP_MAX) / NUM_VIB;
                float oldInc   = Mathf.Floor((old_x_rotation - STOP_MAX) / angleInc);
                float newInc   = Mathf.Floor((x_rotation - STOP_MAX) / angleInc);
                vibrateController = (oldInc != newInc);
            }
            else if (x_rotation < STOP_MIN || old_x_rotation < STOP_MIN)
            {
                float angleInc = (STOP_MIN - MIN_ROTATION) / NUM_VIB;
                float oldInc   = Mathf.Floor((STOP_MIN - old_x_rotation) / angleInc);
                float newInc   = Mathf.Floor((STOP_MIN - x_rotation) / angleInc);
                vibrateController = (oldInc != newInc);
            }

            //updates the lever's rotation
            transform.localEulerAngles = new Vector3(x_rotation, transform.localEulerAngles.y, transform.localEulerAngles.z);

            //vibrates the controller if a vibration point is passed
            if (vibrateController)
            {
                Debug.Log("Should vibrate here");
                foreach (Transform controller in touchingControllers)
                {
                    SteamVR_Controller.Input((int)controller.GetComponent <SteamVR_TrackedController>().controllerIndex).TriggerHapticPulse(VIB_INTENSITY);
                }
            }
        }

        // updates the speed of the ship if there's a valid orbitManager
        if (orbitManager != null)
        {
            float x_rot = transform.localEulerAngles.x;

            //calculates the desired speed from the lever's rotation
            if (x_rot > STOP_MAX && x_rot <= MAX_ROTATION + FP_TOLERANCE)
            {
                orbitManager.LinearSpeed = (x_rot - STOP_MAX) / (MAX_ROTATION - STOP_MAX) * MAX_SPEED;
            }
            else if (x_rot < 360.0f + STOP_MIN && x_rot >= 360.0f + MIN_ROTATION - FP_TOLERANCE)
            {
                orbitManager.LinearSpeed = (x_rot - (360.0f + STOP_MIN)) / (STOP_MIN - MIN_ROTATION) * MAX_SPEED;
            }
            else
            {
                orbitManager.LinearSpeed = 0.0f;

                //moves controller to exact center if you let go of it the zone considered 'stop' or '0 speed'
                if (numActive <= 0 && AcceptingInput)
                {
                    SetThrottle(0.0f);
                }
            }

            //updates the speed label
            SetLabel(orbitManager.LinearSpeed);
        }
    }
Exemple #13
0
 private void Start()
 {
     otherPlayer = otherPlayerController.GetComponent <AllowToDraw>();
     trackedObj  = GetComponent <SteamVR_TrackedObject>();
     PlayerTurn  = true;
 }
Exemple #14
0
 void Start()
 {
     otherPlayer = otherPlayerController.GetComponent <AllowToDraw>();
     player      = playerController.GetComponent <AllowToDraw>();
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        device = SteamVR_Controller.Input((int)trackedObject.index);

        if (tollary.GetComponent <Tmove>().touch == 0)
        {
            if (controller.padPressed)
            {
                float x = device.GetAxis().x;
                float y = device.GetAxis().y;

                Vector3 forward;

                if (x != 0 || y != 0)
                {
                    int areaTag = area(x, y);

                    if (areaTag == 1 || areaTag == 3)
                    {
                        forward = controller.transform.TransformDirection(Vector3.forward);
                        float curSpeed = m_Speed * y;
                        player.SimpleMove(forward * curSpeed);
                    }
                    else if (areaTag == 2 || areaTag == 4)
                    {
                        player.transform.Rotate(0, x * m_TurnSpeed, 0);
                    }
                }

                step = 1;
                if (record == false)
                {
                    //time = System.DateTime.Now;
                    elapsedTime = new TimeSpan(DateTime.Now.Ticks);
                    record      = true;
                }
                TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts  = ts2.Subtract(elapsedTime).Duration();

                if (record == true && ts.Seconds >= 1)
                {
                    if (tollary.GetComponent <Tmove>().touch == 0)
                    {
                        if (HistoryPos.Count > 5)
                        {
                            HistoryPos.RemoveAt(0);
                            HistoryRot.RemoveAt(0);
                        }

                        position = controller.GetComponent <Transform>().position;
                        //position.y = 0.5f;
                        Quaternion rot = transform.rotation;

                        HistoryPos.Add(position);
                        HistoryRot.Add(rot);
                        Debug.Log("记录在位置 " + HistoryPos.Count);

                        record = false;
                    }
                }
            }
        }
        else
        {
            if (HistoryPos.Count > 0)
            {
                Debug.Log("循环论多少遍啊" + step);
                int index = HistoryPos.Count - step;
                if (index < 0)
                {
                    step = 1; index = HistoryPos.Count - step;
                }
                Vector3 temp = HistoryPos[index];
                temp.y = -0.3f;
                player.GetComponent <Transform>().position = temp;
            }
            if (HistoryRot.Count > 0)
            {
                int index = HistoryRot.Count - step;
                this.transform.rotation = HistoryRot[index];
            }
            //Debug.Log("循环多少遍啊" + step);
            if (step < 5)
            {
                step++;
            }
        }
    }