原文链接:https://blog.csdn.net/li1214661543/article/details/105437955?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-105437955-blog-143413519.235%5Ev43%5Epc_blog_bottom_relevance_base6&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-105437955-blog-143413519.235%5Ev43%5Epc_blog_bottom_relevance_base6&utm_relevant_index=12icon-default.png?t=O83Ahttps://blog.csdn.net/li1214661543/article/details/105437955?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-105437955-blog-143413519.235%5Ev43%5Epc_blog_bottom_relevance_base6&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-105437955-blog-143413519.235%5Ev43%5Epc_blog_bottom_relevance_base6&utm_relevant_index=12 如侵,联系,必删,谢谢

/// <summary>
/// 从一张大图中截取指定位置和大小的小图
/// </summary>
/// <param name="m_texPlayer">大图</param>
/// <param name="cur_x">开始截取的x位置</param>
/// <param name="cur_y">开始截取的y位置</param>
/// <param name="width">截取的宽度</param>
/// <param name="height">截取的高度</param>
/// <returns>返回截取后的小图</returns>
public Texture2D DePackTexture(Texture2D m_texPlayer, int cur_x, int cur_y, int width,int height)
{
    Texture2D newTexture=new Texture2D(width, height);
    for (int m = cur_y; m < height + cur_y; m++)
    { 
        for (int n = cur_x; n < width + cur_x; n++)
        {
            newTexture.SetPixel(n - cur_x, m - cur_y, m_texPlayer.GetPixel(n, m));
        }
    }
    newTexture.Apply();
    return newTexture;
}

Logo

分享前沿Unity技术干货和开发经验,精彩的Unity活动和社区相关信息

更多推荐