Beispiel #1
0
    public void RefreshWeaponWheel()
    {
        int weaponToShow = _currentWeapon;
        int weaponPos    = 1;
        int weaponsShown = 0;

        // no items means skip to the section where we hide the quads.
        bool bPlacedAll = (GameManager.Inventory.Weapons.Count == 0);

        while (!bPlacedAll)
        {
            // show proper texture
            _weaponQuads [weaponPos].gameObject.GetComponent <Renderer>().enabled = true;
            _weaponQuads [weaponPos].gameObject.GetComponent <Renderer>().material.mainTexture = GameManager.Inventory.Weapons [weaponToShow].IconTexture;

            WeaponQuad wq = _weaponQuads [weaponPos].gameObject.GetComponent <WeaponQuad>();
            wq.Title       = GameManager.Inventory.Weapons [weaponToShow].Title;
            wq.Description = GameManager.Inventory.Weapons [weaponToShow].Description;

            _weaponCountQuads [weaponPos].gameObject.GetComponent <Renderer>().enabled = true;
            _weaponCountQuads [weaponPos].gameObject.GetComponent <Renderer>().material.mainTexture = CountQuadFactory.GetTextureForCount(GameManager.Inventory.Weapons [weaponToShow].Quantity);

            weaponToShow = (weaponToShow + 1) % GameManager.Inventory.Weapons.Count;
            weaponPos    = (weaponPos + 1) % 3;
            weaponsShown++;


            // placed 3 or all of our stuff, stop trying
            bPlacedAll = (weaponsShown == 3 || weaponsShown == GameManager.Inventory.Weapons.Count);
        }

        // *** hide the slots that didn't get filled ***
        while (weaponsShown < 3)
        {
            _weaponQuads [weaponPos].gameObject.GetComponent <Renderer>().enabled      = false;
            _weaponCountQuads [weaponPos].gameObject.GetComponent <Renderer>().enabled = false;


            weaponPos = (weaponPos + 1) % 3;
            weaponsShown++;
        }

        // select the weapon
        if (GameManager.Inventory.Weapons.Count > 0 &&
            (GameManager.Inventory.CurrentWeapon != GameManager.Inventory.Weapons [_currentWeapon]))
        {
            GameManager.Inventory.CurrentWeapon = GameManager.Inventory.Weapons [_currentWeapon];
        }
    }
Beispiel #2
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);
            }
        }
    }
Beispiel #3
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));
        }
    }