Exemplo n.º 1
0
 private void Init()
 {
     Debug.Log("Starting Recipe Container");
     if (m_checkmarks == null)
     {
         m_checkmarks = new Checkmark[4];
     }
     if (!m_craftButton)
     {
         m_craftButton = this.gameObject.GetComponentInChildren <CraftButton>();
     }
     if (m_recipeSprites == null)
     {
         m_recipeSprites = new Dictionary <ItemType, Sprite>();
         m_recipeSprites.Add(ItemType.HAMMER, m_hammerRecipe);
         m_recipeSprites.Add(ItemType.RAM, m_ramRecipe);
         m_recipeSprites.Add(ItemType.DYNAMITE, m_dynamiteRecipe);
     }
 }
Exemplo n.º 2
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));
        }
    }