예제 #1
0
    /// <summary>
    /// Creates the quick item.
    /// </summary>
    /// <returns>The quick item.</returns>
    /// <param name="item">Item.</param>
    public QuickItem CreateQuickItem(GameObject item)
    {
        QuickItem res     = null;
        DadCell   dadCell = GetComponent <DadCell>();

        if (item != null && dadCell != null)
        {
            ClickItem clickItem = item.GetComponent <ClickItem>();
            if (clickItem != null)
            {
                // Remove old quick item
                RemoveQuickItem();
                // Load quick item template
                GameObject newQuickItem = Instantiate(Resources.Load <GameObject>("QuickItemPrefab"));
                newQuickItem.name = item.name;
                res            = newQuickItem.GetComponent <QuickItem>();
                res.itemSource = clickItem;
                Image myImage     = newQuickItem.GetComponent <Image>();
                Image sourceImage = item.GetComponent <Image>();
                if (myImage != null && sourceImage != null)
                {
                    myImage.sprite = sourceImage.sprite;
                    myImage.color  = sourceImage.color;
                }
                // Place quick item to quick cell
                dadCell.AddItem(newQuickItem.gameObject);
            }
        }
        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)
    {
        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);
    }
예제 #3
0
    /// <summary>
    /// Manualy add item into cell.
    /// </summary>
    /// <param name="cell">Cell.</param>
    /// <param name="item">Item.</param>
    public static void AddItem(GameObject cell, GameObject item)
    {
        DadCell dadCell = cell.GetComponent <DadCell>();

        if (dadCell != null)
        {
            dadCell.AddItem(item);
        }
    }
예제 #4
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);
    }
예제 #5
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);
    }