コード例 #1
0
 /// <summary>
 /// Swaps DaD items between cells.
 /// </summary>
 /// <param name="firstDadCell">First DaD cell.</param>
 /// <param name="secondDadCell">Second DaD cell.</param>
 public static void SwapItems(DadCell firstDadCell, DadCell secondDadCell)
 {
     //print(11);
     if ((firstDadCell != null) && (secondDadCell != null))
     {
         GameObject firstItem  = firstDadCell.GetItem();                           // Get item from first cell
         GameObject secondItem = secondDadCell.GetItem();                          // Get item from second cell
         // Swap items
         firstDadCell.PlaceItem(secondItem, false);
         secondDadCell.PlaceItem(firstItem, false);
         // Update states
         firstDadCell.UpdateMyItem();
         secondDadCell.UpdateMyItem();
         firstDadCell.UpdateBackgroundState();
         secondDadCell.UpdateBackgroundState();
     }
 }
コード例 #2
0
ファイル: StackCell.cs プロジェクト: TFM-AEIS/TFM
    /// <summary>
    /// Crete item from prefab and place it in cell. Current item will be removed
    /// </summary>
    /// <returns>The item from prefab.</returns>
    /// <param name="itemPrefab">Item prefab.</param>
    /// <param name="stackAmount">Stack amount of created item.</param>
    public StackItem AddItemFromPrefab(StackItem itemPrefab, int stackAmount)
    {
        StackItem res     = null;
        DadCell   dadCell = GetComponent <DadCell>();

        if (dadCell != null)
        {
            // Create item
            res = Instantiate(itemPrefab);
            // Remove current stack item
            RemoveStackItem();
            // Place item into cell
            dadCell.AddItem(res.gameObject);
            res.name = itemPrefab.name;
            // Set stack amount for created item
            stackAmount = Mathf.Min(stackAmount, cellStackLimit, res.maxStack);
            res.SetStack(stackAmount);
        }
        return(res);
    }
コード例 #3
0
    /// <summary>
    /// Swaps the stacks between cells.
    /// </summary>
    /// <returns><c>true</c>, if stacks was swaped, <c>false</c> otherwise.</returns>
    /// <param name="sourceStackCell">Source stack cell.</param>
    public bool SwapStacks(StackCell sourceStackCell)
    {
        bool res = false;

        if (sourceStackCell != null)
        {
            StackItem myStackItem    = GetStackItem();
            StackItem theirStackItem = sourceStackCell.GetStackItem();
            if (myStackItem != null && theirStackItem != null)
            {
                if (SortCell.IsSortAllowed(gameObject, theirStackItem.gameObject) == true &&
                    SortCell.IsSortAllowed(sourceStackCell.gameObject, myStackItem.gameObject) == true)
                {
                    if (cellStackLimit >= theirStackItem.GetStack() &&
                        sourceStackCell.cellStackLimit >= myStackItem.GetStack())
                    {
                        DadCell.SwapItems(gameObject, sourceStackCell.gameObject);
                        res = true;
                    }
                }
            }
        }
        return(res);
    }
コード例 #4
0
 /// <summary>
 /// Item is dropped into this cell.
 /// </summary>
 /// <param name="data"></param>
 public void OnDrop(PointerEventData data)
 {
     if (DadItem.icon != null)
     {
         DadCell sourceCell = DadItem.sourceCell;
         if (sourceCell != this)
         {
             DadEventDescriptor desc = new DadEventDescriptor();
             desc.sourceCell      = sourceCell;
             desc.destinationCell = this;
             SendGroupRequest(desc);                                                         // Send group request
             SendCellRequest(desc);                                                          // Send cell request
             StartCoroutine(NotifyOnDragEnd(desc));                                          // Send notification after drop will be finished
             if (desc.cellPermission == true && desc.groupPermission == true)                // If drop permitted
             {
                 SwapItems(sourceCell, this);                                                // Swap items between cells
             }
         }
         UpdateMyItem();
         UpdateBackgroundState();
         sourceCell.UpdateMyItem();
         sourceCell.UpdateBackgroundState();
     }
 }