当前位置: 首页>>代码示例>>C#>>正文


C# Rect.Intersect方法代码示例

本文整理汇总了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();
        }
开发者ID:Skybladev2,项目名称:TacticalRPG,代码行数:41,代码来源:GenericImageExtendionMethodsForUnity.cs


注:本文中的UnityEngine.Rect.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。