コード例 #1
0
ファイル: StackCell.cs プロジェクト: reviloj/Dream-State
    /// <summary>
    /// Unites item in stack with this cell.
    /// </summary>
    /// <returns>The stack.</returns>
    /// <param name="stackItem">Stack item.</param>
    /// <param name="limit">Stack limit.</param>
    public int UniteStack(StackItem stackItem, int limit)
    {
        print(5);
        int res = 0;

        if (stackItem != null)
        {
            int       allowedSpace = GetAllowedSpace();
            StackItem myStackItem  = GetStackItem();
            if (myStackItem == null)                                                                                            // Cell has no item
            {
                if (SortCell.IsSortAllowed(gameObject, stackItem.gameObject) == true)
                {
                    // Create new stack item to put it into this cell
                    StackItem newStackItem = Instantiate(stackItem);
                    newStackItem.name = stackItem.name;
                    DadCell.AddItem(gameObject, newStackItem.gameObject);
                    // Check the correct amout of united item
                    int stackDelta = Mathf.Min(stackItem.GetStack(), allowedSpace, limit);
                    newStackItem.SetStack(stackDelta);
                    stackItem.ReduceStack(stackDelta);
                    res = stackDelta;
                }
            }
            else if (HasSameItem(stackItem) == true)                                                            // Cell has same item
            {
                int stackDelta = Mathf.Min(stackItem.GetStack(), allowedSpace, limit);
                myStackItem.AddStack(stackDelta);
                stackItem.ReduceStack(stackDelta);
                res = stackDelta;
            }
        }
        return(res);
    }
コード例 #2
0
    /// <summary>
    /// Unites item in stack with this cell.
    /// </summary>
    /// <returns>The stack.</returns>
    /// <param name="stackItem">Stack item.</param>
    /// <param name="limit">Stack limit.</param>
    public int UniteStack(StackItem stackItem, int limit)
    {
        int res = 0;

        if (stackItem != null)
        {
            int       allowedSpace = GetAllowedSpace();
            StackItem myStackItem  = GetStackItem();
            if (myStackItem == null)                                                                            // Cell has no item
            {
                if (SortCell.IsSortAllowed(gameObject, stackItem.gameObject) == true)                           // Item type is allowed for this cell
                {
                    if (stackItem.GetStack() == limit && allowedSpace >= limit)                                 // Cell has anough space for all item's stack
                    {
                        // Totaly place item in new cell
                        DadCell sourceDadCell = Gets.GetComponentInParent <DadCell>(stackItem.transform);
                        if (sourceDadCell != null)
                        {
                            DadCell.SwapItems(gameObject, sourceDadCell.gameObject);
                        }
                        else
                        {
                            DadCell.AddItem(gameObject, stackItem.gameObject);
                        }
                        res = limit;
                    }
                    else                                                                                                                                                        // Only part of item stack will be placed into new cell
                    {
                        // Create new stack item to put it into this cell
                        StackItem newStackItem = Instantiate(stackItem);
                        newStackItem.name = stackItem.name;
                        DadCell.AddItem(gameObject, newStackItem.gameObject);
                        // Check the correct amout of united item
                        int stackDelta = Mathf.Min(stackItem.GetStack(), allowedSpace, limit);
                        newStackItem.SetStack(stackDelta);
                        stackItem.ReduceStack(stackDelta);
                        res = stackDelta;
                    }
                }
            }
            else if (HasSameItem(stackItem) == true)                                                                                            // Cell has same item
            {
                int stackDelta = Mathf.Min(stackItem.GetStack(), allowedSpace, limit);
                myStackItem.AddStack(stackDelta);
                stackItem.ReduceStack(stackDelta);
                res = stackDelta;
            }
        }
        return(res);
    }