예제 #1
0
    void ConsumeItemsInSlots()
    {
        // for each slot,
        for (int i = 0; i < 4; i++)
        {
            if (_craftingSlots [i] != null)
            {
                // get inventory item its for
                ItemQuad iq = _craftingSlots [i].GetComponent <ItemQuad>();

                // remove quantity of 1 for item.
                GameManager.Inventory.TryRemoveItemQty(iq.invItem.Type, 1);
                Destroy(iq.gameObject);
                _craftingSlots [i] = null;
            }
        }

        _lastClickedQuad = null;
    }
예제 #2
0
    public GameObject CreateDraggableCopy()
    {
        GameObject quadCopy = (GameObject)Instantiate(gameObject);

        quadCopy.GetComponent <Renderer>().material.color = new Color(quadCopy.GetComponent <Renderer>().material.color.r,
                                                                      quadCopy.GetComponent <Renderer>().material.color.g,
                                                                      quadCopy.GetComponent <Renderer>().material.color.b,
                                                                      1.0f);

        ItemQuad itemQuad = quadCopy.GetComponent <ItemQuad>();

        itemQuad.invItem       = invItem;
        itemQuad.IsDraggedCopy = true;

        Vector3 newScale = new Vector3(transform.parent.localScale.x, transform.parent.localScale.y, transform.parent.localScale.z);

        // TODO: make not arbitrary scale-down.
        newScale /= 4.0f;

        itemQuad.transform.localScale = newScale;
        return(quadCopy);
    }
예제 #3
0
    void OnGUI()
    {
        // REFRESH LAST CLICKED ITEM
        if (_lastClickedQuad != null)
        {
            GUI.skin.textArea.normal.background = null;
            GUI.skin.textArea.active.background = null;

            ItemQuad   iq = _lastClickedQuad.GetComponent <ItemQuad>();
            WeaponQuad wq = _lastClickedQuad.GetComponent <WeaponQuad>();


            if (iq != null)
            {
                if (iq.invItem != null)
                {
                    GUI.Label(ItemDescriptionBounds, iq.invItem.Name + "\n\n" + iq.invItem.Caption, TextStyle);
                }
            }
            else if (wq != null)
            {
                GUI.Label(ItemDescriptionBounds, wq.Title + "\n\n" + wq.Description, TextStyle);
            }
        }

        // REFRESH CRAFT RESULT
        if (_craftResult != null)
        {
            if (_craftResult.IsWeapon)
            {
                GUI.Label(new Rect(900, 450, 200, 200), _craftResult.WeaponName, TextStyle);
            }
            else
            {
                GUI.Label(new Rect(900, 450, 200, 200), _craftResult.InvItem.Name, TextStyle);
            }
        }
    }
예제 #4
0
    void ProcessMouse()
    {
        if (_state != CraftingMenuState.CraftingMenu_Open)
        {
            return;
        }


        // catch mouse down/up to begin/end dragging
        if (Input.GetMouseButtonDown(0))
        {
            Ray rayToGUI = _uiCamera.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            if (Physics.Raycast(rayToGUI, out hit))
            {
                // we either clicked an item quad or a weapon quad.
                // or maybe the craft button

                _sound.Play(_sound.SelectItem, 1.0f);
                ItemQuad    itemQuad = hit.collider.GetComponent <ItemQuad>();
                WeaponQuad  weapQuad = hit.collider.GetComponent <WeaponQuad>();
                CraftButton cb       = hit.collider.GetComponent <CraftButton>();

                if (itemQuad != null)
                {
                    _lastClickedQuad = hit.collider.gameObject;

                    // an item from the wheel
                    if (!itemQuad.IsDraggedCopy)
                    {
                        _draggingQuad = itemQuad.CreateDraggableCopy();

                        // an item already in a crafting slot, just moving it.
                    }
                    else
                    {
                        _draggingQuad = itemQuad.gameObject;

                        // take it out of whichever slot it was in.
                        for (int i = 0; i <= _craftingSlots.Length - 1; i++)
                        {
                            if (_craftingSlots [i] == _draggingQuad)
                            {
                                _craftingSlots [i] = null;
                            }
                        }
                    }

                    // clicked a weapon because we want to see its info?
                }
                else if (weapQuad != null)
                {
                    Debug.Log("Clicked a weapon quad.");
                    _lastClickedQuad = hit.collider.gameObject;
                }
                else if (cb != null)
                {
                    // we should be able to make something
                    if (_craftResult != null)
                    {
                        Craft();
                    }
                }
            }

            UpdateCraftResult();
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (_draggingQuad != null)
            {
                Vector2 mousePoint2D = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

                for (int i = 0; i <= CraftingPoints.Length - 1; i++)
                {
                    if (Vector2.Distance(mousePoint2D, CraftingPoints [i]) <= CraftingDropDistance)
                    {
                        // remove any existing item in the slot
                        if (_craftingSlots [i] != null)
                        {
                            Destroy(_craftingSlots [i]);
                            _craftingSlots [i] = null;
                        }

                        // put new item in the slot
                        _craftingSlots [i] = _draggingQuad;
                        _draggingQuad.transform.position = _uiCamera.ScreenToWorldPoint(CraftingPoints [i]);
                        // stop dragging
                        _draggingQuad = null;
                        //play sound
                        _sound.Play(_sound.DropoffItem, 0.5f);
                    }
                }

                // got here, no crafting point for it, so destroy it
                Destroy(_draggingQuad);
                _draggingQuad = null;
                //_sound.Play(_sound.NotACombination,1.0f);
            }

            UpdateCraftResult();
        }


        // if dragging something, put it under mouse
        if (_draggingQuad != null)
        {
            _draggingQuad.transform.position = _uiCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x - 15.0f, Input.mousePosition.y + 15.0f, 2.0f));
        }
    }