예제 #1
0
    void Update()
    {
        inventory = GetComponent <ScriptManager>().GetScript <Inventory>();

        if (inputManager.HasInputs())
        {
            UseKey    = inputManager.GetInput("Use");
            PickupKey = inputManager.GetInput("Pickup").ToString();
        }

        if (Input.GetKey(UseKey) && RaycastObject && !isPressed && !isHeld && !inUse)
        {
            Interact();
            isPressed = true;
        }

        if (Input.GetKeyUp(UseKey) && isPressed)
        {
            isPressed = false;
        }

        Ray        playerAim = playerCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        if (Physics.Raycast(playerAim, out hit, RayLength, cullLayers))
        {
            RaycastTag = hit.collider.gameObject.tag;
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
            {
                RaycastObject = hit.collider.gameObject;
                correctLayer  = true;

                if (RaycastObject.GetComponent <DynamicObject>())
                {
                    dynamic = RaycastObject.GetComponent <DynamicObject>();
                }
                else
                {
                    dynamic = null;
                }

                if (RaycastObject.GetComponent <CrosshairReticle>())
                {
                    CrosshairReticle ChangeReticle = RaycastObject.GetComponent <CrosshairReticle>();
                    if (dynamic)
                    {
                        if (dynamic.useType != DynamicObject.type.Locked)
                        {
                            interactCrosshair = ChangeReticle.interactSprite;
                            interactSize      = ChangeReticle.size;
                        }
                    }
                    else
                    {
                        interactCrosshair = ChangeReticle.interactSprite;
                        interactSize      = ChangeReticle.size;
                    }
                }

                useTexture = true;

                if (LastRaycastObject)
                {
                    if (!(LastRaycastObject == RaycastObject))
                    {
                        ResetCrosshair();
                    }
                }
                LastRaycastObject = RaycastObject;

                if (!inUse)
                {
                    if (dynamic)
                    {
                        if (dynamic.useType == DynamicObject.type.Locked)
                        {
                            if (dynamic.CheckHasKey())
                            {
                                gameManager.ShowInteractSprite(1, UnlockText, UseKey.ToString());
                            }
                            else
                            {
                                gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                            }
                        }
                        else
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                        }
                    }
                    else
                    {
                        if (RaycastObject.GetComponent <DynamicObjectPlank>())
                        {
                            gameManager.ShowInteractSprite(1, RemoveText, UseKey.ToString());
                        }
                        else if (!(RaycastTag == "OnlyGrab"))
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                        }
                    }
                    if (RaycastTag == "OnlyGrab")
                    {
                        gameManager.ShowInteractSprite(1, GrabText, PickupKey);
                    }
                    else if (RaycastTag == "Grab")
                    {
                        gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                        gameManager.ShowInteractSprite(2, GrabText, PickupKey);
                    }
                    else if (RaycastTag == "Paper")
                    {
                        gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                    }
                    if (RaycastObject.GetComponent <ExamineItem>())
                    {
                        if (RaycastObject.GetComponent <ExamineItem>().isUsable)
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey.ToString());
                            gameManager.ShowInteractSprite(2, ExamineText, PickupKey);
                        }
                        else
                        {
                            gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                        }
                    }
                }
            }
            else if (RaycastObject)
            {
                correctLayer = false;
            }
        }
        else if (RaycastObject)
        {
            correctLayer = false;
        }

        if (!correctLayer)
        {
            ResetCrosshair();
            useTexture    = false;
            RaycastTag    = null;
            RaycastObject = null;
            dynamic       = null;
        }

        if (!RaycastObject)
        {
            gameManager.HideSprites(spriteType.Interact);
            useTexture = false;
            dynamic    = null;
        }

        CrosshairUpdate();
    }
예제 #2
0
    void Update()
    {
        inventory = GetComponent <ScriptManager>().GetScript <Inventory>();

        if (inputManager.HasInputs())
        {
            UseKey    = inputManager.GetInput("Use");
            PickupKey = inputManager.GetInput("Pickup");
        }

        if (Input.GetKey(UseKey) && RaycastObject && !isPressed && !isHeld && !inUse)
        {
            Interact(RaycastObject);
            isPressed = true;
        }

        if (Input.GetKeyUp(UseKey) && isPressed)
        {
            isPressed = false;
        }

        Ray playerAim = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

        if (Physics.Raycast(playerAim, out RaycastHit hit, RaycastRange, cullLayers))
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer(InteractLayer))
            {
                if (hit.collider.gameObject != RaycastObject)
                {
                    gameManager.HideSprites(hideType.Interact);
                }

                RaycastObject = hit.collider.gameObject;
                RaycastTag    = hit.collider.tag;
                correctLayer  = true;

                if (RaycastObject.GetComponent <InteractiveItem>())
                {
                    interactItem = RaycastObject.GetComponent <InteractiveItem>();
                }
                else
                {
                    interactItem = null;
                }

                if (RaycastObject.GetComponent <DynamicObject>())
                {
                    dynamicObj = RaycastObject.GetComponent <DynamicObject>();
                }
                else
                {
                    dynamicObj = null;
                }

                if (RaycastObject.GetComponent <UIObjectInfo>())
                {
                    objectInfo = RaycastObject.GetComponent <UIObjectInfo>();
                }
                else
                {
                    objectInfo = null;
                }

                if (RaycastObject.GetComponent <CrosshairReticle>())
                {
                    CrosshairReticle ChangeReticle = RaycastObject.GetComponent <CrosshairReticle>();
                    if (dynamicObj)
                    {
                        if (dynamicObj.useType != Type_Use.Locked)
                        {
                            interactCrosshair = ChangeReticle.interactSprite;
                            interactSize      = ChangeReticle.size;
                        }
                    }
                    else
                    {
                        interactCrosshair = ChangeReticle.interactSprite;
                        interactSize      = ChangeReticle.size;
                    }
                }

                if (LastRaycastObject)
                {
                    if (!(LastRaycastObject == RaycastObject))
                    {
                        ResetCrosshair();
                    }
                }
                LastRaycastObject = RaycastObject;

                if (objectInfo && !string.IsNullOrEmpty(objectInfo.objectTitle))
                {
                    gameManager.ShowInteractInfo(objectInfo.objectTitle);
                }

                if (!inUse)
                {
                    if (dynamicObj)
                    {
                        if (dynamicObj.useType == Type_Use.Locked)
                        {
                            if (dynamicObj.CheckHasKey())
                            {
                                gameManager.ShowInteractSprite(1, UnlockText, UseKey);
                            }
                            else
                            {
                                if (dynamicObj.interactType == Type_Interact.Mouse)
                                {
                                    gameManager.ShowInteractSprite(1, DragText, UseKey);
                                }
                                else
                                {
                                    gameManager.ShowInteractSprite(1, UseText, UseKey);
                                }
                            }
                        }
                        else
                        {
                            if (dynamicObj.interactType == Type_Interact.Mouse)
                            {
                                gameManager.ShowInteractSprite(1, DragText, UseKey);
                            }
                            else
                            {
                                gameManager.ShowInteractSprite(1, UseText, UseKey);
                            }
                        }
                    }
                    else
                    {
                        if (interactItem)
                        {
                            if (interactItem.showItemName && !string.IsNullOrEmpty(interactItem.ItemName))
                            {
                                gameManager.ShowInteractInfo(interactItem.ItemName);
                            }

                            if (RaycastTag != "GrabUse")
                            {
                                if (interactItem.ItemType == InteractiveItem.Type.OnlyExamine)
                                {
                                    gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                                }
                                else if (interactItem.ItemType == InteractiveItem.Type.InteractObject)
                                {
                                    if (interactItem.examineType != InteractiveItem.ExamineType.None)
                                    {
                                        gameManager.ShowInteractSprite(1, UseText, UseKey);
                                        gameManager.ShowInteractSprite(2, ExamineText, PickupKey);
                                    }
                                    else
                                    {
                                        gameManager.ShowInteractSprite(1, UseText, UseKey);
                                    }
                                }
                                else if (interactItem.examineType != InteractiveItem.ExamineType.None && interactItem.ItemType != InteractiveItem.Type.InteractObject)
                                {
                                    gameManager.ShowInteractSprite(1, TakeText, UseKey);
                                    gameManager.ShowInteractSprite(2, ExamineText, PickupKey);
                                }
                                else if (interactItem.examineType == InteractiveItem.ExamineType.Paper)
                                {
                                    gameManager.ShowInteractSprite(1, ExamineText, PickupKey);
                                }
                                else
                                {
                                    gameManager.ShowInteractSprite(1, TakeText, UseKey);
                                }
                            }
                            else
                            {
                                if (interactItem.ItemType != InteractiveItem.Type.OnlyExamine)
                                {
                                    gameManager.ShowInteractSprite(1, TakeText, UseKey);
                                    gameManager.ShowInteractSprite(2, GrabText, PickupKey);
                                }
                            }
                        }
                        else if (RaycastObject.GetComponent <DynamicObjectPlank>())
                        {
                            gameManager.ShowInteractSprite(1, RemoveText, UseKey);
                        }
                        else if (RaycastTag == "Grab")
                        {
                            gameManager.ShowInteractSprite(1, GrabText, PickupKey);
                        }
                        else if (objectInfo)
                        {
                            gameManager.ShowInteractSprite(1, objectInfo.useText, UseKey);
                        }
                        else
                        {
                            gameManager.ShowInteractSprite(1, UseText, UseKey);
                        }
                    }
                }

                CrosshairChange(true);
            }
            else if (RaycastObject)
            {
                correctLayer = false;
            }
        }