예제 #1
0
    void OnGUI()
    {
        if (stateHandler && playerInput && settingsManager && runtimeInventory && stateHandler.gameState == GameState.Normal)
        {
            if (!playerInput.mouseOverMenu && Camera.main)
            {
                if (settingsManager.inputType == InputType.TouchScreen)
                {
                    if (playerInput.CanClick() && playerInput.buttonPressed == 1)
                    {
                        playerInput.ResetClick();

                        // Check Hotspots only when click/tap
                        Hotspot    newHotspot = null;
                        Ray        ray        = Camera.main.ScreenPointToRay(playerInput.mousePosition);
                        RaycastHit hit;

                        if (Physics.Raycast(ray, out hit, settingsManager.hotspotRaycastLength, 1 << LayerMask.NameToLayer("Default")))
                        {
                            newHotspot = hit.collider.gameObject.GetComponent <Hotspot>();
                        }

                        if (hotspot && !newHotspot)
                        {
                            hotspot.Deselect();
                            hotspot = null;
                        }
                        else if (newHotspot)
                        {
                            if (settingsManager.controlStyle != ControlStyle.PointAndClick && playerInput.dragStartPosition != Vector2.zero)
                            {
                                // Disable hotspots while dragging player
                                if (hotspot)
                                {
                                    hotspot.Deselect();
                                    hotspot = null;
                                }
                            }
                            else
                            {
                                if (newHotspot != hotspot)
                                {
                                    if (hotspot)
                                    {
                                        hotspot.Deselect();
                                    }

                                    hotspot = newHotspot;
                                    hotspot.Select();
                                }
                                else if (hotspot)
                                {
                                    playerInput.ResetClick();
                                    HandleInteraction();
                                }
                            }
                        }
                    }
                    else if (playerInput.buttonPressed == 2 && playerInput.CanClick())
                    {
                        playerInput.ResetClick();
                        HandleInteraction();
                    }
                    else if (playerInput.buttonPressed > 0 && !IsMouseOverHotspot() && runtimeInventory.selectedID > -1)
                    {
                        runtimeInventory.SetNull();
                    }
                }

                else
                {
                    // Mouse-over objects

                    Hotspot    newHotspot = null;
                    Ray        ray        = Camera.main.ScreenPointToRay(playerInput.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, settingsManager.hotspotRaycastLength, 1 << LayerMask.NameToLayer("Default")))
                    {
                        newHotspot = hit.collider.gameObject.GetComponent <Hotspot>();
                    }

                    if (hotspot && !newHotspot)
                    {
                        hotspot.Deselect();
                        hotspot = null;
                    }
                    else if (newHotspot && hotspot != newHotspot)
                    {
                        if (hotspot)
                        {
                            hotspot.Deselect();
                        }

                        hotspot = newHotspot;
                        hotspot.Select();
                    }

                    if (playerInput.buttonPressed == 1 && hotspot == null && runtimeInventory.selectedID > -1)
                    {
                        runtimeInventory.SetNull();
                    }

                    if (playerInput.CanClick() && playerInput.buttonPressed > 0 && hotspot)
                    {
                        playerInput.ResetClick();
                        HandleInteraction();
                    }
                }
            }
            else if (hotspot)
            {
                hotspot.Deselect();
                hotspot = null;
            }
        }
    }
예제 #2
0
    private void ReturnMainData()
    {
        Player           player           = GameObject.FindWithTag(Tags.player).GetComponent <Player>();
        PlayerInput      playerInput      = GameObject.FindWithTag(Tags.gameEngine).GetComponent <PlayerInput>();
        MainCamera       mainCamera       = GameObject.FindWithTag(Tags.mainCamera).GetComponent <MainCamera>();
        RuntimeInventory runtimeInventory = this.GetComponent <RuntimeInventory>();
        RuntimeVariables runtimeVariables = runtimeInventory.GetComponent <RuntimeVariables>();
        SceneChanger     sceneChanger     = this.GetComponent <SceneChanger>();

        if (player && playerInput && mainCamera && runtimeInventory && runtimeVariables)
        {
            sceneChanger.previousScene = saveData.mainData.previousScene;

            player.transform.position    = new Vector3(saveData.mainData.playerLocX, saveData.mainData.playerLocY, saveData.mainData.playerLocZ);
            player.transform.eulerAngles = new Vector3(0f, saveData.mainData.playerRotY, 0f);
            player.SetLookDirection(Vector3.zero, true);

            // Active path
            player.Halt();
            Paths savedPath = Serializer.returnComponent <Paths> (saveData.mainData.playerActivePath);
            if (savedPath)
            {
                player.SetLockedPath(savedPath);
            }

            // Active screen arrows
            playerInput.RemoveActiveArrows();
            ArrowPrompt loadedArrows = Serializer.returnComponent <ArrowPrompt> (saveData.mainData.playerActiveArrows);
            if (loadedArrows)
            {
                loadedArrows.TurnOn();
            }

            // Active conversation
            playerInput.activeConversation = Serializer.returnComponent <Conversation> (saveData.mainData.playerActiveConversation);

            playerInput.isUpLocked    = saveData.mainData.playerUpLock;
            playerInput.isDownLocked  = saveData.mainData.playerDownLock;
            playerInput.isLeftLocked  = saveData.mainData.playerLeftlock;
            playerInput.isRightLocked = saveData.mainData.playerRightLock;
            playerInput.runLock       = (PlayerMoveLock)saveData.mainData.playerRunLock;
            runtimeInventory.isLocked = saveData.mainData.playerInventoryLock;

            playerInput.timeScale = saveData.mainData.timeScale;

            mainCamera.SetGameCamera(Serializer.returnComponent <GameCamera> (saveData.mainData.gameCamera));
            mainCamera.transform.position    = new Vector3(saveData.mainData.mainCameraLocX, saveData.mainData.mainCameraLocY, saveData.mainData.mainCameraLocZ);
            mainCamera.transform.eulerAngles = new Vector3(saveData.mainData.mainCameraRotX, saveData.mainData.mainCameraRotY, saveData.mainData.mainCameraRotZ);
            if (mainCamera.attachedCamera)
            {
                mainCamera.attachedCamera.MoveCameraInstant();
            }
            else
            {
                Debug.LogWarning("MainCamera has no attached GameCamera");
            }

            // Inventory
            AssignInventory(runtimeInventory, saveData.mainData.inventoryData);
            if (saveData.mainData.selectedInventoryID > -1)
            {
                runtimeInventory.SelectItemByID(saveData.mainData.selectedInventoryID);
            }
            else
            {
                runtimeInventory.SetNull();
            }

            // Variables
            AssignVariables(runtimeVariables, saveData.mainData.variablesData);

            // StateHandler
            StateHandler stateHandler = runtimeInventory.GetComponent <StateHandler>();
            if (playerInput.activeConversation)
            {
                stateHandler.gameState = GameState.DialogOptions;
            }
            else
            {
                stateHandler.gameState = GameState.Normal;
            }

            // Fade in camera
            mainCamera.FadeIn(0.5f);

            playerInput.ResetClick();
        }
        else
        {
            if (player == null)
            {
                Debug.LogWarning("Load failed - no Player found.");
            }
            if (playerInput == null)
            {
                Debug.LogWarning("Load failed - no PlayerInput found.");
            }
            if (mainCamera == null)
            {
                Debug.LogWarning("Load failed - no MainCamera found.");
            }
            if (runtimeInventory == null)
            {
                Debug.LogWarning("Load failed - no RuntimeInventory found.");
            }
            if (runtimeVariables == null)
            {
                Debug.LogWarning("Load failed - no RuntimeVariables found.");
            }
            if (sceneChanger == null)
            {
                Debug.LogWarning("Load failed - no SceneChanger found.");
            }
        }
    }
예제 #3
0
    void FixedUpdate()
    {
        if (stateHandler && stateHandler.gameState == GameState.Normal)
        {
            if (buttonPressed == 2)
            {
                runtimeInventory.SetNull();
            }

            if (settingsManager && settingsManager.inputType != InputType.TouchScreen && activeArrows && (activeArrows.arrowPromptType == ArrowPromptType.KeyOnly || activeArrows.arrowPromptType == ArrowPromptType.KeyAndClick))
            {
                // Arrow Prompt is displayed: respond to movement keys
                if (Input.GetAxis("Vertical") > 0.1)
                {
                    activeArrows.DoUp();
                }

                else if (Input.GetAxis("Vertical") < -0.1)
                {
                    activeArrows.DoDown();
                }

                else if (Input.GetAxis("Horizontal") < -0.1)
                {
                    activeArrows.DoLeft();
                }

                else if (Input.GetAxis("Horizontal") > 0.1)
                {
                    activeArrows.DoRight();
                }
            }

            if (activeArrows && (activeArrows.arrowPromptType == ArrowPromptType.ClickOnly || activeArrows.arrowPromptType == ArrowPromptType.KeyAndClick))
            {
                // Arrow Prompt is displayed: respond to mouse clicks
                if (buttonPressed == 1)
                {
                    if (activeArrows.upArrow.rect.Contains(invertedMouse))
                    {
                        activeArrows.DoUp();
                    }

                    else if (activeArrows.downArrow.rect.Contains(invertedMouse))
                    {
                        activeArrows.DoDown();
                    }

                    else if (activeArrows.leftArrow.rect.Contains(invertedMouse))
                    {
                        activeArrows.DoLeft();
                    }

                    else if (activeArrows.rightArrow.rect.Contains(invertedMouse))
                    {
                        activeArrows.DoRight();
                    }
                }
            }

            else if (settingsManager.controlStyle != ControlStyle.PointAndClick)
            {
                float h = 0f;
                float v = 0f;
                bool  run;

                if (settingsManager.inputType != InputType.TouchScreen)
                {
                    h = Input.GetAxis("Horizontal");
                    v = Input.GetAxis("Vertical");
                }
                else
                {
                    h = dragVector.x;
                    v = -dragVector.y;
                }

                if ((isUpLocked && v > 0f) || (isDownLocked && v < 0f))
                {
                    v = 0f;
                }

                if ((isLeftLocked && h > 0f) || (isRightLocked && h < 0f))
                {
                    h = 0f;
                }

                if (runLock == PlayerMoveLock.Free)
                {
                    if (settingsManager.inputType == InputType.TouchScreen)
                    {
                        if (dragStartPosition != Vector2.zero && dragSpeed > settingsManager.dragRunThreshold * 10f)
                        {
                            run = true;
                        }
                        else
                        {
                            run = false;
                        }
                    }
                    else
                    {
                        try
                        {
                            run = Input.GetButton("Run");
                        }
                        catch
                        {
                            run = false;
                            Debug.LogWarning("No 'Run' button exists - please define one in the Input Manager.");
                        }
                    }
                }
                else if (runLock == PlayerMoveLock.AlwaysWalk)
                {
                    run = false;
                }
                else
                {
                    run = true;
                }

                isRunning = run;
                moveKeys  = new Vector2(h, v);
            }
        }
    }