private IEnumerable <Texture2D> SplitVertical(Texture2D source, int maxSize) { var splitCount = SplitHelper.GetSplitCount(source.height, maxSize); if (splitCount > 1) { var partHeight = Mathf.FloorToInt((float)source.height / splitCount); for (var i = 0; i < splitCount; i++) { if (i == splitCount - 1) { var commonSplitHeight = partHeight * i; partHeight = source.height - commonSplitHeight; } var rect = new Rect(0.0f, i * partHeight, source.width, partHeight); var texture = GetTextureByRect(source, rect); texture.name = SplitHelper.GetSplittedTextureName(i, source.name); yield return(texture); } } else { yield return(source); } }
private IEnumerable <Texture2D> SplitHorizontal(Texture2D source, int maxSize) { var splitCount = SplitHelper.GetSplitCount(source.width, maxSize); if (splitCount > 1) { var partWidth = Mathf.FloorToInt((float)source.width / splitCount); for (var i = 0; i < splitCount; i++) { var rect = new Rect(i * partWidth, 0.0f, partWidth, source.height); if (i == splitCount - 1) { var commonSplitWidth = partWidth * i; partWidth = source.width - commonSplitWidth; rect = new Rect(commonSplitWidth, 0.0f, partWidth, source.height); } var texture = GetTextureByRect(source, rect); texture.name = SplitHelper.GetSplittedTextureName(i, source.name); yield return(texture); } } else { yield return(source); } }