Render Texture在Android下的异常渲染问题--最终用动态生成Render Texture解决

今天出现了一个奇怪的问题,人物角色在UI上的显示,采用的是Render Texture方案。在PC上正常,但在Android下的渲染异常(不显示)。

尝试改了兼容性比较好的色彩模式(如下图),也不行。最后动态生成Render Texture,可以了。我没有搞明白这是为什么,如果有明白的朋友,请不吝赐教。

改了参数也不行

下面是动态生成Render Texture

动态生成的代码,根据你项目适当修改即可:

cs 复制代码
using UnityEngine.UI;


public class DynamicRenderTexture_Role : MonoBehaviour
{
    // 获取 RawImage 组件并应用 Render Texture
    public RawImage rawImage;

    // 最新更改为动态生成 Render Texture
    [Header("动态生成--RenderTexture")]
    public int textureWidth = 1024;
    public int textureHeight = 1024;
    // 格式, RenderTextureFormat.ARGB32 或 RenderTextureFormat.Default 
    // 貌似都是 [ R8B8G8A8_UNORM ]
    public RenderTextureFormat textureFormat = RenderTextureFormat.Default;  
    public RenderTexture renderTexture;
    public Camera cam;


    void Start()
    {
        // ---------- 用于动态生成 RT ---------
        // 动态找相机
        cam = GameObject.Find("Camera_For_RT").GetComponent<Camera>();
        // 创建 Render Texture
        renderTexture = new RenderTexture(textureWidth, textureHeight, 16, textureFormat);
        renderTexture.Create();
        // 将 Render Texture 附加到像机
        cam.targetTexture = renderTexture;
        // 将其应用到UI
        if (rawImage != null)
        {
            rawImage.texture = renderTexture;
        }
        // ----------------------------------
    }

    void OnDisable()
    {
        // 清理 Render Texture
        if (renderTexture != null)
        {
            renderTexture.Release();
            renderTexture = null;
        }
    }
}
相关推荐
似霰2 小时前
传统 Hal 开发笔记6----App 访问硬件服务
android·framework·hal
爱装代码的小瓶子2 小时前
【c++知识铺子】封装map和set(详细版)
android·java·c++
私人珍藏库2 小时前
AutoGLM无需豆包手机,让AI自动帮你点外卖-刷视频
android·ai·智能手机·工具·软件·辅助·autoglm
孤舟簔笠翁3 小时前
【Android驱动14】Android系统Crash工具使用方法和分析
android
帅得不敢出门4 小时前
MTK Android11 APP调用OTA升级
android·java·开发语言·framework
2501_915909064 小时前
苹果应用加密方案的一种方法,在没有源码的前提下,如何处理 IPA 的安全问题
android·安全·ios·小程序·uni-app·iphone·webview
用户2018792831674 小时前
Android App 换肤原理:用 "装修小房子" 故事浅谈
android
百锦再4 小时前
与AI沟通的正确方式——AI提示词:原理、策略与精通之道
android·java·开发语言·人工智能·python·ui·uni-app
2501_915909064 小时前
iOS 项目中常被忽略的 Bundle ID 管理问题
android·ios·小程序·https·uni-app·iphone·webview