///<summary>
    ///构造一个Item
    ///<summary>
    ///<param name="itemid"></param>
    ///<param name="name"></param>
    ///<param name="desc"></param>
    ///<param name="itemType"> -1:all 0:equip 1:chips</param>
    ///<param name="icon"></param>
    ///<param name="bgIcon"></param>
    ///<param name="itemcount"></param>
    ///<param name="quality"></param>0:white 1:cyan 2:green 3:red</summary>param>
    ///<param name="operation"></param>
    public BackPackItem(int itemid, string name, string desc, int itemType, string icon, string bgIcon, int itemcount, int quality, int opreation)
    {
        this.ItemID   = itemid;
        this.ItemName = name;
        this.ItemDesc = desc;
        switch (itemType)
        {
        case -1:
            this.ItemType = BackPackItemType.UnKown;
            break;

        case 0:
            this.ItemType = BackPackItemType.Equip;
            break;

        case 1:
            this.ItemType = BackPackItemType.Chips;
            break;

        default:
            break;
        }
        this.ItemIcon      = icon;
        this.ItemBgIcon    = bgIcon;
        this.ItemCount     = itemcount;
        this.ItemQuality   = quality;
        this.ItemOpreation = opreation;
    }
    //Adds an item type to the BackPack
    IEnumerator AddItemType(BackPackItemType t, ObjectBase item)
    {
        t.AddItem(item);

        while (transitInProgress)
        {
            yield return(new WaitForEndOfFrame());
        }

        transitInProgress = true;

        float newTypePos;
        float addWidth;

        //If the BackPack is empty, calculate new position from the BackPack button
        if (items.Count == 0)
        {
            newTypePos = button.transform.position.x + (t.GetWidth() / 2) + (spaceBetweenItems);
            addWidth   = t.GetWidth() + (spaceBetweenItems * 5);
        }
        //Else, calculate new position from the last item
        else
        {
            newTypePos = items[items.Count - 1].transform.position.x + (items[items.Count - 1].GetWidth() / 2) + spaceBetweenItems + (t.GetWidth() / 2);
            addWidth   = t.GetWidth() + spaceBetweenItems;
        }

        Vector3 newPos = new Vector3(newTypePos, button.transform.position.y, t.transform.position.z);

        //Reset the type
        t.SetPosition(newPos);
        t.gameObject.SetActive(true);

        //Remove the type from the inactive list and add it to the active list
        inactiveItems.Remove(t);
        items.Add(t);

        ModifyBackPackValues(addWidth);

        yield return(new WaitForEndOfFrame());

        //If the newly added item is the only item, open the BackPack
        if (items.Count == 1)
        {
            Open();
            yield return(new WaitForSeconds(0.2f));
        }
        //If the item can fit into the BackPack without scrolling, extend the BackPack
        else if (scrollAmmount == 0)
        {
            StartCoroutine(MoveHorizontalBy(strip, -(t.GetWidth() + spaceBetweenItems), 0.2f, false));
            yield return(new WaitForSeconds(0.2f));
        }

        transitInProgress = false;
    }
    //Returns the index of t in the items array
    int GetIndex(BackPackItemType t)
    {
        int i = 0;

        while (i < items.Count && t.ContentName() != items[i].ContentName())
        {
            i++;
        }

        return(i);
    }
    //Removes an item type from the BackPack
    IEnumerator RemoveItemType(BackPackItemType t)
    {
        while (transitInProgress)
        {
            yield return(new WaitForEndOfFrame());
        }

        transitInProgress = true;

        //Get the index of the item and store the items to its right
        int index = GetIndex(t);
        List <BackPackItemType> right = GetItemsAfter(index);

        //Remove the item type from the items list
        items.Remove(t);
        inactiveItems.Add(t);
        t.gameObject.SetActive(false);

        //Place the right items to the temp, and move them to their new place
        MoveToTemp(right);
        StartCoroutine(MoveHorizontalBy(tempContainer, -(t.GetWidth() + spaceBetweenItems), 0.2f, false));

        //Modify BackPack movement variables
        ModifyBackPackValues(-(t.GetWidth() + spaceBetweenItems));

        //StartCoroutine("Test");
        yield return(new WaitForSeconds(0.2f));

        //Copy back the items from the temp to their original position
        ResetParents();

        //If the items can fit into the whole BackPack
        if (totalWidth < maxBackPackMovement && items.Count > 0)
        {
            //Move the BackPack to the right
            float movementAmmount = button.transform.position.x - (3 * spaceBetweenItems) - (items[items.Count - 1].GetWidth() / 2);
            movementAmmount -= items[items.Count - 1].transform.position.x;

            StartCoroutine(MoveHorizontalBy(strip, movementAmmount, 0.2f, false));
            yield return(new WaitForSeconds(0.2f));
        }

        //Finalise item scrolling
        FinaliseScrolling();

        transitInProgress = false;
    }
    //Disables and removes an item type from the BackPack
    public void DisableItemType(BackPackItemType item)
    {
        //If this is the last item in the BackPack, simply remove it
        if (items.Count == 1)
        {
            inactiveItems.Add(items[0]);

            totalWidth       = 0;
            BackPackMovement = 0;
            scrollAmmount    = 0;

            items[0].gameObject.SetActive(false);

            items.Remove(items[0]);
            Close();
        }
        //If there is more than one item left in the BackPack, "remove" animation is played
        else
        {
            StartCoroutine("RemoveItemType", item);
        }
    }
    //Removes an item type from the BackPack
    IEnumerator RemoveItemType(BackPackItemType t)
    {
        while (transitInProgress)
            yield return new WaitForEndOfFrame();

        transitInProgress = true;

        //Get the index of the item and store the items to its right
        int index = GetIndex(t);
        List<BackPackItemType> right = GetItemsAfter(index);

        //Remove the item type from the items list
        items.Remove(t);
        inactiveItems.Add(t);
        t.gameObject.SetActive(false);

        //Place the right items to the temp, and move them to their new place
        MoveToTemp(right);
        StartCoroutine(MoveHorizontalBy(tempContainer, -(t.GetWidth() + spaceBetweenItems), 0.2f, false));

        //Modify BackPack movement variables
        ModifyBackPackValues(-(t.GetWidth() + spaceBetweenItems));

        //StartCoroutine("Test");
        yield return new WaitForSeconds(0.2f);

        //Copy back the items from the temp to their original position
        ResetParents();

        //If the items can fit into the whole BackPack
        if (totalWidth < maxBackPackMovement && items.Count > 0)
        {
            //Move the BackPack to the right
            float movementAmmount = button.transform.position.x - (3 * spaceBetweenItems) - (items[items.Count - 1].GetWidth() / 2);
            movementAmmount -= items[items.Count - 1].transform.position.x;

            StartCoroutine(MoveHorizontalBy(strip, movementAmmount, 0.2f, false));
            yield return new WaitForSeconds(0.2f);
        }

        //Finalise item scrolling
        FinaliseScrolling();

        transitInProgress = false;
    }
    //Returns the index of t in the items array
    int GetIndex(BackPackItemType t)
    {
        int i = 0;
        while (i < items.Count && t.ContentName() != items[i].ContentName())
            i++;

        return i;
    }
    //Adds an item type to the BackPack
    IEnumerator AddItemType(BackPackItemType t, ObjectBase item)
    {
        t.AddItem(item);

        while (transitInProgress)
            yield return new WaitForEndOfFrame();

        transitInProgress = true;

        float newTypePos;
        float addWidth;

        //If the BackPack is empty, calculate new position from the BackPack button
        if (items.Count == 0)
        {
            newTypePos = button.transform.position.x + (t.GetWidth() / 2) + (spaceBetweenItems);
            addWidth = t.GetWidth() + (spaceBetweenItems * 5);
        }
        //Else, calculate new position from the last item
        else
        {
            newTypePos = items[items.Count - 1].transform.position.x + (items[items.Count - 1].GetWidth() / 2) + spaceBetweenItems + (t.GetWidth() / 2);
            addWidth = t.GetWidth() + spaceBetweenItems;
        }

        Vector3 newPos = new Vector3(newTypePos, button.transform.position.y, t.transform.position.z);

        //Reset the type
        t.SetPosition(newPos);
        t.gameObject.SetActive(true);

        //Remove the type from the inactive list and add it to the active list
        inactiveItems.Remove(t);
        items.Add(t);

        ModifyBackPackValues(addWidth);

        yield return new WaitForEndOfFrame();

        //If the newly added item is the only item, open the BackPack
        if (items.Count == 1)
        {
            Open();
            yield return new WaitForSeconds(0.2f);
        }
        //If the item can fit into the BackPack without scrolling, extend the BackPack
        else if (scrollAmmount == 0)
        {
            StartCoroutine(MoveHorizontalBy(strip, -(t.GetWidth() + spaceBetweenItems), 0.2f, false));
            yield return new WaitForSeconds(0.2f);
        }

        transitInProgress = false;
    }
    //Disables and removes an item type from the BackPack
    public void DisableItemType(BackPackItemType item)
    {
        //If this is the last item in the BackPack, simply remove it
        if (items.Count == 1)
        {
            inactiveItems.Add(items[0]);

           totalWidth = 0;
            BackPackMovement = 0;
            scrollAmmount = 0;

            items[0].gameObject.SetActive(false);

            items.Remove(items[0]);
            Close();
        }
        //If there is more than one item left in the BackPack, "remove" animation is played
        else
            StartCoroutine("RemoveItemType", item);
    }