当前位置: 首页> 文旅> 美景 > 云服务器官网_兰州网站排名哪家公司好_淘宝运营团队怎么找_谷歌seo综合查询

云服务器官网_兰州网站排名哪家公司好_淘宝运营团队怎么找_谷歌seo综合查询

时间:2025/7/13 0:07:26来源:https://blog.csdn.net/weixin_43796392/article/details/147384295 浏览次数:0次
云服务器官网_兰州网站排名哪家公司好_淘宝运营团队怎么找_谷歌seo综合查询

思路

创建全屏大小纹理,类型为TextureFormat.RGBA32。
创建纹理数组,大小为屏幕大小的4倍。
修改纹理数组数据,纹理应用修改后的数据。

示例

using UnityEngine;
using UnityEngine.UI;
public class TestTextureChange : MonoBehaviour
{[SerializeField] RawImage image;Texture2D texture;byte[] textureData;private void Awake(){texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGBA32, false);texture.filterMode = FilterMode.Point;texture.wrapMode = TextureWrapMode.Clamp;image.texture = texture;textureData = new byte[Screen.width * Screen.height * 4];texture.LoadRawTextureData(textureData);texture.Apply(false);}private void Update(){if (Input.GetMouseButtonDown(0)){       var xLength = Random.Range(0, Screen.width);var yLength = Random.Range(0, Screen.height);Color color = Color.white;color.r = Random.Range(0f, 1f);color.g = Random.Range(0f, 1f);color.b = Random.Range(0f, 1f);FillColor(xLength, yLength, color);}if (Input.GetMouseButtonUp(0))FillColor(Screen.width, Screen.height, Color.clear);}void FillColor(int x, int y, Color32 color){for (int i = 0; i < x; i++){for (int j = 0; j < y; j++)SetPixelColor(i, j, color);}texture.LoadRawTextureData(textureData);texture.Apply(false);}void SetPixelColor(int x, int y, Color32 color){if (x < 0 || y < 0 || x >= texture.width || y >= texture.height){return;}else{int index = (texture.width * y + x) * 4;textureData[index++] = color.r;textureData[index++] = color.g;textureData[index++] = color.b;textureData[index] = color.a;}}
}

层级结构

在这里插入图片描述

运行结果

在这里插入图片描述
按下鼠标左键,显示一个纯色矩形。
松开鼠标左键,清除纯色矩形。

知识

TextureFormat.RGBA32

橡皮檫制作思路

使用透明颜色,修改纹理数组。

关键字:云服务器官网_兰州网站排名哪家公司好_淘宝运营团队怎么找_谷歌seo综合查询

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: