示例#1
0
    public void Update()
    {
        // Set if the player clicked the left mouse button or not
        didClick = Input.GetMouseButtonDown(0);

        // Cast a ray from the camera to the current mouse position
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        // Create a variable to hold the ray hit
        RaycastHit hit;

        // Check if the ray hit anything and if it did run the logic
        if (Physics.Raycast(ray, out hit, 100f))
        {
            // Check if this object is what was hit AND if didClick is true
            if (hit.collider.gameObject == gameObject && didClick)
            {
                // If so check to see if the current action is use...
                if (action.canUse)
                {
                    // ... if it is check to see if an inventory item has been chosen to use
                    if (InventoryUseItem.instance.currentItem != null)
                    {
                        // ... if it has been use the item on this gameobject and set canUse to false
                        action.DoAction_Use(gameObject);

                        action.canUse = false;
                    }
                    else if (gameObject.name == "Cleared Tree")
                    {
                        action.UseSnakeTree();
                        action.canUse = false;
                    }
                }
                // Check if the current action is LookAt...
                else if (action.canLookAt)
                {
                    // ... if it is, Look at this gameObject
                    action.DoAction_LookAt(null, didClick);
                }
                // Check if the current action is Push...
                else if (action.canPush)
                {
                    // ... if it is Push this object if you can...
                    action.DoAction_Push();
                }
                // Check if the current action is Pull...
                else if (action.canPull)
                {
                    // ... if it is Pull this object if you can...
                    action.DoAction_Pull(hit.collider.gameObject);
                }
                // Check if the current action is Open...
                else if (action.canOpen)
                {
                    // ... if it is Open the object if you can...
                    action.DoAction_Open(currentItem);
                }
                else if (action.canClose)
                {
                    action.DoAction_Close(currentItem);
                }
                else if (action.canTalkTo)
                {
                    action.DoAction_TalkTo(hit.collider.gameObject);
                }
            }
        }
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        // Set didClick flag to true
        didClick = true;
        // Get the current Image on this inventory slot button
        Image thisSlot = GetComponent <Image>();
        // Get the instance of the UIActionManager
        UIActionManager actions = UIActionManager.instance;

        // Check if we're going to use an item and if we've selected an item from the inventory
        // to actually use.
        if (actions.canUse && assignedItem != null)
        {
            // Check the name of the item we are going to use and do the appropriate action
            // for that item.
            switch (assignedItem.name)
            {
            case "Whip":
                Cursor.SetCursor(whipCursor, Vector2.zero, CursorMode.Auto);
                InventoryUseItem.instance.currentItem = assignedItem;
                break;

            case "Kerosene Lamp":
                Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                if (assignedItem.isOpen)
                {
                    InventoryUseItem.instance.currentItem = assignedItem;
                    wasUsed = true;
                }
                else
                {
                    UpdateSprites(assignedItem);

                    indianaJones.TextUpdate("I think I need to open it first.");
                    indianaJones.isTextEnabled = true;
                    wasUsed = false;
                }
                break;

            case "Spiral Design":
                Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                InventoryUseItem.instance.currentItem = assignedItem;
                wasUsed = true;
                break;

            default:
                Debug.LogError("Something in switching the cursor went wrong!" + assignedItem);
                break;
            }

            // Set the assignedItem to null as we've either used it or put it back into the inventory
            //assignedItem = null;

            // Set the itemDefaultSprite and itemHighlightedSprite to null, as
            // we no longer have an item.
            //itemDefaultSprite = null;
            //itemHighlightedSprite = null;

            if (wasUsed)
            {
                UpdateSprites(null);
            }
        }
        else if (actions.canLookAt)
        {
            if (assignedItem != null)
            {
                actions.DoAction_LookAt(assignedItem, didClick);
            }
            else
            {
                if (InventoryUseItem.instance.currentItem != null)
                {
                    if (!assignedItem.isOpen)
                    {
                        InventoryUIManager.instance.OnInventoryUpdate(InventoryUseItem.instance.currentItem);
                        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                    }
                    else
                    {
                        UpdateSprites(assignedItem);
                    }
                }
                else
                {
                    indianaJones.TextUpdate("There's nothing to look at!");
                    indianaJones.isTextEnabled = true;
                }
            }
        }
        else if (actions.canOpen)
        {
            if (assignedItem != null)
            {
                actions.DoAction_Open(assignedItem);
                UpdateSprites(assignedItem);
            }
        }
        else if (actions.canClose)
        {
            if (assignedItem != null)
            {
                actions.DoAction_Close(assignedItem);
                UpdateSprites(assignedItem);
            }
        }
    }