本文整理匯總了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();
}