• Unity CombineTexture


    public Texture2D CombineTexture(Texture2D background, Texture2D top)
        {
            int width = background.width;
            int height = background.height;
            Texture2D ret = new Texture2D(width, height);
            for(int x = 0; x < width; x++)
            {
                for(int y = 0; y < height; y++)
                {
                    ret.SetPixel(x, y, background.GetPixel(x, y));
                }
            }
    
            int topWidth = top.width;
            int topHeight = top.height;
            int x_start = width / 2 - topWidth / 2;
            int y_start = height / 2 - topHeight / 2;
    
            for (int x = x_start; x < topWidth + x_start; x++)
            {
                for (int y = y_start; y < topHeight + y_start; y++)
                {
                    Color bgColor = background.GetPixel(x, y);
                    Color topColor = top.GetPixel(x - x_start, y - y_start);
                    ret.SetPixel(x, y, Color.Lerp(bgColor, topColor, topColor.a/1f));
                }
            }
            ret.Apply();
            return ret;
        }

    tip: the background and top texture need can readable.

  • 相关阅读:
    python学习之模块补充二
    MySQL的表关系
    初识数据库
    MySQL基础
    死锁 递归锁 信号量 Event事件 线程q
    进程池/线程池与协程
    线程
    进程相关知识点
    python 之多进程
    socket 基础
  • 原文地址:https://www.cnblogs.com/lurenjiashuo/p/unity-CombineTexture.html
Copyright © 2020-2023  润新知