예제 #1
0
    public void Update()
    {
        position = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
        dragging = IsDragging();

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            ObjectInformation info = hit.transform.GetComponent <ObjectInformation> ();
            if (info)
            {
                if (Input.GetMouseButtonUp(0) && info.item.type != ItemType.Deployer)
                {
                    player.AddToInventory(info.item, info.item.count);
                    info.item.DestroyWorldObject();
                }
                else if (Input.GetMouseButtonUp(1))
                {
                    RightClickMenu rcm = transform.gameObject.AddComponent <RightClickMenu> ();
                    rcm.Init(info.item, WindowType.WorldObject);
                    print(info.item.type.ToString());
                }
            }
        }
    }
예제 #2
0
    void WindowFunction(int windowID)
    {
        int x = 0, y = 0;

        //for each item in inventory
        foreach (Item item in player.inventory_items)
        {
            //index position of the item : add to y
            if (x >= width)
            {
                x -= width;
                y++;
            }
            if (!item.nullified)
            {
                if (item.type != ItemType.Null)
                {
                    //default button : used with all items : add window top border
                    Vector2 position = new Vector2((button_size + button_margin) * x + button_margin, (button_size + button_margin) * y + skin.window.border.top + button_margin),
                            size     = new Vector2(button_size, button_size);
                    Rect button      = new Rect(position, size);

                    //item button
                    if (GUI.Button(button, item.texture))
                    {
                        //Left clicked the item
                        if (Event.current.button == 0 && item.equip_location != null)                          //left clicked

                        //equip to the first equip_location

                        {
                            player.Equip(item, item.equip_location [0]);
                            return;

                            //Right clicked the item
                        }
                        else if (Event.current.button == 1)
                        {
                            //add right click menu to the player object as a script
                            RightClickMenu rcm = transform.gameObject.AddComponent <RightClickMenu> ();
                            rcm.Init(item, WindowType.Inventory);
                        }
                    }
                    if (item.stackable)
                    {
                        GUI.Label(button, item.count.ToString());
                    }
                }
            }
            x++;
        }
    }
예제 #3
0
    void WindowFunction(int windowID)
    {
        int index = 0;

        foreach (Rect r in slots)
        {
            GUI.Box(r, "");

            if (player.equipment_items [index] != null)
            {
                if (player.equipment_items [index].type != ItemType.Null)
                {
                    if (player.equipment_items [index] != null)
                    {
                        Item    item = player.equipment_items [index];
                        Vector2 position;
                        Rect    button;

                        button = slots [index];

                        if (GUI.Button(button, item.texture))
                        {
                            if (Input.GetMouseButtonUp(0))
                            {
                                player.Unequip(item);
                            }
                            else if (Input.GetMouseButtonUp(1))
                            {
                                RightClickMenu rcm = transform.gameObject.AddComponent <RightClickMenu> ();
                                rcm.Init(item, WindowType.Equipment);
                            }
                        }
                    }
                }
            }
            index++;
        }
    }