找回密码
 立即注册
查看: 142|回复: 0

Unity检测UI上的像素 判断颜色

[复制链接]
发表于 2022-12-3 16:17 | 显示全部楼层 |阅读模式
/***************************** * Title:         * Date:         2022.11.01 * Author:       玄策 * UnityVersion: 2022.1.21 * Func:               *  ****************************/using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class NewBehaviourScript : MonoBehaviour{    RenderTexture rt;  //RawImage上的RenderTexture    Texture2D texture;    Color color;    void Start()    {        StartCoroutine(CaptureScreenshot());    }    IEnumerator CaptureScreenshot()    {        while (true)        {            //只在每一帧渲染完成后才读取屏幕信息            yield return new WaitForEndOfFrame();            //RawImage上的RenderTexture            rt = GetComponent<RawImage>().texture as RenderTexture;            texture = new Texture2D(rt.width, rt.height, TextureFormat.ARGB32, false);            RenderTexture.active = rt;            texture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);            //RawImage上的trxture            //texture = GetComponent<RawImage>().texture as Texture2D;            texture.Apply();            color = texture.GetPixel((int)Input.mousePosition.x, (int)Input.mousePosition.y);            Debug.Log (                  color.r * 255 + ",       "                + color.g * 255 + ",       "                + color.b * 255 + ",       "                + color.a * 255);        }    }}
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-6-9 10:15 , Processed in 0.096974 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表