Ejemplo n.º 1
0
        public void HandleGrabRequest(EntityId grabberEntityId, ControllerSide controllerSide, GameObject controllerGameObject)
        {
            if (controllerGameObject == null)
            {
                return;
            }

            // Check collisions to determine grab legality
            Collider controllerCollider = controllerGameObject.GetComponent <Collider>();

            if (controllerCollider == null)
            {
                return;
            }

            if (AnyCollision(controllerCollider, gameObject.GetComponentsInChildren <Collider>()))
            {
                var inverseControllerOrientation = UnityEngine.Quaternion.Inverse(controllerGameObject.transform.rotation);
                var relativeOrientation          = inverseControllerOrientation * gameObject.transform.rotation;
                var relativePosition             = inverseControllerOrientation * (gameObject.transform.position - controllerGameObject.transform.position);

                var grabberInfo = new CurrentGrabberInfo(grabberEntityId, controllerSide, relativePosition.ToVector3f(), MathUtils.ToNativeQuaternion(relativeOrientation));
                GrabbableWriter.Send(new Grabbable.Update().SetCurrentGrabberInfo(grabberInfo));
            }
        }
        private void SendPickupRequest(ControllerSide controllerSide, EntityId reachableObjectId)
        {
            var update           = new Grab.Update();
            var grabRequestEvent = new GrabRequestEvent(reachableObjectId, controllerSide);

            update.AddGrabRequest(grabRequestEvent);
            GrabWriter.Send(update);
        }
 public static ControllerSide OtherController(ControllerSide controllerSide)
 {
     if (controllerSide.Equals(ControllerSide.LEFT))
     {
         return(ControllerSide.RIGHT);
     }
     else
     {
         return(ControllerSide.LEFT);
     }
 }
Ejemplo n.º 4
0
 public override void Reset()
 {
     base.Reset();
     Power          = 10.0f;
     BouncySides    = ControllerSide.Right;
     AccurateBounce = false;
     LockControl    = false;
     LockDuration   = 0.266667f;
     KeepOnGround   = false;
     HitTrigger     = "";
 }
        public void UpdateHeldEntity(ControllerSide controllerSide, Option <EntityId> grabbedObjectId)
        {
            var heldEntities = GrabWriter.Data.heldEntities;

            heldEntities.Remove(controllerSide);
            if (grabbedObjectId.HasValue)
            {
                heldEntities.Add(controllerSide, grabbedObjectId.Value);
            }
            GrabWriter.Send(new Grab.Update().SetHeldEntities(heldEntities));
        }
 public GameObject GetController(ControllerSide controllerSide)
 {
     if (controllerSide.Equals(ControllerSide.LEFT))
     {
         return(LeftController);
     }
     else
     {
         return(RightController);
     }
 }
Ejemplo n.º 7
0
        public Quaternion GetLocalRotation(ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Left:
                return(InputTracking.GetLocalRotation(XRNode.LeftHand));

            case ControllerSide.Right:
                return(InputTracking.GetLocalRotation(XRNode.RightHand));

            default:
                return(Quaternion.identity);
            }
        }
Ejemplo n.º 8
0
        public bool GetClick(ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Left:
                return(Input.GetKey(KeyCode.JoystickButton16));

            case ControllerSide.Right:
                return(Input.GetKey(KeyCode.JoystickButton17));

            default:
                return(false);
            }
        }
Ejemplo n.º 9
0
        public Vector3 GetLocalPosition(ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Left:
                return(InputTracking.GetLocalPosition(XRNode.LeftHand));

            case ControllerSide.Right:
                return(InputTracking.GetLocalPosition(XRNode.RightHand));

            default:
                return(Vector2.zero);
            }
        }
Ejemplo n.º 10
0
        public Vector2 GetCoord(ControllerSide side)
        {
            var interactionStates = InteractionManager.GetCurrentReading();

            foreach (var state in interactionStates)
            {
                if (side == ControllerSide.Left && state.source.handedness == InteractionSourceHandedness.Left ||
                    side == ControllerSide.Right && state.source.handedness == InteractionSourceHandedness.Right)
                {
                    return(state.touchpadPosition);
                }
            }
            return(Vector2.zero);
        }
Ejemplo n.º 11
0
        protected void SetControllerInput(ControllerSide controllerSide)
        {
            controllerSide.stickHorizontal += Mathf.Clamp(openVRController.joystick.x + openVRController.touchpad.x, -1, 1);
            controllerSide.stickVertical   += Mathf.Clamp(openVRController.joystick.y + openVRController.touchpad.y, -1, 1);
            controllerSide.stickButton     |= (openVRController.joystick.z > 0.5F) || (openVRController.touchpad.z > 0.5F);

            controllerSide.buttons[0] |= openVRController.aButton > 0.5F;
            controllerSide.buttons[1] |= openVRController.bButton > 0.5F;

            controllerSide.trigger1 += openVRController.trigger;
            controllerSide.trigger2 += openVRController.grip;

            controllerSide.option |= openVRController.aButton > 0.5F;
        }
Ejemplo n.º 12
0
        private void UpdateLocalCurrentGrabberInfo(Option <CurrentGrabberInfo> infoOption)
        {
            CurrentGrabberInfo currentGrabberInfo;

            if (infoOption.TryGetValue(out currentGrabberInfo))
            {
                // Update local variables with new grabber
                grabberEntityId       = currentGrabberInfo.grabberEntity;
                grabberControllerSide = currentGrabberInfo.controllerSide;
            }
            else
            {
                // No current grabber, so indicate this with an empty option
                grabberEntityId.Clear();
            }
        }
Ejemplo n.º 13
0
        public static BodySide ToBody(this ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Right:
                return(BodySide.Right);

            case ControllerSide.Left:
                return(BodySide.Left);

            case ControllerSide.None:
                return(BodySide.None);

            default:
                throw new ArgumentOutOfRangeException("side", side, null);
            }
        }
Ejemplo n.º 14
0
        public static float ControllerSideToNormal(ControllerSide side)
        {
            switch (side)
            {
            case ControllerSide.Right:
            default:
                return(0.0f);

            case ControllerSide.Top:
                return(90.0f);

            case ControllerSide.Left:
                return(180.0f);

            case ControllerSide.Bottom:
                return(270.0f);
            }
        }
Ejemplo n.º 15
0
        private void OnGrabbableUpdated(Grabbable.Update update)
        {
            if (!update.currentGrabberInfo.HasValue)
            {
                return;
            }

            var            previousGrabberEntityId       = grabberEntityId;
            ControllerSide previousGrabberControllerSide = grabberControllerSide;

            UpdateLocalCurrentGrabberInfo(update.currentGrabberInfo.Value);

            if (grabberEntityId != previousGrabberEntityId ||
                grabberControllerSide != previousGrabberControllerSide)
            {
                // Current grabber has changed or side
                if (previousGrabberEntityId.HasValue)
                {
                    // Notify the previous grabber entity it no longer holds the item
                    GameObject     previousControllerGameObject = LocalEntities.Instance.Get(previousGrabberEntityId.Value).UnderlyingGameObject;
                    GrabbingSender grabbingSender = previousControllerGameObject.GetComponent <GrabbingSender>();

                    // GrabbingSender will be disabled on workers not authoritative over dropped object's Grabbable
                    if (grabbingSender != null && grabbingSender.isActiveAndEnabled)
                    {
                        grabbingSender.ForceLocalDrop(previousGrabberControllerSide);
                    }
                }

                if (grabberEntityId.HasValue)
                {
                    // Update grabbing on the new game object
                    GameObject     controllerGameObject = LocalEntities.Instance.Get(grabberEntityId.Value).UnderlyingGameObject;
                    GrabbingSender grabbingSender       = controllerGameObject.GetComponent <GrabbingSender>();
                    if (grabbingSender != null && grabbingSender.isActiveAndEnabled)
                    {
                        grabbingSender.UpdateHeldEntity(grabberControllerSide, gameObject.EntityId());
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public float GetHold(ControllerSide side)
        {
            var interactionStates = InteractionManager.GetCurrentReading();

            foreach (var state in interactionStates)
            {
                if (side == ControllerSide.Left && state.source.handedness == InteractionSourceHandedness.Left ||
                    side == ControllerSide.Right && state.source.handedness == InteractionSourceHandedness.Right)
                {
                    if (state.grasped)
                    {
                        return(1.0f);
                    }
                    else
                    {
                        return(0.0f);
                    }
                }
            }
            return(0.0f);
        }
Ejemplo n.º 17
0
        public TerrainCastHit Initialize(RaycastHit2D hit, ControllerSide fromSide = ControllerSide.All,
                                         HedgehogController controller             = null, Vector2 start = default(Vector2), Vector2 end = default(Vector2))
        {
            Start        = start;
            End          = end;
            Hit          = hit;
            Side         = fromSide;
            Controller   = controller;
            NormalAngle  = DMath.Modp(DMath.Angle(hit.normal), DMath.DoublePi);
            SurfaceAngle = DMath.Modp(NormalAngle - DMath.HalfPi, DMath.DoublePi);

            if (!hit)
            {
                return(this);
            }

            Transform = hit.transform;
            Collider  = hit.collider;

            return(this);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Performs a linecast against the terrain taking into account a controller's attributes.
        /// </summary>
        /// <param name="source">The controller that queried the linecast.</param>
        /// <param name="start">The beginning of the linecast.</param>
        /// <param name="end">The end of the linecast.</param>
        /// <param name="fromSide">The side from which the linecast originated, if any.</param>
        /// <returns></returns>
        public static TerrainCastHit TerrainCast(this HedgehogController source, Vector2 start,
                                                 Vector2 end, ControllerSide fromSide = ControllerSide.All)
        {
            var amount = Physics2D.LinecastNonAlloc(start, end, LinecastResults, source.CollisionMask);

            if (amount == 0)
            {
                return(null);
            }

            for (var i = 0; i < amount; ++i)
            {
                var hit = GetTerrainCastHit().Initialize(LinecastResults[i], fromSide, source, start, end);
                if (!TransformSelector(hit))
                {
                    continue;
                }
                return(hit);
            }

            return(null);
        }
Ejemplo n.º 19
0
    void UpdateSide(ref ControllerSideDebugger sideDebugger, ControllerSide controllerSide)
    {
        sideDebugger.stickHorizontal = controllerSide.stickHorizontal;
        sideDebugger.stickVertical   = controllerSide.stickVertical;

        sideDebugger.stickButton = controllerSide.stickButton;
        sideDebugger.stickTouch  = controllerSide.stickTouch;

        //sideDebugger.up = controllerSide.up;
        //sideDebugger.down = controllerSide.down;
        //sideDebugger.left = controllerSide.left;
        //sideDebugger.right = controllerSide.right;

        sideDebugger.buttons[0] = controllerSide.buttons[0];
        sideDebugger.buttons[1] = controllerSide.buttons[1];
        sideDebugger.buttons[2] = controllerSide.buttons[2];
        sideDebugger.buttons[3] = controllerSide.buttons[3];

        sideDebugger.bumper  = controllerSide.trigger1;
        sideDebugger.trigger = controllerSide.trigger2;

        sideDebugger.option = controllerSide.option;
    }
Ejemplo n.º 20
0
 public static bool GetHover(ControllerSide side)
 {
     return(OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, GetOVRController(side)));
 }
Ejemplo n.º 21
0
 public static float GetHold(ControllerSide side)
 {
     return(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, GetOVRController(side)));
 }
Ejemplo n.º 22
0
 public static Quaternion GetLocalRotation(ControllerSide side)
 {
     return(OVRInput.GetLocalControllerRotation(GetOVRController(side)));
 }
Ejemplo n.º 23
0
 public static Vector3 GetLocalPosition(ControllerSide side)
 {
     return(OVRInput.GetLocalControllerPosition(GetOVRController(side)));
 }
Ejemplo n.º 24
0
 private static OVRInput.Controller GetOVRController(ControllerSide side)
 {
     return((side == ControllerSide.Left) ?
            OVRInput.Controller.LTouch :
            OVRInput.Controller.RTouch);
 }
Ejemplo n.º 25
0
 public Vector2 GetCoord(ControllerSide side)
 {
     return(_instance.GetCoord(side));
 }
Ejemplo n.º 26
0
 public bool GetClick(ControllerSide side)
 {
     return(_instance.GetClick(side));
 }
Ejemplo n.º 27
0
 public bool GetHover(ControllerSide side)
 {
     return(_instance.GetHover(side));
 }
Ejemplo n.º 28
0
 public static bool GetClick(ControllerSide side)
 {
     return(OVRInput.Get(OVRInput.Button.PrimaryThumbstick, GetOVRController(side)));
 }
Ejemplo n.º 29
0
 public static Vector2 GetCoord(ControllerSide side)
 {
     return(OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, GetOVRController(side)));
 }
Ejemplo n.º 30
0
 public float GetHold(ControllerSide side)
 {
     return(_instance.GetHold(side));
 }