Ejemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D col)
    {
        if (this.enabled)
        {
            Item_Component item = col.GetComponent <Item_Component>();

            pickUp.PickedUp(item);
        }
    }
Ejemplo n.º 2
0
    private void FixedUpdate()
    {
        Collider2D[] col = Physics2D.OverlapCircleAll(transform.position, pickUpRadius, mask);

        foreach (Collider2D c in col)
        {
            if (c.GetComponent <Item_Component>())
            {
                //here we update to inventory Ui
                Item_Component item = c.transform.gameObject.GetComponent <Item_Component>();
                pickUp.PickedUp(item);
            }
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("q"))
        {
            Vector3 mosPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mosPos.z = 0;

            GameObject     clone = Instantiate(obj, mosPos, Quaternion.identity);
            Item_Component item  = clone.GetComponent <Item_Component>();

            item.itemType = items.container[Random.Range(0, items.container.Count)].item;

            if (item.itemType.type != ItemType.Equipable && item.itemType.type != ItemType.Permanent)
            {
                item.amount = Random.Range(1, 10);
            }
        }
    }
Ejemplo n.º 4
0
    private void FixedUpdate()
    {
        posInDirection = ((Vector2)transform.position) + (directionInput * distance);
        if (directionInput != Vector2.zero)
        {
            Collider2D[] col = Physics2D.OverlapCircleAll(posInDirection, pickUpRadius, mask);

            foreach (Collider2D c in col)
            {
                if (c.GetComponent <Item_Component>())
                {
                    //here we update to inventory Ui

                    Item_Component item = c.transform.gameObject.GetComponent <Item_Component>();
                    pickUp.PickedUp(item);
                }
            }
        }
    }
Ejemplo n.º 5
0
    void GetItem()
    {
        RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.up, 1, mask);

        if (hit.collider != null)
        {
            print("Hit Something");
            if (hit.transform.GetComponent <Item_Component>())
            {
                distanceFromClick = (Vector2)transform.position - (Vector2)hit.transform.position;


                if (distanceFromClick.magnitude < maxDistance)
                {
                    Item_Component item = hit.transform.gameObject.GetComponent <Item_Component>();
                    pickUp.PickedUp(item);
                }
            }
        }
    }
Ejemplo n.º 6
0
    public void PickedUp(Item_Component item)
    {
        if (item.itemType.type == ItemType.Permanent) //apply the permanent object
        {
            for (int i = 0; i < item.itemType.buffs.Length; i++)
            {
                //apply stats for permament
                Debug.Log("You picked up " + item.itemType.itemName);
                pAttributes.pickedUpItems.Add(item.itemType);
                Destroy(item.gameObject);
            }
        }

        if (item && inventory.container.Count < inventory.capacity && item.itemType.type != ItemType.Permanent) //apply the permanent object
        {
            //here we update to inventory Ui
            inventory.AddItem(item.itemType, item.amount);
            Destroy(item.gameObject);
        }
        else if (item && inventory.container.Count >= inventory.capacity && item.itemType.type != ItemType.Permanent)
        {
            print("You are full");
        }
    }
Ejemplo n.º 7
0
    override public void OnInspectorGUI()
    {
        serializedObject.Update();
        Item_Database myDB = (Item_Database)target;

        EditorGUI.BeginChangeCheck();
        GUILayout.BeginVertical();
        GUIContent addButtonContent = new GUIContent("Add Items", "Search for and add Items to database");

        if (GUILayout.Button(addButtonContent))
        {
            myDB.addItems = true;
        }
        GUIContent updateButtonContent = new GUIContent("Update Items", "Updates prefabs in /Prefabs/Items to match json data");

        if (GUILayout.Button(updateButtonContent))
        {
            myDB.updateDatabase = true;
        }
        GUILayout.EndVertical();
        if (EditorGUI.EndChangeCheck())
        {
            Debug.Log("Editor Change Detected");
        }
        #region EditorActions
        if (myDB.updateDatabase)
        {
            myDB.initialiseJsonFile();
            Debug.Log("Checking for updates");
            myDB.updateLocalJsonData();
            Debug.Log("local items updated");
            myDB.updateDatabase = false;
        }
        if (myDB.addItems)
        {
            myDB.initialiseJsonFile();
            GameObject[] prefabs = Resources.LoadAll <GameObject>("Prefabs/Items");
            foreach (GameObject item in prefabs)
            {
                Item_Component itemComponent = item.GetComponent <Item_Component>();
                if (itemComponent.exists() == false)
                {
                    if (itemComponent.needsUpdating())
                    {
                        Debug.Log("needs updating");
                        //myDB.syncItemFromJson(item);
                    }
                    else
                    {
                        Debug.Log("Creating new Json data for item found");
                        itemComponent.Init();
                        myDB.createItem(item);
                    }
                }
                else
                {
                    Debug.Log("Item Found, Didn't need to update");
                }
            }
            myDB.addItems = false;
        }
        #endregion
    }