コード例 #1
0
    void OnMouseOverItem(GridItem item)                 // mesmo nome que o da outra classe
    {                                                   // para nao selecionar mais que um item quando selecionar um
        if (_selectedItem == item || _canPlay == false) // se tem item e se a interaçao do usuario = falso
        {
            return;
        }

        if (_selectedItem == null) // se esta vazio
        {
            _selectedItem = item;  // atribui o item selecionado
            _selectedItem.GetComponent <Animator>().SetTrigger("Select");
        }
        else
        {
            int xResult = Mathf.Abs(item.x - _selectedItem.x); // posiçao x dele - a posiçao anterior selecionada
            int yResult = Mathf.Abs(item.y - _selectedItem.y); //valor absoluto
            //assim nao consegue fazer a troca com outras frutas alem das q estao do lado


            if (xResult + yResult == 1)                              //para nao trocar com a diagonal
            {
                StartCoroutine(TryMatch(_selectedItem, item, 0.1f)); //corrotina
            }

            _selectedItem.GetComponent <Animator>().SetTrigger("DeSelect");
            _selectedItem = null;
        }
    }
コード例 #2
0
    public void SetCurrentDragedItem(GridItem item, bool longPressMode)
    {
        _gridItem = item;
        InventoryUI.SetEventPanelActive(true);
        if (item.GetContainedPanel() is InventoryUI)
        {
            _fromInventory = true;
            Inventory.RemoveItemFromInventory(_gridItem, false);
        }
        else
        {
            Equipment.RemoveItem(item.GetItemReference());
            _fromInventory = false;
        }

        underItem = ObjectPoolManager.Instance.GetObject <UnderMouseItem>(UNDER_MOUSE_ICON_PREFAB_KEY);
        underItem.Setup(item.GetItemReference().Image);
        underItem.transform.SetParent(InventoryUI.CanvasRoot.transform);
        underItem.transform.localScale = Vector2.one;
        ObjectPoolManager.Instance.RecycleObject(_gridItem.GetComponent <PoolableObjectInstance>());
        _longPressMode = longPressMode;

        if (_longPressMode)
        {
            InventoryUI.SetScrollRectActive(false);
        }
    }
コード例 #3
0
    void OnMouseOverItem(GridItem item)
    {
        if (_selectedItem == item || _canPlay == false)
        {
            return;
        }

        if (_selectedItem == null)
        {
            _selectedItem = item;
            _selectedItem.GetComponent <Animator>().SetTrigger("Select");
        }
        else
        {
            int xResult = Mathf.Abs(item.x - _selectedItem.x);
            int yResult = Mathf.Abs(item.y - _selectedItem.y);

            if (xResult + yResult == 1)
            {
                StartCoroutine(TryMatch(_selectedItem, item, 0.1f));
            }

            _selectedItem.GetComponent <Animator>().SetTrigger("Deselect");
            _selectedItem = null;
        }
    }
コード例 #4
0
 public override void PrePush(GridItem byItem, Direction inDirection)
 {
     //base.PrePush(byItem, inDirection);
     if (byItem.GetComponent <GridCharacter>())
     {
         pushByChar = true;
         Debug.Log("pushed by char");
     }
 }
コード例 #5
0
ファイル: Builder.cs プロジェクト: dj46563/Misplaced
 private void ClientOnExitingBuildingMode()
 {
     // Let go of what im holding
     if (_highlightedItem != null)
     {
         _highlightedItem.ResetPosition();
         SpriteRenderer renderer = _highlightedItem.GetComponent <SpriteRenderer>();
         renderer.material.SetFloat("Vector1_5D8044E5", 0);
     }
     _grabbyHand.Pointer();
 }
コード例 #6
0
    public override void AddNewGridItem(GridItem gItem, Item item)
    {
        //Vector3 beforeScale = gItem.transform.localScale;
        Transform selectedParent = null;

        switch (item.Equipment)
        {
        case Item.EquipmentCategory.PrimaryWeapon:
            selectedParent = _primaryWeaponRoot;
            break;

        case Item.EquipmentCategory.SecondaryWeapon:
            selectedParent = _secondaryWeaponRoot;

            break;

        case Item.EquipmentCategory.Helmet:
            selectedParent = _helmetRoot;

            break;

        case Item.EquipmentCategory.Shoes:
            selectedParent = _shoesRoot;

            break;

        case Item.EquipmentCategory.Medal:
            selectedParent = _medalRoot;

            break;

        case Item.EquipmentCategory.Amulet:
            selectedParent = _amuletRoot;

            break;

        case Item.EquipmentCategory.Ring:
            selectedParent = _ringRoot;

            break;
        }
        gItem.transform.SetParent(selectedParent);
        gItem.transform.localScale = Vector3.one;

        RectTransform rect = gItem.GetComponent <RectTransform>();

        rect.anchorMin        = new Vector2(0.5f, 0.5f);
        rect.anchorMax        = new Vector2(0.5f, 0.5f);
        rect.pivot            = new Vector2(0.5f, 0.5f);
        rect.anchoredPosition = new Vector2(0, 0);
        rect.sizeDelta        = selectedParent.GetComponent <RectTransform>().sizeDelta;
        gItem.Setup(item);
    }
コード例 #7
0
    // -- Método de assina o evento 'OnMouseOverItem'
    void OnMouseOverItem(GridItem item)
    {
        if (_selectedItem == item || _canPlay == false)
        {
            return;
        }

        //Debug.Log(item.gameObject.name);
        if (_selectedItem == null)
        {
            // -- Se não existir _selectedItem, este será o item atual
            _selectedItem = item;
            _selectedItem.GetComponent <Animator>().SetTrigger("Select");
        }
        else
        {
            // -- Lógica para o swap
            // -- Como saber se a posição é visinha?
            int xResult = Mathf.Abs(item.x - _selectedItem.x);
            int yResult = Mathf.Abs(item.y - _selectedItem.y);

            if (xResult + yResult == 1)
            {
                StartCoroutine(TryMatch(_selectedItem, item, 0.1f));

                /*
                 * List<GridItem> gridItemList = CheckHorizontalMatches(_selectedItem);
                 * if (gridItemList.Count > 2)
                 * {
                 *  foreach (GridItem g in gridItemList)
                 *  {
                 *      Destroy(g.gameObject);
                 *  }
                 * }
                 *
                 * gridItemList = CheckHorizontalMatches(item);
                 * if (gridItemList.Count > 2)
                 * {
                 *  foreach (GridItem g in gridItemList)
                 *  {
                 *      Destroy(g.gameObject);
                 *  }
                 * }
                 */
            }
            // -- Se existir _selectedItem (item anterior) será null
            _selectedItem.GetComponent <Animator>().SetTrigger("Deselect");
            _selectedItem = null;
        }
    }
コード例 #8
0
 public void RemoveItemFromInventory(GridItem item, bool destroyObject)
 {
     if (_items.ContainsKey(item.GetItemReference().Id))
     {
         List <GridItem> stackableItems = _items[item.GetItemReference().Id];
         stackableItems.Remove(item);
         if (stackableItems.Count == 0)
         {
             _items.Remove(item.GetItemReference().Id);
         }
         if (destroyObject)
         {
             ObjectPoolManager.Instance.RecycleObject(item.GetComponent <PoolableObjectInstance>());
         }
     }
 }