本文整理汇总了C#中UnityEngine.Rect.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Intersect方法的具体用法?C# Rect.Intersect怎么用?C# Rect.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rect
的用法示例。
在下文中一共展示了Rect.Intersect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
/// <summary>
/// Draws a <see cref="GenericImage{T}"/> on to a <see cref="Texture2D"/> texture.
/// </summary>
/// <param name="texture">A reference to a <see cref="Texture2D"/> type.</param>
/// <param name="sourceImage">A reference to the <see cref="GenericImage{T}"/> that will be drawn.</param>
/// <param name="x">The x position where the <see cref="sourceImage"/> will be drawn.</param>
/// <param name="y">The y position where the <see cref="sourceImage"/> will be drawn.</param>
/// <param name="sourceX">The source x position within <see cref="sourceImage"/>.</param>
/// <param name="sourceY">The source y position within <see cref="sourceImage"/>.</param>
/// <param name="sourceWidth">The source width within the <see cref="sourceImage"/>.</param>
/// <param name="sourceHeight">The source height within the <see cref="sourceImage"/>.</param>
/// <param name="flipHorizontally">If true will flip the <see cref="sourceImage"/> horizontally before drawing.</param>
/// <param name="flipVertically">If true will flip the <see cref="sourceImage"/> vertically before drawing.</param>
public static void Draw(this Texture2D texture, GenericImage<Color> sourceImage, int x, int y, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool flipHorizontally, bool flipVertically)
{
var textureRectangle = new Rect(0, 0, texture.width, texture.height);
var sourceRectangle = new Rect(x, y, sourceWidth, sourceHeight);
var intersect = textureRectangle.Intersect(sourceRectangle);
if (!intersect.Intersects(new Rect(0, 0, sourceImage.Width, sourceImage.Height)))
{
return;
}
var tempImage = new GenericImage<Color>((int)intersect.width, (int)intersect.height);
tempImage.Draw(sourceImage, 0, 0, sourceX, sourceY, tempImage.Width, tempImage.Height, (source, blendWith) => blendWith);
if (flipHorizontally)
{
tempImage.FlipHorizontally();
}
if (flipVertically)
{
tempImage.FlipVertically();
}
var colors = tempImage.ToUnityColorArray();
texture.SetPixels(x, y, (int)intersect.width, (int)intersect.height, colors);
texture.Apply();
}