Пример #1
0
 void HandleItemUnequipped(ItemInstance item)
 {
     if (currentEquippedItem == item.GetComponent <Equippable>())
     {
         currentEquippedItem.equipped = false;
         currentEquippedItem.gameObject.GetComponent <FadeInOut>().Stop();
     }
 }
    public void OnDrag(PointerEventData eventData)
    {
        //Todo - Add mouse smoothing and inertia
        if (!ItemInstance.beingDragged)
        {
            SetStartVars();
            ItemInstance.gameObject.GetComponent <Image>().raycastTarget = false;
            ItemInstance.beingDragged = true;
            InventoryInteraction.DragItem(ItemInstance);
            AudioHost._audio.PlayClip(AudioHost.grabItemSound);
        }
        InventoryInteraction.ContinueDrag(ItemInstance, Input.mousePosition);
        transform.position = Input.mousePosition;

        float   heightOFfset     = ItemInstance.GetComponent <RectTransform>().rect.height / 2;
        float   widthOFfset      = ItemInstance.GetComponent <RectTransform>().rect.width / 2;
        Vector3 adjustedMousePos = Input.mousePosition;

        adjustedMousePos.y -= heightOFfset;
        adjustedMousePos.x -= widthOFfset;
        ItemInstance.GetNewGridPos(InventoryInteraction.getGridPosFromScreen(adjustedMousePos));
    }
Пример #3
0
    public void RecenterDroppedItem(ItemInstance item)
    {
        //Debug.Log("X: " + item.gridPos.x + ", Y: " + item.gridPos.y);
        item.transform.SetParent(itemsHolder);

        item.GetComponent <Image>().rectTransform.anchorMin = new Vector2(0, 0);
        item.GetComponent <Image>().rectTransform.anchorMax = new Vector2(0, 0);

        int multipliedX = (16 * item.ItemDetail.width);
        int multipliedY = (16 * item.ItemDetail.height);

        item.GetComponent <Image>().rectTransform.anchoredPosition = new Vector2(multipliedX + (item.gridPos.x * 32), multipliedY + (item.gridPos.y * 32));

        // Vector2 itemPositionRelative = transform.InverseTransformPoint(item.transform.position);
        // Debug.Log(itemPositionRelative);

        // int dividedX = (int)(itemPositionRelative.x / 32) * 10;
        // int dividedy = (int)(itemPositionRelative.x / 32) * 10;
        // Vector2 roundedPos = new Vector2(dividedX, dividedy);
        // Vector2 roundedPosNonRelative = transform.TransformPoint(roundedPos);

        // item.transform.position = roundedPosNonRelative;
    }
Пример #4
0
    void HandleItemEquipped(ItemInstance item)
    {
        if (currentEquippedItem != null)
        {
            currentEquippedItem.equipped = false;
            if (!currentEquippedItem.GetComponent <Equippable>().defunct)
            {
                currentEquippedItem.gameObject.GetComponent <FadeInOut>().Stop();
            }
        }

        currentEquippedItem          = item.GetComponent <Equippable>();
        currentEquippedItem.equipped = true;
        currentEquippedItem.gameObject.GetComponent <FadeInOut>().Begin();
        AudioHost._audio.PlayClip(AudioHost.equipItemSound);
    }
Пример #5
0
    public void DestroyItemInInventory(ItemInstance item)
    {
        if (items.Contains(item))
        {
            RemoveItem(item);

            DestroyHandler DestroyHandler = item.GetComponent <DestroyHandler>();
            if (DestroyHandler != null)
            {
                DestroyHandler.DestroySelf();
            }
            else
            {
                GameObject.Destroy(item.gameObject);
            }
        }
    }
Пример #6
0
    public void TryEquipCell(Vector2Int coord)
    {
        ItemInstance itemAtCell = GetItemAtCell(coord);

        if (itemAtCell != null)
        {
            ItemDetail ItemDetail = itemAtCell.ItemDetail;
            if (ItemDetail.equippable && !itemAtCell.GetComponent <Equippable>().defunct)
            {
                EquipItem(itemAtCell);
            }
        }
        else
        {
            foreach (Vector2 point in items[0].points)
            {
                Debug.Log(point);
            }
            Debug.Log("Nothing to equip at cell + " + coord.x + " : " + coord.y);
        }
    }
Пример #7
0
    public void AttemptPickUp()
    {
        ItemInstance tempItem;

        for (int i = 0; i < Game.Instance.CurrentScene.SceneItemsCount; i++)
        {
            string       itemKey = Game.Instance.CurrentScene.Items.Keys.ElementAt(i);
            ItemInstance item    = Game.Instance.CurrentScene.Items[itemKey];
            tempItem = item.GetComponent <ItemInstance>();

            if (Vector2.Distance(tempItem.transform.position, transform.position) < 0.5f)
            {
                string errorMessage = Info.Inventory.canPickItem(item);
                if (errorMessage != "")
                {
                    InGameMainMenuUI.Instance.ShockMessageCenter.CallMessage(errorMessage, Color.red, false);
                    continue;
                }
                SocketClient.Instance.SendPickedItem(itemKey);
                break;
            }
        }
    }
Пример #8
0
    public void SpawnLoot(EItem item, Vector2 worldPos)
    {
        ItemInstance ii = SpawnItem(item);

        if (!ii)
        {
            return;
        }

        ii.gameObject.transform.position = new Vector3(worldPos.x, worldPos.y, -0.06f);

        Mover itemInstanceMover = ii.GetComponent <Mover>();

        if (itemInstanceMover)
        {
            // make it moves around in a random direction
            Vector2 randDir = RandomManager.Vector();
            float   dir     = RandomManager.Next(0.8f, 3.5f);

            Vector2 target = (Vector2)ii.gameObject.transform.position + (randDir * dir);

            itemInstanceMover.StartInterpolation(target, 0.3f, null);
        }
    }
Пример #9
0
 public PotentialPurchaseItem(GameObject obj, Transform parent)
 {
     ItemInstance = GameObject.Instantiate(obj, parent);
     Item         = ItemInstance.GetComponent <IShopItem>();
 }