Exemple #1
0
    static int LayoutComplete(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        ScrollRect obj = LuaScriptMgr.GetUnityObject <ScrollRect>(L, 1);

        obj.LayoutComplete();
        return(0);
    }
Exemple #2
0
    private void Init(bool repos = true)
    {
        if (initDone)
        {
            return;
        }

        initDone = true;

        if (mScrollRect == null)
        {
            mScrollRect = transform.GetComponentInParent <ScrollRect>();
        }

        if (mScrollRect == null)
        {
            Debug.LogError("Can't find the ScrollRect");
            return;
        }

        mScrollRect.onValueChanged.AddListener(OnValueChanged);
        mScrollRect.LayoutComplete();

        originContentPosX = rectTransform.transform.localPosition.x;
        originContentPosY = rectTransform.transform.localPosition.y;

        float oneSize = 0;

        if (Changeable)
        {
            oneSize = MinCellSize;
            switch (ConstraintType)
            {
            case Constraint.FixedRowCount:
                oneSize += Spacing.x;
                break;

            case Constraint.FixedColumnCount:
                oneSize += Spacing.y;
                break;
            }

            ConstraintCount = 1;
        }
        else
        {
            switch (ConstraintType)
            {
            case Constraint.FixedRowCount:
                oneSize = CellSize.x + Spacing.x;
                break;

            case Constraint.FixedColumnCount:
                oneSize = CellSize.y + Spacing.y;
                break;
            }
        }

        if (ViewPortValue <= 0)
        {
            switch (ConstraintType)
            {
            case Constraint.FixedRowCount:
                ViewPortValue = mScrollRect.viewport.rect.size.x;
                break;

            case Constraint.FixedColumnCount:
                ViewPortValue = mScrollRect.viewport.rect.size.y;
                break;
            }
        }

        maxCount  = Mathf.CeilToInt(ViewPortValue / oneSize) + 1;
        GridItems = new FastGridItem[maxCount * ConstraintCount];

        if (repos)
        {
            Reposition();
        }

        enabled = false;
    }