Ejemplo n.º 1
0
    private void CycleReticleState()
    {
        switch (ShowReticles)
        {
        case ReticleState.NONE:
            ShowReticles = ReticleState.ALL;
            _tags        = new List <string>();
            _tags.AddRange(MainTags);
            _tags.AddRange(SecondaryTags);
            _detector = new ChildTagTargetDetector
            {
                Tags = _tags
            };
            break;

        case ReticleState.ALL:
            ShowReticles = ReticleState.MAIN;
            _tags        = MainTags;
            _detector    = new ChildTagTargetDetector
            {
                Tags = _tags
            };
            break;

        case ReticleState.MAIN:
            ShowReticles = ReticleState.NONE;
            break;
        }
        Debug.Log(ShowReticles);
    }
Ejemplo n.º 2
0
        private void CycleReticleState()
        {
            switch (ShowReticles)
            {
            case ReticleState.NONE:
                ShowReticles = ReticleState.ALL;
                _detector    = new ChildTagTargetDetector
                {
                    Tags = Tags
                };
                break;

            case ReticleState.ALL:
                ShowReticles = ReticleState.MAIN;
                _detector    = new ChildTagTargetDetector
                {
                    Tags = Tags
                };
                break;

            case ReticleState.MAIN:
                ShowReticles = ReticleState.NONE;
                break;
            }
            Debug.Log(ShowReticles);
        }
Ejemplo n.º 3
0
    Vector2 _textureSize = Vector2.zero; // Keeps track of the texture scale

    #endregion Fields

    #region Methods

    public void SetState(ReticleState newState)
    {
        if (_reticleState != newState)
        {
          _reticleState = newState;

          _currentCoroutineIndex++;

          // Start the update tiling coroutine
          StartCoroutine(updateTiling());
        }
    }
Ejemplo n.º 4
0
    public void SetState(ReticleState newState)
    {
        if (_reticleState != newState)
        {
            _reticleState = newState;

            _currentCoroutineIndex++;

            // Start the update tiling coroutine
            StartCoroutine(updateTiling());
        }
    }
Ejemplo n.º 5
0
 /// <summary>
 /// Releases object
 /// </summary>
 public void ReleaseObject()
 {
     IntroSessionManager.s_Instance.ReticleSetDefaultState();
     m_CurrentReticleState = ReticleState.DefaultState;
     m_ObjectHeld.GetComponent <Rigidbody>().isKinematic = false;
     m_ObjectHeld.transform.parent   = null;
     m_ObjectHeld.transform.position = OVRInput.GetLocalControllerPosition(Controller) + m_OffsetVector;
     m_HoldingObject = false;
     m_ObjectHeld    = null;
     // Notify subscribers that an object has been picked up
     if (e_ObjectWasDropped != null)
     {
         e_ObjectWasDropped();
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Grabs an object and makes it a child of the controller model.
        /// </summary>
        public void GrabObject()
        {
            // put the reticle in a interacting state.
            IntroSessionManager.s_Instance.ReticleSetInteracting();
            m_CurrentReticleState = ReticleState.InteractingState;

            // Grab the object
            m_ObjectHeld.GetComponent <Rigidbody>().isKinematic = true;
            m_ObjectHeld.transform.parent   = m_ControllerModel.transform;
            m_ObjectHeld.transform.position = OVRInput.GetLocalControllerPosition(Controller) + m_OffsetVector;
            m_HoldingObject = true;

            // Notify subscribers that an object has been picked up
            if (e_ObjectWasPickedUp != null)
            {
                e_ObjectWasPickedUp();
            }
        }
Ejemplo n.º 7
0
        private void SwitchReticleState(ReticleState state)
        {
            switch (state)
            {
            case ReticleState.Hide:
                m_DefaultVisual.SetActive(false);
                m_HoverVisual.SetActive(false);
                break;

            case ReticleState.Normal:
                m_DefaultVisual.SetActive(true);
                m_HoverVisual.SetActive(false);
                break;

            case ReticleState.Hover:
                m_DefaultVisual.SetActive(false);
                m_HoverVisual.SetActive(true);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        public override void Update(GameTime gameTime)
        {
            MouseState mouseState = Mouse.GetState();
            _position = new Vector2(mouseState.X, mouseState.Y);
            FiredThisFrame = false;

            int gameMs = (int)gameTime.TotalGameTime.TotalMilliseconds;

            if (_powerupActive)
            {
                _rotation = -(float)(Math.PI * 2 * (_powerupEndTime.TotalMilliseconds - gameMs) / _powerupDuration.TotalMilliseconds);

                if (gameTime.TotalGameTime > _powerupEndTime)
                {
                    EndPowerUp(gameTime);
                }
            }

            if (State == ReticleState.Reloading)
            {
                if (gameTime.TotalGameTime > _reloadStartTime + _reloadDuration)
                {
                    Reload();
                    _color = Color.White;
                    State = ReticleState.Idle;
                }
                else
                {
                    float reloadRatio =
                        (float)((gameMs - _reloadStartTime.TotalMilliseconds) / _reloadDuration.TotalMilliseconds);

                    CurrentAmmo = (int)(MaxAmmo * reloadRatio);

                    _rotation = -(float)Math.PI * 2 * reloadRatio;
                }
            }
            else
            {

                if (mouseState.LeftButton == ButtonState.Pressed &&
                    (State == ReticleState.Firing ||
                    (State == ReticleState.Idle && _prevMouseState.LeftButton == ButtonState.Released))
                   )
                {
                    if (gameMs > _lastFire + _fireDelay)
                    {
                        _lastFire = gameMs;

                        if (CurrentAmmo <= 0)
                        {
                            _color = Color.Red;
                            _rotation = 0;

                            if (_prevMouseState.LeftButton == ButtonState.Released)
                            {
                                State = ReticleState.Reloading;
                                _reloadStartTime = gameTime.TotalGameTime;
                                // Play gun reloading sound
                                Game.PlayCue("gunreload");
                            }
                            else
                            {
                                // Play gun empty click sound
                                Game.PlayCue("metallicclick");
                            }
                        }
                        else
                        {
                            Game.PlayCue("m21shot");
                            State = ReticleState.Firing;
                            FiredThisFrame = true;

                            if (!_powerupActive)
                            {
                                _rotation = -(float)(Math.PI * 2 * CurrentAmmo / (float)MaxAmmo);
                                CurrentAmmo--;
                            }

                            double recoilAngle = Game.NextDouble() * Math.PI * 2;

                            Vector2 recoil;
                            recoil.X = (float)(Math.Sin(recoilAngle) * _recoilDistance);
                            recoil.Y = (float)(Math.Cos(recoilAngle) * _recoilDistance);

                            Mouse.SetPosition(mouseState.X + (int)Math.Round(recoil.X),
                                              mouseState.Y + (int)Math.Round(recoil.Y));
                        }
                    }
                }
                else
                {
                    State = ReticleState.Idle;
                }
            }

            _prevMouseState = mouseState;
            base.Update(gameTime);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Function will emit a raycast from the camera or controller. It will set <c>m_Target</c> to the current object being raycast on.
        /// Inside this function is also where the events are triggered and objects are interacted with (held/thrown/clicked on).
        /// </summary>
        private void Raycast()
        {
            // Show the debug ray if required
            if (m_ShowDebugRay)
            {
                Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration);
            }

            // Create a ray that points forwards from the camera.
            Ray        ray = new Ray(m_Camera.position, m_Camera.forward);
            RaycastHit hit;

            Vector3 worldStartPoint = Vector3.zero;
            Vector3 worldEndPoint   = Vector3.zero;

            // If the controller is connected and we are past Scene 1, emit the raycast from the controller instead of the camera
            if (ControllerIsConnected && m_TrackingSpace != null && IntroSessionManager.s_Instance.GetCurrentScene() > 1)
            {
                if (!m_ControllerModel.activeSelf)
                {
                    m_ControllerModel.SetActive(true);
                }
                m_ControllerModel.SetActive(true);
                Matrix4x4  localToWorld = m_TrackingSpace.localToWorldMatrix;
                Quaternion orientation  = OVRInput.GetLocalControllerRotation(Controller);

                Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller);
                Vector3 localEndPoint   = localStartPoint + ((orientation * Vector3.forward) * 500.0f);

                worldStartPoint = localToWorld.MultiplyPoint(localStartPoint);
                worldEndPoint   = localToWorld.MultiplyPoint(localEndPoint);

                // Create new ray
                ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint);
            }

            // Do the raycast forwards to see if we hit an interactive item
            if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers))
            {
                m_Target = hit.collider.gameObject;       // the target hit by the raycast

                m_OffsetVector = m_Target.transform.position - OVRInput.GetLocalControllerPosition(Controller);


                // Check if the reticle is in an interacting state
                if (m_CurrentReticleState == ReticleState.InteractingState && !m_HoldingObject)
                {
                    m_ReticleStateTimer += Time.deltaTime;
                    if (m_ReticleStateTimer >= 0.5f)
                    {
                        // Timer is finished, revert back to default
                        IntroSessionManager.s_Instance.ReticleSetDefaultState();
                        m_CurrentReticleState = ReticleState.DefaultState;
                        m_ReticleStateTimer   = 0;
                    }
                }


                // check to see if the raycast is hitting anything we can interact with and was not already aiming at one
                if (m_Target.tag.Contains("_Interactable_"))
                {
                    // Target is interactable

                    if (!m_OverrideDefaultReticleControls)
                    {
                        if (m_CurrentReticleState == ReticleState.DefaultState)
                        {
                            // The reticle is in its default state on the current frame
                            // so put the reticle in a hover state.
                            IntroSessionManager.s_Instance.ReticleSetHoverState();
                            m_CurrentReticleState = ReticleState.HoverState;
                        }
                    }

                    // Check in here for trigger being pulled
                    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
                    {
                        // Add code here to check if user clicks the trigger while targeting an object
                        IntroSessionManager.s_Instance.ReticleSetInteracting(); // Set the reticle to its interacting state
                        m_CurrentReticleState = ReticleState.InteractingState;

                        //if (m_Target.tag.Contains("_EnterTagOnObjectHere_"))


                        if (m_Target.tag.Contains("_Stage3Button_"))
                        {
                            // User clicked on the button
                            AudioSource buttonSound = m_Target.GetComponent <AudioSource>();
                            if (buttonSound != null)
                            {
                                buttonSound.Play();
                            }

                            // Notify any subscribers that the button has been clicked.
                            if (e_ButtonClicked != null)
                            {
                                e_ButtonClicked();
                            }
                        } // End checking for Stage3Button
                    }   // End checking when user pulled trigger
                }
                else
                {
                    // The target is not interactable
                    if (m_CurrentReticleState == ReticleState.HoverState && !m_OverrideDefaultReticleControls)
                    {
                        // On this frame the user is not looking targeting/interacting with an interactable object and the user was on the last frame
                        // Set the reticle state to default
                        IntroSessionManager.s_Instance.ReticleSetDefaultState();
                        m_CurrentReticleState = ReticleState.DefaultState;
                    }
                }


                if (m_ObjectHeld)
                {
                    // Currently holding an object
                    if (OVRInput.GetDown(OVRInput.Button.DpadUp) || OVRInput.GetDown(OVRInput.Button.DpadLeft) || OVRInput.GetDown(OVRInput.Button.DpadRight))
                    {
                        // User swiped, throw ball forward. This works if the user swipes up, left, or right. We found this made it easier for the user to throw the ball forward
                        ThrowObject(1);
                    }
                    else if (OVRInput.GetDown(OVRInput.Button.DpadDown))
                    {
                        // User swiped down, throw ball backwards (towards the user)
                        ThrowObject(-1);
                    }
                    if (!OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger))
                    {
                        //Trigger button is released
                        ReleaseObject();
                        m_ObjectReleased = true;
                    }
                }
                else
                {
                    // not currently holding an object
                    if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger))
                    {
                        // User pulled the trigger in
                        if (m_Target.tag.Contains("_PickUp_"))
                        {
                            // object being aimed at can be picked up
                            if (m_ObjectReleased)
                            {
                                // User has released the trigger since the last time and now held the trigger down (for this frame). Pick up the object
                                m_ObjectHeld = m_Target;
                                GrabObject();
                                m_ObjectReleased = false;
                            }
                        }
                    }
                    else
                    {
                        // User is not pressing the trigger
                        m_ObjectReleased = true;
                    }
                }

                // Something was hit, set at the hit position.
                if (m_Reticle)
                {
                    m_Reticle.SetPosition(hit);
                }
            }
            else
            {
                m_Target = null;
                // Position the reticle at default distance.
                if (m_Reticle)
                {
                    m_Reticle.SetPosition(ray.origin, ray.direction);
                }
            }
        }
Ejemplo n.º 10
0
        private ReticleState m_CurrentReticleState;                                             // The current state of the reticle

        // Used for initialization
        private void Start()
        {
            m_CurrentReticleState = ReticleState.DefaultState;      // Reticle will begin in its default state
            IntroSessionManager.s_Instance.ReticleSetDefaultState();
        }