// Start is called before the first frame update
    void Start()
    {
        gameManager = GameObject.FindGameObjectWithTag("GameController");
        canvas      = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Canvas"));
        text        = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Text"));
        text.transform.SetParent(canvas.transform);
        text.GetComponent <RectTransform>().localPosition = new Vector3(0, 0, 0);
        selectionImage = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/selectionImage"));
        selectionImage.transform.SetParent(canvas.transform);
        selectionImage.GetComponent <RectTransform>().localPosition = new Vector3(0, 0, 0);

        GameObject.FindGameObjectWithTag("Canvas").GetComponent <UserInterface>().Init(this);
        cursorHandler = GameObject.FindGameObjectWithTag("UnderCursorDisplay").GetComponent <UnderCursorDisplay>();
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        UnderCursorDisplay cursorHandler = root.underCursorDisplay.GetComponent <UnderCursorDisplay>();

        if (eventData.button == PointerEventData.InputButton.Left)
        {
            if (targetInventory.Get(index) != null)
            {
                if (cursorHandler.heldItem == null)
                {
                    cursorHandler.heldItem = targetInventory.Get(index);
                    targetInventory.Add(null, index);
                }
                else
                {
                    cursorHandler.heldItem = targetInventory.Add(cursorHandler.heldItem, index);
                }
            }
            else
            {
                if (cursorHandler.heldItem != null)
                {
                    cursorHandler.heldItem = targetInventory.Add(cursorHandler.heldItem, index);
                }
            }
        }
        else if (eventData.button == PointerEventData.InputButton.Right)
        {
            if (cursorHandler.heldItem != null)
            {
                if (root.isInventoryShown)
                {
                    root.ToggleInventory();
                }
            }
            else
            {
                if (root.isInventoryShown)
                {
                    root.ToggleInventory();
                }
                if (targetInventory.Get(index) != null)
                {
                    targetInventory.Get(index).UseFromInventory(root.player, targetInventory, index);
                }
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        mainCamera.GetComponent <MainCamera>().player = gameObject;
        transform.position = new Vector3(transform.position.x, transform.position.y, -1);

        Item bumbel;

        bumbel        = new Item();
        bumbel.itemId = 0;
        backpack.Add(bumbel);

        bumbel        = new Item();
        bumbel.itemId = 1;
        backpack.Add(bumbel);

        bumbel        = new Item();
        bumbel.itemId = 2;
        backpack.Add(bumbel, 2);

        GameObject.FindGameObjectWithTag("Canvas").GetComponent <UserInterface>().Init(this);
        cursorHandler = GameObject.FindGameObjectWithTag("UnderCursorDisplay").GetComponent <UnderCursorDisplay>();
    }
    void DefinePrototypes()
    {
        ItemPrototype bumbel;


        bumbel                      = new ItemPrototype();
        bumbel.name                 = "Oil";
        bumbel.iconIndex            = 0;
        bumbel.maxStackCount        = 10;
        bumbel.craftable            = true;
        bumbel.consumptionBehaviour = ConsumptionBehaviour.consumable;
        bumbel.Use                  = (Player p, Inventory container, int index) => {
            Debug.Log(p.backpack.maxSize);
        };
        prototypes.Add(bumbel);

        bumbel                      = new ItemPrototype();
        bumbel.name                 = "Wood";
        bumbel.iconIndex            = 1;
        bumbel.maxStackCount        = 10;
        bumbel.craftable            = true;
        bumbel.consumptionBehaviour = ConsumptionBehaviour.consumable;
        bumbel.Use                  = (Player p, Inventory container, int index) => {
            Debug.Log("USED WOOD");
        };
        prototypes.Add(bumbel);

        bumbel                      = new ItemPrototype();
        bumbel.name                 = "Campfire Schematic";
        bumbel.iconIndex            = 6;
        bumbel.maxStackCount        = 10;
        bumbel.craftable            = true;
        bumbel.consumptionBehaviour = ConsumptionBehaviour.consumable;
        bumbel.Use                  = (Player p, Inventory container, int index) => {
            UnderCursorDisplay underCursorDisplay = GameObject.FindGameObjectWithTag("UnderCursorDisplay").GetComponent <UnderCursorDisplay>();
            underCursorDisplay.itemUsedFromInventory = container;
            underCursorDisplay.itemUsedFromIndex     = index;
            underCursorDisplay.structure             = structurePrototypes[0];
            container.Get(index).inUse = true;
        };
        bumbel.Callback = (Player p, Inventory container, int index, bool successFlag) => {
            UnderCursorDisplay cursorHandler = GameObject.FindGameObjectWithTag("UnderCursorDisplay").GetComponent <UnderCursorDisplay>();
            container.Get(index).inUse          = false;
            cursorHandler.itemUsedFromInventory = null;
            cursorHandler.itemUsedFromIndex     = -1;
            if (successFlag)
            {
                GameObject construction     = Instantiate(Resources.Load <GameObject>("Prefabs/firepit"));
                Camera     mainCamera       = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
                Vector3    mouseCoordinates = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, mainCamera.nearClipPlane));
                mouseCoordinates.x = Mathf.Round(mouseCoordinates.x * 2) / 2f;
                mouseCoordinates.y = Mathf.Round(mouseCoordinates.y * 2) / 2f;
                construction.transform.position = new Vector3(mouseCoordinates.x, mouseCoordinates.y, -0.5f);
                cursorHandler.structure         = null;

                container.Get(index).Decrement(container, index);
            }
            else
            {
                cursorHandler.structure = null;
            }
        };
        prototypes.Add(bumbel);



        StructurePrototype structurePrototype;

        structurePrototype        = new StructurePrototype();
        structurePrototype.sprite = Resources.Load <Sprite>("Sprites/firepit");
        structurePrototype.size   = 2;
        structurePrototype.name   = "firepit";
        structurePrototypes.Add(structurePrototype);
    }