Exemple #1
0
    IEnumerator FadeOut()
    {
        Destroy(GameObject.Find("BootupText")); // Why are we doing this? So the glitch effect plays?
        Debug.Log("IT'S Gone");
        textCanvasGrewp.alpha = 0;

        while (textCanvasGrewp.alpha < 1)
        {
            textCanvasGrewp.alpha += Time.deltaTime / textFadeDuration;
            yield return(null);
        }

        yield return(new WaitForSeconds(textShowDuration));

        while (fadeCanvasGrewp.alpha < 1)
        {
            fadeCanvasGrewp.alpha += Time.deltaTime / textFadeDuration;
            yield return(null);
        }

        // Set scene transition fade up before moving the player in preparation for the handoff to GameStateHome fading it out
        CanvasGroup sceneTransitionFade = GameObject.Find("SceneTransitionFade").GetComponent <CanvasGroup>();

        sceneTransitionFade.alpha = 1f;

        // Before sending player back home, destroy held item
        PickupHolder pickupHolder = FindObjectOfType <PickupHolder>();

        if (pickupHolder)
        {
            Pickupable heldItem = pickupHolder.GetHeldItem();
            if (heldItem)
            {
                Object.Destroy(heldItem.gameObject);
            }
        }

        FindObjectOfType <PlayableDirector>().enabled = false;
        EventBus.PublishEvent(new ReturnHomeEvent());
    }
Exemple #2
0
    public override void DoUpdate()
    {
        if (canPause && (Input.GetKeyUp(KeyCode.Escape) || player.GetButtonUp("Pause")))
        {
            this.stateMachine.ChangeState(pauseMenuState);
            return;
        }

        if (debugCheatsEnabled)
        {
            // Hold back tick, then press 'O' to cheat an objective item in front of you
            if (Input.GetKey(KeyCode.BackQuote) && Input.GetKeyDown(KeyCode.O))
            {
                // Debug.Log("Cheat Keys Hit");
                ObjectivePickupable objectiveItem = GameObject.FindObjectOfType <ObjectivePickupable>();
                if (objectiveItem)
                {
                    // Debug.Log("Objective Item Found");
                    if (Vector3.Distance(movement.transform.position, objectiveItem.transform.position) > 5f)
                    {
                        Debug.Log("Dropping " + objectiveItem + " in front of player.");
                        Vector3 playerForwardDirection = movement.transform.TransformDirection(Vector3.forward);
                        objectiveItem.transform.position = movement.transform.position + (playerForwardDirection * 3f) + Vector3.up;
                    }
                }
            }
        }

        if (Input.GetKey("space") || player.GetAxis("ShowPhoto") > 0)
        {
            photo.ShowPhoto();
        }
        else
        {
            photo.HidePhoto();
        }

        Interactable focusedInteractable = interactionDetector.GeInteractableInFocus(); // Note: the held item is never focused

        // Handle Movement & Looking
        if (focusedInteractable == null || !focusedInteractable.IsInteractionRestrictingMovement())
        {
            float keyboardVertical   = Input.GetAxisRaw("Vertical");
            float keyboardHorizontal = Input.GetAxisRaw("Horizontal");

            float forward = Mathf.Abs(keyboardVertical) > 0 ? keyboardVertical : player.GetAxis("Move Vertical");
            float strafe  = Mathf.Abs(keyboardHorizontal) > 0 ? keyboardHorizontal : player.GetAxis("Move Horizontal");

            Vector3 moveVector = Vector3.forward * forward + Vector3.right * strafe;
            moveVector = moveVector.sqrMagnitude > 1f ? moveVector.normalized : moveVector;
            bool isRunning = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) || player.GetAxis("Run") > 0f);
            movement.Move(moveVector, isRunning);
        }

        if (focusedInteractable == null || !focusedInteractable.IsInteractionRestrictingView())
        {
            float lookX = player.GetAxis("Look Horizontal"); // Input.GetAxis("Mouse X");
            float lookY = player.GetAxis("Look Vertical");   // Input.GetAxis("Mouse Y");

            Vector2 lookVector = Vector2.up * lookY + Vector2.right * lookX;
            playerView.Look(lookVector); // Looking along vertical axis only rotates the camera view
            playerView.AddToYaw(lookX);  // Looking along horizontal axis rotates the player
        }

        ///                                 IsInteracting == true               isInteracting == false
        /// focusedInteractable == null               N\A               |        attempt pick up / drop
        ///                              -------------------------------|--------------------------------------
        /// focusedInteractable != null     handle multi interaction    |     begin interaction attempt

        // Handle Interactions
        if (focusedInteractable != null)
        {
            // Handle Beginning of Interaction
            if (!focusedInteractable.IsInteracting())
            {
                // Handle Picking Up item
                Pickupable focusedPickupable = focusedInteractable.GetComponent <Pickupable>();
                if (focusedPickupable != null && pickupHolder.GetHeldItem() == null)
                {
                    // Possibly split out pick and and drop if we map these actions to different inputs
                    bool pickUp = player.GetButtonDown("Pickup/Drop"); // Input.GetMouseButtonDown(0);
                    if (pickUp)
                    {
                        Debug.Log("Pick Up at " + Time.time);
                    }
                    if (pickUp)
                    {
                        pickupHolder.TryPickupOrDrop(); // This will try to pickup when held item is null
                    }
                }
                // Attempt beginning of iteraction
                else
                {
                    bool interact = player.GetButtonDown("Interact"); // Input.GetMouseButtonDown(0);
                    if (interact)
                    {
                        Debug.Log("Interact at " + Time.time);
                    }
                    if (interact && focusedInteractable != null)
                    {
                        interactionDetector.PerformInteraction();
                    }
                }
            }
            // Handle Multiple Input Interaction
            else
            {
                // Do stuff here
            }
        }
        // Drop item
        else
        {
            // Possibly split out pick and and drop if we map these actions to different inputs
            bool drop = player.GetButtonDown("Pickup/Drop"); // Input.GetMouseButtonDown(0);
            if (drop)
            {
                Debug.Log("Drop at " + Time.time);
            }
            if (drop)
            {
                pickupHolder.TryPickupOrDrop(); // This will drop the held item if not null
            }
        }
    }
Exemple #3
0
    private void UpdateInteractableInFocus()
    {
        /* For the moment, we will allow other interactables to come into focus while other interactions are ongoing
         * // Do not change the interactableInFocus if it is currently being interacted with
         * if (interactableInFocus != null && interactableInFocus.IsInteracting())
         * {
         *  return; // Exit update and do not reset interactableInFocus
         * }
         */

        // Check whether a new interactable should now be in focus
        /// Note: A variety of events will affect what is currently the nearest valid interactable
        ///         These events include:   Player moving and/or looking around
        ///                                 Player dropping current item or picking up a new one
        ///                                 New interactable entering or exiting detector
        ///                                 Interactable internal state changing, resulting in CanInteractWith() => true
        ///         This effectively means that we may as well check every frame which item should be in focus
        if (interactablesInRange.Count > 0)
        {
            SortInteractablesInRange();
            foreach (Interactable interactable in interactablesInRange)
            {
                if (!interactable)
                {
                    continue;
                }

                Pickupable pickupable = interactable.GetComponent <Pickupable>();

                // Ignore the currently held item
                if (pickupable && pickupable == pickupHolder.GetHeldItem())
                {
                    continue;
                }

                // Ignore pickupables that are currently enclosed within a container
                if (pickupable && Container.CheckContained(pickupable.gameObject))
                {
                    continue;
                }

                // Ignore interactables if they cannot be interacted with given the currently held item
                if (!interactable.CanInteractWith(pickupHolder.GetHeldItem()))
                {
                    continue;
                }

                // Update outline highlight if nearest valid interactable is different from the previous interactable in focus
                if (interactable != interactableInFocus)
                {
                    if (interactableInFocus != null)
                    {
                        OutlineManager.Instance.UnapplyOutline(interactableInFocus.gameObject); // Highlighted is the Highlander...
                    }
                    OutlineManager.Instance.ApplyOutline(interactable.gameObject);              // ...There can only be one!
                    interactableInFocus = interactable;
                }

                return; // Exit once interactableInFocus is found, whether current or new
            }
        }
        // If there are no valid interactables in range, set interactableInFocus to null
        // UnapplyOutline here rather than in OnTriggerExit?
        interactableInFocus = null;
    }