コード例 #1
0
        public override void OnRayHover(Ray ray)
        {
            base.OnRayHover(ray);

            bool joyRightJustClicked  = false;
            bool joyRightJustReleased = false;
            bool joyRightLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.primaryController, VRInput.JoyDirection.RIGHT, ref joyRightJustClicked, ref joyRightJustReleased, ref joyRightLongPush);

            bool joyLeftJustClicked  = false;
            bool joyLeftJustReleased = false;
            bool joyLeftLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.primaryController, VRInput.JoyDirection.LEFT, ref joyLeftJustClicked, ref joyLeftJustReleased, ref joyLeftLongPush);

            if (joyRightJustClicked || joyLeftJustClicked || joyRightLongPush || joyLeftLongPush)
            {
                if (joyRightJustClicked || joyRightLongPush)
                {
                    Value = Mathf.Clamp(Value + 1.0f, minValue, maxValue);
                }
                else if (joyLeftJustClicked || joyLeftLongPush)
                {
                    Value = Mathf.Clamp(Value - 1.0f, minValue, maxValue);
                }
                onSlideEvent.Invoke(currentValue);
                int intValue = Mathf.RoundToInt(currentValue);
                onSlideEventInt.Invoke(intValue);
            }
        }
コード例 #2
0
ファイル: PlayerController.cs プロジェクト: ubisoft/vrtist
        private void HandleTimeManipulation()
        {
            bool joyRightJustClicked  = false;
            bool joyRightJustReleased = false;
            bool joyRightLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.secondaryController, VRInput.JoyDirection.RIGHT, ref joyRightJustClicked, ref joyRightJustReleased, ref joyRightLongPush);

            bool joyLeftJustClicked  = false;
            bool joyLeftJustReleased = false;
            bool joyLeftLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.secondaryController, VRInput.JoyDirection.LEFT, ref joyLeftJustClicked, ref joyLeftJustReleased, ref joyLeftLongPush);

            // Manage time with joystick
            if (joyRightJustClicked || joyLeftJustClicked || joyRightLongPush || joyLeftLongPush)
            {
                int frame = GlobalState.Animation.CurrentFrame;
                if (joyRightJustClicked || joyRightLongPush)
                {
                    frame = Mathf.Clamp(frame + 1, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame);
                }
                else
                {
                    frame = Mathf.Clamp(frame - 1, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame);
                }
                GlobalState.Animation.CurrentFrame = frame;
            }
        }
コード例 #3
0
        public override void OverrideRayEndPoint(Ray ray, ref Vector3 rayEndPoint)
        {
            bool triggerJustClicked  = false;
            bool triggerJustReleased = false;

            VRInput.GetInstantButtonEvent(VRInput.primaryController, CommonUsages.triggerButton, ref triggerJustClicked, ref triggerJustReleased);

            // Project ray on the widget plane.
            Plane widgetPlane = new Plane(-transform.forward, transform.position);
            float enter;

            widgetPlane.Raycast(ray, out enter);
            Vector3 worldCollisionOnWidgetPlane = ray.GetPoint(enter);

            Vector3 localWidgetPosition          = transform.InverseTransformPoint(worldCollisionOnWidgetPlane);
            Vector3 localProjectedWidgetPosition = new Vector3(localWidgetPosition.x, localWidgetPosition.y, 0.0f);

            if (IgnoreRayInteraction())
            {
                // return endPoint at the surface of the widget.
                rayEndPoint = transform.TransformPoint(localProjectedWidgetPosition);
                return;
            }

            // CLAMP

            float startX = 0.0f;
            float endX   = width;

            if (localProjectedWidgetPosition.x < startX)
            {
                localProjectedWidgetPosition.x = startX;
            }

            if (localProjectedWidgetPosition.x > endX)
            {
                localProjectedWidgetPosition.x = endX;
            }

            localProjectedWidgetPosition.y = -height / 2.0f;

            // GRIP CLOSEST Keyframe

            if (triggerJustClicked)
            {
                deltaFrame = 0;
                float distThreshold = 0.31f / 20.0f;
                closestIndex = -1;
                float closestDistance = Mathf.Infinity;
                int   i = 0;
                foreach (Transform child in transform)
                {
                    float dist = Mathf.Abs(localProjectedWidgetPosition.x - child.localPosition.x);
                    if (dist < closestDistance && dist < distThreshold)
                    {
                        closestDistance = dist;
                        closestIndex    = i;
                    }
                    i++;
                }

                if (closestIndex != -1)
                {
                    localProjectedWidgetPosition.x = transform.GetChild(closestIndex).localPosition.x;
                }
            }
            else if (triggerJustReleased)
            {
                dopesheet.OnUpdateKeyframe(closestIndex, deltaFrame);
                deltaFrame   = 0;
                closestIndex = -1;
            }
            else
            {
                // JOYSTICK Left/Right
                bool joyRightJustClicked  = false;
                bool joyRightJustReleased = false;
                bool joyRightLongPush     = false;
                VRInput.GetInstantJoyEvent(VRInput.primaryController, VRInput.JoyDirection.RIGHT, ref joyRightJustClicked, ref joyRightJustReleased, ref joyRightLongPush);

                bool joyLeftJustClicked  = false;
                bool joyLeftJustReleased = false;
                bool joyLeftLongPush     = false;
                VRInput.GetInstantJoyEvent(VRInput.primaryController, VRInput.JoyDirection.LEFT, ref joyLeftJustClicked, ref joyLeftJustReleased, ref joyLeftLongPush);

                if (joyRightJustClicked || joyLeftJustClicked || joyRightLongPush || joyLeftLongPush)
                {
                    float localDeltaOneFrame = dopesheet != null ? 0.31f / (dopesheet.LocalLastFrame - dopesheet.LocalFirstFrame) : 0.0f;
                    if (joyRightJustClicked || joyRightLongPush)
                    {
                        if (closestIndex != -1)
                        {
                            deltaFrame++;
                            Transform child            = transform.GetChild(closestIndex);
                            Vector3   newChildPosition = child.localPosition + new Vector3(+localDeltaOneFrame, 0, 0);
                            localProjectedWidgetPosition.x = newChildPosition.x;
                            child.localPosition            = newChildPosition;
                        }
                    }
                    else if (joyLeftJustClicked || joyLeftLongPush)
                    {
                        if (closestIndex != -1)
                        {
                            deltaFrame--;
                            Transform child            = transform.GetChild(closestIndex);
                            Vector3   newChildPosition = child.localPosition + new Vector3(-localDeltaOneFrame, 0, 0);
                            localProjectedWidgetPosition.x = newChildPosition.x;
                            child.localPosition            = newChildPosition;
                        }
                    }
                }
                else
                {
                    if (closestIndex != -1)
                    {
                        localProjectedWidgetPosition.x = transform.GetChild(closestIndex).localPosition.x;
                    }
                }
            }

            // OUT ray end point

            Vector3 worldProjectedWidgetPosition = transform.TransformPoint(localProjectedWidgetPosition);

            rayEndPoint = worldProjectedWidgetPosition;
        }