protected void UpdateLayout() { float contentWidth = sourceWidth; float contentHeight = sourceHeight; if (_autoSize) { _updatingLayout = true; if (contentWidth == 0) { contentWidth = 50; } if (contentHeight == 0) { contentHeight = 30; } SetSize(contentWidth, contentHeight); _updatingLayout = false; if (_width == contentWidth && _height == contentHeight) { _content.SetXY(0, 0); _content.SetScale(1, 1); InvalidateBatchingState(); return; } //如果不相等,可能是由于大小限制造成的,要后续处理 } float sx = 1, sy = 1; if (_fill != FillType.None) { sx = this.width / sourceWidth; sy = this.height / sourceHeight; if (sx != 1 || sy != 1) { if (_fill == FillType.ScaleMatchHeight) { sx = sy; } else if (_fill == FillType.ScaleMatchWidth) { sy = sx; } else if (_fill == FillType.Scale) { if (sx > sy) { sx = sy; } else { sy = sx; } } else if (_fill == FillType.ScaleNoBorder) { if (sx > sy) { sy = sx; } else { sx = sy; } } if (_shrinkOnly) { if (sx > 1) { sx = 1; } if (sy > 1) { sy = 1; } } contentWidth = sourceWidth * sx; contentHeight = sourceHeight * sy; } } _content.SetScale(sx, sy); float nx; float ny; if (_align == AlignType.Center) { nx = (this.width - contentWidth) / 2; } else if (_align == AlignType.Right) { nx = this.width - contentWidth; } else { nx = 0; } if (_verticalAlign == VertAlignType.Middle) { ny = (this.height - contentHeight) / 2; } else if (_verticalAlign == VertAlignType.Bottom) { ny = this.height - contentHeight; } else { ny = 0; } _content.SetXY(nx, ny); InvalidateBatchingState(); }