Наследование: MonoBehaviour
Пример #1
0
    public void StartUp(UI_Inventory uI_Inventory, Item item)
    {
        ui        = uI_Inventory;
        this.item = item;

        uIRectTransform = uI_Inventory.GetComponent <RectTransform>();
    }
Пример #2
0
    public void CloseUI()
    {
        UI_Popup LastPopUp = Managers.UI.PeekUI();

        if (LastPopUp != null)
        {
            string temp = LastPopUp.PopUpName();
            if (LastPopUp.ClosePopupUI())
            {
                if (temp == "Inven")
                {
                    _Inven = null;
                }
                else if (temp == "Equip")
                {
                    _Equip = null;
                }

                else if (temp == "SkillTree")
                {
                    _SkillTree = null;
                }
            }
        }
    }
Пример #3
0
 public void transfer(UI_Inventory toTransfer)
 {
     this.AddInventory(toTransfer.GetInventory());
     this.RefreshInventoryItems();
     toTransfer.GetInventory().ClearItemList();
     toTransfer.RefreshInventoryItems();
 }
    private void GetUIKeyInput()
    {
        if (Input.GetKeyDown(KeyCode.I))
        {
            UI_GameScene gameSceneUI = Managers.UI.SceneUI as UI_GameScene;
            UI_Inventory invenUI     = gameSceneUI.InvenUI;

            if (invenUI.gameObject.activeSelf)
            {
                invenUI.gameObject.SetActive(false);
            }
            else
            {
                invenUI.gameObject.SetActive(true);
                invenUI.RefreshUI();
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            UI_GameScene gameSceneUI = Managers.UI.SceneUI as UI_GameScene;
            UI_Stat      statUI      = gameSceneUI.StatUi;

            if (statUI.gameObject.activeSelf)
            {
                statUI.gameObject.SetActive(false);
            }
            else
            {
                statUI.gameObject.SetActive(true);
                statUI.RefreshUI();
            }
        }
    }
Пример #5
0
    public void AddUI(UI_Inventory uI)
    {
        if (uI is UI_TogglableInventory)
        {
            togglableUIs.Add(uI.gameObject);
        }

        inventoryUIs.Add(uI);
    }
Пример #6
0
 private void Awake()
 {
     uiInventory = FindObjectOfType <UI_Inventory>();
     if (inventory == null)
     {
         Debug.Log("making new inventory");
         inventory = new Inventory();
     }
 }
    private void Awake()
    {
        inventory   = new Inventory(UseItem);
        uiInventory = (UI_Inventory)FindObjectOfType(typeof(UI_Inventory));
        uiInventory.SetPlayer(this);
        uiInventory.SetInventory(inventory);

        //How to spawn stuff in the world
        //ItemWorld.SpawnItemWorld(new Vector3(0, 0), new Item { itemType = Item.ItemType.LogWorld, amount = 2 });
    }
Пример #8
0
    public override void Init()
    {
        base.Init();

        InvenUI = GetComponentInChildren<UI_Inventory>();
        StatUI = GetComponentInChildren<UI_Stat>();

        InvenUI.gameObject.SetActive(false);
        StatUI.gameObject.SetActive(false);
    }
Пример #9
0
 public static void InventoryClick(UI_Inventory ui, InventoriesController invController)
 {
     if (ui.isHovering && ui.hoverSlot != null && ui.hoverSlot.item != null && (invController.activeItem == null || invController.activeItem.itemType == ItemType.Empty))
     {
         Pickup(ui, invController, ui.hoverSlot.item.amount);
     }
     else
     {
         Drag(ui, invController);
     }
 }
Пример #10
0
    private void Awake()
    {
        inventory   = new Inventory(UseItem);
        uiInventory = (UI_Inventory)FindObjectOfType(typeof(UI_Inventory));
        uiInventory.SetPlayer(this);
        uiInventory.SetInventory(inventory);

        /*  ItemWorld.SpawnItemWorld(new Vector3(0, 0), new Item { itemType = Item.ItemType.LogWorld, amount = 2 });
         * ItemWorld.SpawnItemWorld(new Vector3(3, 4), new Item { itemType = Item.ItemType.StickWorld, amount = 5 });
         * ItemWorld.SpawnItemWorld(new Vector3(-2, -2), new Item { itemType = Item.ItemType.WoodenAxeWorld, amount = 1 });
         */
    }
Пример #11
0
    void Start()
    {
        ui_Inventory = FindObjectOfType <UI_Inventory>();

        item = new Item {
            itemType = thisItemType, amount = 1, maxStack = maxStack
        };

        currentSprite = this.GetComponent <SpriteRenderer>().sprite;

        StartCoroutine(waitBeforeSetPickupBool());
    }
Пример #12
0
    public static void Drop(UI_Inventory ui, int count)
    {
        if (ui.isHovering && ui.hoverSlot.item != null)
        {
            var tempItem = new Item {
                itemType = ui.hoverSlot.item.itemType, amount = count
            };

            ui.inventory.DropItem(tempItem);
            ui.inventory.RemoveItem(ui.hoverSlot.index, count);
        }
    }
Пример #13
0
    protected override void Awake()
    {
        base.Awake();

        if (Inventory)
        {
            ParentInventory = GetComponentInParent <UI_Inventory>();
            if (!ParentInventory)
            {
                Debug.LogError("UI_InventorySlot: inventory class component is null");
            }
        }
    }
Пример #14
0
    void Awake()
    {
        inv          = inventoryGO.GetComponent <UI_Inventory>();
        itemList     = inventoryGO.GetComponent <UI_ItemsList>();
        eventManager = inventoryGO.GetComponent <UI_EventManager>();
        hotbar       = inventoryGO.GetComponent <UI_Hotbar>();

        if (playerEquipGO == null)
        {
            playerEquipGO = GameObject.Find("PlayerEquipment");
        }
        playerEquipment = playerEquipGO.GetComponent <UI_PlayerEquipment>();
    }
Пример #15
0
 public void ShowInventory()
 {
     if (_Inven == null)
     {
         _Inven = Managers.UI.ShowPopupUI <UI_Inventory>("UI_Inven");
     }
     else
     {
         if (_Inven.ClosePopupUI())
         {
             _Inven = null;
         }
     }
 }
Пример #16
0
 void Awake()
 {
     inventoryGO  = GameObject.Find("Ultimate Inventory Pro");
     inv          = inventoryGO.GetComponent <UI_Inventory>();
     itemList     = inventoryGO.GetComponent <UI_ItemsList>();
     eventManager = inventoryGO.GetComponent <UI_EventManager>();
     hotbar       = inventoryGO.GetComponent <UI_Hotbar>();
     if (playerEquipGO == null)
     {
         playerEquipGO = GameObject.Find("PlayerEquipment");
     }
     playerEquipment = playerEquipGO.GetComponent <UI_PlayerEquipment>();
     conScript       = container.GetComponent <UI_Container>();
 }
Пример #17
0
 void Awake()
 {
     inv       = GetComponent <UI_Inventory>();
     itemsList = GetComponent <UI_ItemsList>();
     htbar     = GetComponent <UI_Hotbar>();
     GameObject[] allGO = GameObject.FindObjectsOfType <GameObject>();
     foreach (GameObject obj in allGO)
     {
         if (obj.GetComponent <UI_Container>() != null)
         {
             containers.Add(obj);
         }
     }
 }
Пример #18
0
    private static void PutDown(UI_Inventory ui, InventoriesController invController)
    {
        if (ui.isHovering && invController.activeItem != null && invController.activeItem.itemType != ItemType.Empty)
        {
            // place
            if (ui.hoverSlot.item == null)
            {
                ui.inventory.SetItem(invController.activeItem, ui.hoverSlot.index);
                invController.DestroyActive();
            }
            else
            {
                var tempItem = ui.hoverSlot.item;

                // combine
                if (tempItem.itemType == invController.activeItem.itemType)
                {
                    var totalAmount = tempItem.amount + invController.activeItem.amount;

                    if (totalAmount <= Item.MaxAmount)
                    {
                        ui.inventory.SetItem(new Item {
                            itemType = tempItem.itemType, amount = totalAmount
                        }, ui.hoverSlot.index);
                        invController.DestroyActive();
                    }
                    else
                    {
                        ui.inventory.SetItem(new Item {
                            itemType = tempItem.itemType, amount = Item.MaxAmount
                        }, ui.hoverSlot.index);
                        invController.activeItem = new Item {
                            itemType = tempItem.itemType, amount = totalAmount - Item.MaxAmount
                        };
                        invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
                    }
                }
                // switch
                else
                {
                    ui.inventory.SetItem(invController.activeItem, ui.hoverSlot.index);
                    invController.activeItem = new Item {
                        itemType = tempItem.itemType, amount = tempItem.amount
                    };
                    invController.activeTransform.GetComponent <Image>().sprite = invController.activeItem.GetSprite();
                    invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
                }
            }
        }
    }
Пример #19
0
    private static void Drag(UI_Inventory ui, InventoriesController invController)
    {
        if (invController.slotList.Count > 1)
        {
            var itemsPerSlot = invController.activeItem.amount / invController.slotList.Count;
            var itemsHeld    = invController.activeItem.amount % invController.slotList.Count;

            foreach (var slot in invController.slotList)
            {
                if (slot.item != null)
                {
                    var totalAmount = slot.item.amount + itemsPerSlot;
                    if (totalAmount > Item.MaxAmount)
                    {
                        slot.ui.inventory.SetItem(new Item {
                            itemType = invController.activeItem.itemType, amount = Item.MaxAmount
                        }, slot.index);
                        itemsHeld += totalAmount - Item.MaxAmount;
                    }
                    else
                    {
                        slot.ui.inventory.SetItem(new Item {
                            itemType = invController.activeItem.itemType, amount = totalAmount
                        }, slot.index);
                    }
                }
                else
                {
                    slot.ui.inventory.SetItem(new Item {
                        itemType = invController.activeItem.itemType, amount = itemsPerSlot
                    }, slot.index);
                }
            }

            if (itemsHeld == 0)
            {
                invController.DestroyActive();
            }
            else
            {
                invController.activeItem.amount = itemsHeld;
                invController.activeTransform.Find("Amount").GetComponent <TextMeshProUGUI>().text = invController.activeItem.amount.ToString();
            }
        }
        else
        {
            PutDown(ui, invController);
        }
    }
Пример #20
0
 public Shop_Inventory()
 {
     player          = GameObject.Find("Player").GetComponent <Player> ();
     playerInventory = GameObject.Find("Inventory").GetComponent <UI_Inventory> ();
     itemList        = new List <Item> ();
     addItem(new Item {
         itemType = Item.ItemType.woodPickaxe, amount = 1
     });
     addItem(new Item {
         itemType = Item.ItemType.woodShovel, amount = 1
     });
     addItem(new Item {
         itemType = Item.ItemType.woodSword, amount = 1
     });
 }
Пример #21
0
 private static void Pickup(UI_Inventory ui, InventoriesController invController, int count)
 {
     if (!ui.isHovering ||
         (invController.activeItem != null && invController.activeItem.itemType != ItemType.Empty))
     {
         return;
     }
     if (ui.hoverSlot.item != null)
     {
         invController.activeItem = new Item {
             itemType = ui.hoverSlot.item.itemType, amount = count
         };
         ui.inventory.RemoveItem(ui.hoverSlot.index, count);
         invController.CreateActiveItem();
     }
 }
Пример #22
0
 public static void Hover(UI_Inventory ui)
 {
     ui.hoverSlot  = null;
     ui.isHovering = false;
     foreach (var itemSlot in from itemSlot in ui.slotList
              let mousePos = itemSlot.transform.InverseTransformPoint(Input.mousePosition)
                             where itemSlot.rectTransform && itemSlot.rectTransform.rect.Contains(mousePos)
                             select itemSlot)
     {
         ui.hoverSlot  = itemSlot;
         ui.isHovering = true;
         break;
     }
     if (!ui.isHovering)
     {
         ui.hoverSlot = null;
     }
 }
Пример #23
0
    public static void Split(UI_Inventory ui, InventoriesController invController)
    {
        if (ui.isHovering && ui.hoverSlot.item != null)
        {
            int amount;

            if (ui.hoverSlot.item.amount > 1 && ui.hoverSlot.item.IsStackable())
            {
                amount = ui.hoverSlot.item.amount / 2;
            }
            else
            {
                amount = 1;
            }

            Pickup(ui, invController, amount);
        }
    }
Пример #24
0
    public static void SelectSlot(UI_Inventory ui, InventoriesController invController)
    {
        if (invController.activeItem != null && ui.isHovering && !invController.slotList.Contains(ui.hoverSlot))
        {
            foreach (var slot in invController.slotList)
            {
                if (slot.index == ui.hoverSlot.index)
                {
                    return;
                }
            }

            if ((ui.hoverSlot.item == null || ((invController.activeItem != null || invController.activeItem.itemType != ItemType.Empty) && invController.activeItem.itemType == ui.hoverSlot.item.itemType && ui.hoverSlot.item.amount < Item.MaxAmount)) &&
                invController.slotList.Count < invController.activeItem.amount)
            {
                invController.slotList.Add(ui.hoverSlot);
                ui.hoverSlot.SetSelectedColor();
            }
        }
    }
Пример #25
0
    public void AddToInventory(GameObject item)
    {
        UI_Inventory ui_inv = new UI_Inventory();

        ui_inv.name     = item.name;
        ui_inv.inv_icon = item.GetComponent <Image>();
        inventory_dict.Add(ui_inv.name, ui_inv);

        yarn_variables.SetValue(item.GetComponent <PickUp>().yarn_var, true);


        //GameObject g = new GameObject();


        //g.AddComponent(typeof(Image));
        //g.name = ui_inv.name;
        //g.GetComponent<Image>().sprite = ui_inv.inv_icon.sprite;


        //GameObject b =  Instantiate(g);
        //b.transform.parent = inv_ui.transform;
        //b.GetComponent<Image>().color = ui_inv.inv_icon.color;
        // b.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 0);
    }
Пример #26
0
 void Start()
 {
     inventory   = new Inventory();
     uiInventory = GameObject.Find("Inventory").GetComponent <UI_Inventory>();
     uiInventory.SetInventory(inventory);
 }
Пример #27
0
 public static void DisplayInfo(UI_Inventory ui, Transform itemInfo, TextMeshProUGUI nameText, TextMeshProUGUI amountText)
 {
     itemInfo.position = Input.mousePosition + offset;
     nameText.text     = "Name: " + ui.hoverSlot.item.itemType;
     amountText.text   = "Amount: " + ui.hoverSlot.item.amount + "/" + Item.MaxAmount;
 }
Пример #28
0
 private void Awake()
 {
     uI_Inventory = GetComponentInParent<UI_Inventory>();
     uI_SelectionMark = uI_Inventory.GetUISelectionFrame();
 }
Пример #29
0
    private void ShowText(string text)
    {
        string text_tmp = text;

        Debug.Log("Showing TEXT of item description");

        text_window.SetActive(true);

        // Clear all children
        for(int index_child = scroll_contentRect.childCount - 1; index_child > -1; --index_child)
        {
            Destroy(scroll_contentRect.GetChild(index_child).gameObject);
        }

        // Split the string on newlines
        Text instance;
        while (text_tmp.Length > LongStringSecretSplitter.MaxStringCharacters)
        {
            int index_newline = text_tmp.LastIndexOf
            (
                '\n',
                LongStringSecretSplitter.MaxStringCharacters - 1,
                LongStringSecretSplitter.MaxStringCharacters
            );

            string sub_text = text_tmp.Substring(0, index_newline + 1);
            text_tmp = text_tmp.Remove(0, index_newline + 1);

            instance = Instantiate(text_content_element);
            instance.transform.SetParent(scroll_contentRect, false); //move to element holder

            instance.text = sub_text;
        }

        instance = Instantiate(text_content_element);
        instance.transform.SetParent(scroll_contentRect, false); //move to element holder

        instance.text = text_tmp;

        scroll_contentRect.parent.GetComponent<ScrollRect>().normalizedPosition = new Vector2(0,1);
    }
Пример #30
0
 void OnDestroy()
 {
     if (instance == this)
     {
         instance = null;
         player_data_loaded = false;
         is_inventory_setup = false;
         shop_list_current = null;
     }
 }
Пример #31
0
 void Awake()
 {
     instance = this;
 }
Пример #32
0
 // Use this for initialization
 void Start()
 {
     inventoryCanvas = GetComponent <UI_Inventory>();
     uiStats         = GetComponent <UI_Stats>();
     uiMessages      = GetComponent <UI_Messages>();
 }
Пример #33
0
 void Awake()
 {
     instance = this;
 }