示例#1
0
    public bool AllowDropped(DragMe dragMe)
    {
        InventoryItem item = dragMe.GetComponent <InventoryItem>();

        if (item != null)
        {
            if (item.ItemType == allowDropType)
            {
                return(true);
            }
        }

        return(false);
    }
示例#2
0
    public void OnDrop(PointerEventData data)
    {
        Sprite dropSprite = GetDropSprite(data);
        ShipComponentDataHolder shipAttachment = GetShipAttachment(data);

        if (dropSprite == null)
        {
            return;
        }

        if (isShipPart)
        {
            if (shipAttachment != null)
            {
                if (shipAttachment.AttachmentSlot != inventorySlotType)
                {
                    return;
                }
            }
        }


        var DropMe      = dragMe.GetComponent <DropMe>();
        var localDragMe = GetComponent <DragMe>();


        if (DropMe == null)
        {
            if (shipAttachment.cost < PlayerStats.instance.score)
            {
                dragMe.GetComponent <BuyMe>().BuyItem(shipAttachment.cost);
            }
            else
            {
                AddTextToLog.instance.AddTextToEventLog("Not enough credits!");
                return;
            }
        }


        if (!isShipPart)
        {
            if (dropSprite != null)
            {
                if (localDragMe.itemData != null)
                {
                    ChangeImageAndItem(dropSprite, true);
                }
                else
                {
                    ChangeImageAndItem(dropSprite, false);
                }
            }
        }

        if (DropMe != null)
        {
            if (DropMe.isShipPart || isShipPart || !isShipPart)
            {
                DestroyUnequippedComponents(DropMe);
            }
        }

        if (isShipPart)
        {
            bool isNull = true;

            if (localDragMe.itemData != null)
            {
                isNull = false;
                if (!DropMe.isShipPart && isShipPart)
                {
                    SwichIconsAndAttachments(localDragMe);          //receiving slot shipPart and both slots have item.
                    CreateComponentForShip(shipAttachment, transform, weaponSlot);
                }
                if (DropMe.isShipPart && isShipPart)
                {
                    DestroyUnequippedComponents(this);
                    DestroyUnequippedComponents(DropMe);

                    CreateComponentForShip(localDragMe.itemData, dragMe.transform, DropMe.weaponSlot);
                    CreateComponentForShip(dragMe.itemData, transform, weaponSlot);

                    SwichIconsAndAttachments(localDragMe);
                    // molemmat ovat aseita
                }
            }
            else
            {
                isNull = true;
            }

            if (isNull)
            {
                localDragMe.itemData = dragMe.itemData;
                CreateComponentForShip(shipAttachment, transform, weaponSlot);
                DropMe.containerImage.color = HiddenColor;
                containerImage.sprite       = GetDropSprite(data);

                //receiving slot is ShipPart and its empty
                dragMe.itemData = null;
                dragMe.GetComponent <Image>().sprite = null;
            }

            containerImage.color = normalColor;
            PlayerStats.instance.GetComponent <GetShipComponents>().GetComponents(shipAttachment);
        }
    }