Container.SortContainer C# (CSharp) Method

SortContainer() public static method

public static SortContainer ( Container, cn ) : void
cn Container,
return void
    public static void SortContainer(Container cn)
    {
        //Debug.Log ("Sorting container");
        //Flattens the contents of a container so that they occupy the first slots
        int currFreeSlot=-1;
        string ItemName;
        bool GetNextSlot=true;
        for (int i=0;i<=cn.MaxCapacity();i++)
        {
            //Find the first free slot
            if (GetNextSlot==true)
            {
                for (int j=0;j<=cn.MaxCapacity();j++)
                {
                    ItemName=cn.GetItemAt(j);
                    if (ItemName=="")
                    {
                        currFreeSlot=j;
                        GetNextSlot=false;
                        break;
                    }
                }
            }
            if ((i>currFreeSlot) &&(currFreeSlot!=-1))
            {
                ItemName=cn.GetItemAt(i);
                if (ItemName!="")
                {//Move this item to the free slot
                    cn.RemoveItemFromContainer(i);
                    cn.AddItemToContainer(ItemName,currFreeSlot);
                    GetNextSlot=true;
                    currFreeSlot=-1;
                }
            }
        }
    }

Usage Example

Exemplo n.º 1
0
    /*static public bool xAddObjectToContainer(GameObject objInHand, GameObject objUseOn)
     *   {
     *           Container subContainer = objUseOn.GetComponent<Container>();
     *           if (subContainer.AddItemToContainer(objInHand.name))
     *           {
     *                   Container ObjInHandContainer=objInHand.GetComponent<Container>();
     *                   if (ObjInHandContainer!=null)
     *                   {
     *                           subContainer=objInHand.GetComponent<Container>();
     *                           subContainer.ContainerParent=objUseOn.name;
     *                   }
     *                   return true;
     *           }
     *           else
     *           {
     *                   return false;
     *           }
     *   }*/

    public void OpenContainer()
    {
        playerUW.playerInventory.ContainerOffset = 0;
        ScrollButtonStatsDisplay.ScrollValue     = 0;
        ObjectInteraction currObjInt = this.gameObject.GetComponent <ObjectInteraction>();

        if (currObjInt.PickedUp == false)
        {                //The requested container is open in the game world. This can cause problems!
            //Debug.Log ("Opening a container in the real world");
            SpillContents();
            return;
        }
        //Sort the container
        Container.SortContainer(this);
        GameObject.Find("ContainerOpened").GetComponent <UITexture>().mainTexture = currObjInt.GetEquipDisplay().texture;
        if (this.isOpenOnPanel == false)
        {
            this.isOpenOnPanel = true;
            ContainerParent    = playerUW.playerInventory.currentContainer;
        }
        playerUW.playerInventory.currentContainer = this.name;
        if (playerUW.playerInventory.currentContainer == "")
        {
            playerUW.playerInventory.currentContainer = playerUW.name;
            this.ContainerParent = playerUW.name;
        }
        for (int i = 0; i < 8; i++)
        {
            string sItem = this.GetItemAt(i);
            playerUW.playerInventory.SetObjectAtSlot(i + 11, sItem);
        }
    }
All Usage Examples Of Container::SortContainer