Exemplo n.º 1
0
 public Layout StartCorner(GridLayoutGroup.Corner startCorner)
 {
     if (layoutGroup is GridLayoutGroup glg)
     {
         glg.startCorner = startCorner;
     }
     else
     {
         Debug.LogError("Call Grid() before StartCorner()");
     }
     return(this);
 }
Exemplo n.º 2
0
        public static DialogGUIGridLayout GUIGridLayout(RectOffset padding, Vector2 cellSize, Vector2 spacing,
                                                        GridLayoutGroup.Corner startCorner, GridLayoutGroup.Axis startAxis, TextAnchor childAligment,
                                                        GridLayoutGroup.Constraint constraint, Int32 constraintCount, Action optionBuilder, Modifier <DialogGUIGridLayout> modifier = null)
        {
            DialogGUIGridLayout element = new DialogGUIGridLayout(padding, cellSize, spacing, startCorner, startAxis,
                                                                  childAligment, constraint, constraintCount, Declare(optionBuilder));

            if (modifier != null)
            {
                element = modifier(element);
            }
            _elements.Add(element);
            return(element);
        }
Exemplo n.º 3
0
 public void SetGridGroup(GridLayoutGroup grid, RectOffset offset, Vector2 size, Vector2 space, int count,
                          GridLayoutGroup.Constraint constr = GridLayoutGroup.Constraint.Flexible,
                          GridLayoutGroup.Corner starC      = GridLayoutGroup.Corner.UpperLeft
                          , TextAnchor childA = TextAnchor.UpperLeft, GridLayoutGroup.Axis starA = GridLayoutGroup.Axis.Horizontal
                          )
 {
     if (!isHaveUIGrid)
     {
         Debug.Log("not set grid");
         return;
     }
     Debug.Log("set grid");
     grid.padding        = offset;
     grid.cellSize       = size;
     grid.spacing        = space;
     grid.startCorner    = starC;
     grid.startAxis      = starA;
     grid.childAlignment = childA;
     grid.constraint     = constr;
     if (constr == GridLayoutGroup.Constraint.FixedColumnCount)
     {
         grid.constraintCount = count;
     }
 }
Exemplo n.º 4
0
    private int CaculateDataIndex(Vector2Int rowColumnIndex, Vector2Int rowColumnSize, GridLayoutGroup.Axis startAxis, GridLayoutGroup.Corner startCorner)
    {
        // for row column index
        // for temp row column indes
        // x -> index on horizontal axis
        // y -> index on vertical axis

        // for row column size
        // x -> element amount on horizontal axis
        // y -> element amount on vertical axis

        // tempIndex and rowColumn size are all start from topLeft
        int result = 0;

        if (startAxis == GridLayoutGroup.Axis.Horizontal)
        {
            switch (startCorner)
            {
            case GridLayoutGroup.Corner.UpperLeft:
                result = rowColumnIndex.y * rowColumnSize.x + rowColumnIndex.x;
                break;

            case GridLayoutGroup.Corner.LowerLeft:
                result = (rowColumnSize.y - rowColumnIndex.y - 1) * rowColumnSize.x + rowColumnIndex.x;
                break;

            case GridLayoutGroup.Corner.UpperRight:
                result = rowColumnIndex.y * rowColumnSize.x + rowColumnSize.x - rowColumnIndex.x - 1;
                break;

            case GridLayoutGroup.Corner.LowerRight:
                result = (rowColumnSize.y - rowColumnIndex.y - 1) * rowColumnSize.x + rowColumnSize.x - rowColumnIndex.x - 1;
                break;

            default:
                Debug.LogError("start corner type error", this.gameObject);
                break;
            }
        }
        else //if (startAxis == GridLayoutGroup.Axis.Vertical)
        {
            switch (startCorner)
            {
            case GridLayoutGroup.Corner.UpperLeft:
                result = rowColumnIndex.x * rowColumnSize.y + rowColumnIndex.y;
                break;

            case GridLayoutGroup.Corner.LowerLeft:
                result = rowColumnIndex.x * rowColumnSize.y + rowColumnSize.y - rowColumnIndex.y - 1;
                break;

            case GridLayoutGroup.Corner.UpperRight:
                result = (rowColumnSize.x - rowColumnIndex.x - 1) * rowColumnSize.y + rowColumnIndex.y;
                break;

            case GridLayoutGroup.Corner.LowerRight:
                result = (rowColumnSize.x - rowColumnIndex.x - 1) * rowColumnSize.y + rowColumnSize.y - rowColumnIndex.y - 1;
                break;

            default:
                Debug.LogError("start corner type error", this.gameObject);
                break;
            }
        }

        return(result);
    }