拿来吧你~
🦪功能介绍
💡不通过Texture2D 而是通过ComputerShader 提取到RenderTexture的像素值,效率有提升哦!
💡通过扩展方法调用,方便快捷:xxxRT.GetPixel
💡传送门👈
🌭Demo
csharp
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_SYSTEM
var mPos = Input.mousePosition;
#else
var mPos = Mouse.current.position.value;
#endif
var 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();
}
}
}