private void SetSingleContentDataWhenHorizontal(ScrollData data) { data.CalculateSize(); //指定使用新行 if (data.newLine == ScrollLayout.NewLine.None) { //发生过偏移,并且这次物体的右边界超过宽度 if (cursorPos.y > border.y && cursorPos.y + data.height > Height - border.y) { //那么执行换行操作 cursorPos.y = border.y; cursorPos.x += maxHeight; maxHeight = 0; } //设置位置 data.SetAnchoredPosition(cursorPos + data.Size / 2); //更新光标 cursorPos.y += data.height; //更新最大宽度 if (maxWidth < cursorPos.y) { maxWidth = cursorPos.y; } //增加间隔 if (data.height > 0) { cursorPos.y += spacing.y; } //更新最大高度 var curMaxHeight = data.width > 0 ? (data.width + spacing.x) : 0; if (maxHeight < curMaxHeight) { maxHeight = curMaxHeight; } } else { //发生过偏移 if (cursorPos.y > border.y) { //换行 cursorPos.x += maxHeight; maxHeight = 0; } //指定使用新行 switch (data.newLine) { case ScrollLayout.NewLine.Center: cursorPos.y = Width / 2; break; case ScrollLayout.NewLine.LeftOrUp: cursorPos.y = data.height / 2 + border.y; break; case ScrollLayout.NewLine.RightOrDown: cursorPos.y = Width - data.width / 2 - border.y; break; } //设置位置 data.SetAnchoredPosition(cursorPos + data.width / 2 * Vector2.right); //换新行 cursorPos.y = border.y; cursorPos.x += data.width + spacing.x; } }
private void AlignScrollDataWhenVertical(ScrollData data) { data.CalculateSize(); if (data.newLine == ScrollLayout.NewLine.None) { //发生过偏移,并且这次物体的右边界超过宽度 if (cursorPos.x > border.x && cursorPos.x + data.width > Width - border.x) { //那么执行换行操作 cursorPos.x = border.x; cursorPos.y += maxHeight; maxHeight = 0; } //设置位置 data.SetAnchoredPosition(cursorPos + data.Size / 2); //更新光标 cursorPos.x += data.width; //更新最大宽度 if (maxWidth < cursorPos.x) { maxWidth = cursorPos.x; } //增加间隔 if (data.width > 0) { cursorPos.x += spacing.x; } //更新最大高度 float curMaxHeight = data.height > 0 ? (data.height + spacing.y) : 0; if (maxHeight < curMaxHeight) { maxHeight = curMaxHeight; } } else { //发生过偏移 if (cursorPos.x > border.x) { //换行 cursorPos.y += maxHeight; maxHeight = 0; } //指定使用新行 switch (data.newLine) { case ScrollLayout.NewLine.Center: cursorPos.x = Width / 2; break; case ScrollLayout.NewLine.LeftOrUp: cursorPos.x = data.width / 2 + border.x; break; case ScrollLayout.NewLine.RightOrDown: cursorPos.x = Width - data.width / 2 - border.x; break; } //设置位置 data.SetAnchoredPosition(cursorPos + data.height / 2 * Vector2.up); //换新行 cursorPos.x = border.x; cursorPos.y += data.height + spacing.y; } }