Пример #1
0
    protected virtual void CreateCellsOnGameObject(Inventory inven, GameObject parent)
    {
        int numCells;
        int end;

        Inventory.Slot.Range range;
        if (!inven)
        {
            numCells = this.GetNumCells();
            end      = 2147483647;
        }
        else
        {
            inven.GetSlotsOfKind(Inventory.Slot.Kind.Default, out range);
            numCells = range.Count;
            end      = range.End;
        }
        Array.Resize <RPOSInventoryCell>(ref this._inventoryCells, numCells);
        Vector3 component = this.CellPrefab.GetComponent <RPOSInventoryCell>()._background.transform.localScale;
        float   single    = component.x;
        Vector3 vector3   = this.CellPrefab.GetComponent <RPOSInventoryCell>()._background.transform.localScale;
        float   single1   = vector3.y;

        for (int i = 0; i < this.NumCellsVertical; i++)
        {
            for (int j = 0; j < this.NumCellsHorizontal; j++)
            {
                byte cellIndexStart = (byte)(this.CellIndexStart + RPOSInvCellManager.GetIndex2D(j, i, this.NumCellsHorizontal));
                if (cellIndexStart >= end)
                {
                    return;
                }
                GameObject        gameObject = NGUITools.AddChild(parent, this.CellPrefab);
                RPOSInventoryCell str        = gameObject.GetComponent <RPOSInventoryCell>();
                str._mySlot           = cellIndexStart;
                str._displayInventory = inven;
                if (this.NumberedCells)
                {
                    int index2D = RPOSInvCellManager.GetIndex2D(j, i, this.NumCellsHorizontal) + 1;
                    str._numberLabel.text = index2D.ToString();
                }
                gameObject.transform.localPosition = new Vector3((float)this.CellOffsetX + ((float)j * single + (float)(j * this.CellSpacing)), -((float)this.CellOffsetY + ((float)i * single1 + (float)(i * this.CellSpacing))), -2f);
                this._inventoryCells[RPOS.GetIndex2D(j, i, this.NumCellsHorizontal)] = gameObject.GetComponent <RPOSInventoryCell>();
            }
        }
        if (this.CenterFromCells)
        {
            if (this.NumCellsHorizontal > 1)
            {
                base.transform.localPosition = new Vector3((float)(this.CellOffsetX + this.NumCellsHorizontal * this.CellSize + (this.NumCellsHorizontal - 1) * this.CellSpacing) * -0.5f, (float)this.CellSize, 0f);
            }
            else if (this.NumCellsVertical > 1)
            {
                base.transform.localPosition = new Vector3((float)(-this.CellSize), (float)(this.CellOffsetY + this.NumCellsVertical * this.CellSize) * 0.5f, 0f);
            }
        }
    }
Пример #2
0
    protected virtual void CreateCellsOnGameObject(Inventory inven, GameObject parent)
    {
        int count;
        int end;

        if (inven != null)
        {
            Inventory.Slot.Range range;
            inven.GetSlotsOfKind(Inventory.Slot.Kind.Default, out range);
            count = range.Count;
            end   = range.End;
        }
        else
        {
            count = this.GetNumCells();
            end   = 0x7fffffff;
        }
        Array.Resize <RPOSInventoryCell>(ref this._inventoryCells, count);
        float x = this.CellPrefab.GetComponent <RPOSInventoryCell>()._background.transform.localScale.x;
        float y = this.CellPrefab.GetComponent <RPOSInventoryCell>()._background.transform.localScale.y;

        for (int i = 0; i < this.NumCellsVertical; i++)
        {
            for (int j = 0; j < this.NumCellsHorizontal; j++)
            {
                byte num7 = (byte)(this.CellIndexStart + GetIndex2D(j, i, this.NumCellsHorizontal));
                if (num7 >= end)
                {
                    return;
                }
                GameObject        obj2      = NGUITools.AddChild(parent, this.CellPrefab);
                RPOSInventoryCell component = obj2.GetComponent <RPOSInventoryCell>();
                component._mySlot           = num7;
                component._displayInventory = inven;
                if (this.NumberedCells)
                {
                    component._numberLabel.text = (GetIndex2D(j, i, this.NumCellsHorizontal) + 1).ToString();
                }
                obj2.transform.localPosition = new Vector3(this.CellOffsetX + ((j * x) + (j * this.CellSpacing)), -(this.CellOffsetY + ((i * y) + (i * this.CellSpacing))), -2f);
                this._inventoryCells[RPOS.GetIndex2D(j, i, this.NumCellsHorizontal)] = obj2.GetComponent <RPOSInventoryCell>();
            }
        }
        if (this.CenterFromCells)
        {
            if (this.NumCellsHorizontal > 1)
            {
                base.transform.localPosition = new Vector3((this.CellOffsetX + ((this.NumCellsHorizontal * this.CellSize) + ((this.NumCellsHorizontal - 1) * this.CellSpacing))) * -0.5f, (float)this.CellSize, 0f);
            }
            else if (this.NumCellsVertical > 1)
            {
                base.transform.localPosition = new Vector3((float)-this.CellSize, (this.CellOffsetY + (this.NumCellsVertical * this.CellSize)) * 0.5f, 0f);
            }
        }
    }