拿来吧你~
- 🦪功能介绍
- 🌭Demo
🦪功能介绍
💡不通过Texture2D 而是通过ComputerShader 提取到RenderTexture的像素值,效率有提升哦!
💡通过扩展方法调用,方便快捷:xxxRT.GetPixel
💡传送门👈
🌭Demo
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
namespace ZYF
{public class GetRTPixelDemo : MonoBehaviour{public RenderTexture rt;public UnityEvent<Color> onGetColor;private void Update(){
#if !ENABLE_INPUT_SYSTEMvar mPos = Input.mousePosition;
#elsevar mPos = Mouse.current.position.value;
#endifvar pos = new Vector2Int((int)mPos.x, (int)mPos.y);var color= rt.GetPixel(new GetRTPixelExtension.RequestInfo(pos));onGetColor?.Invoke(color);}private void OnDestroy(){rt?.EndGetPixel();}}}