在编辑器环境下OK,打包成PC客户端也OK,但是打包成 apk,在 安卓 手机上运行的时候就会有残留。
我的代码如下。主要是在 LateUpdate() 中,修改特定摄像机的 cullmask,在捕捉到制定的 rendertexture 上(即此处的 m_levelUnitRT)。
void LateUpdate() { if (m_levelUnitRT != null) { var camera = CoolGame.fguiSystem.stageCamera; var oldCullingMask = camera.cullingMask; m_levelUnitRT.DiscardContents(); camera.cullingMask = LayerMask.GetMask("LevelUnit"); camera.targetTexture = m_levelUnitRT; camera.Render(); camera.targetTexture = null; camera.cullingMask = oldCullingMask; } }
private void _InitLevelUnitRT()
{
m_levelUnitRT = new RenderTexture(Screen.width / 2, Screen.height / 2, 24, RenderTextureFormat.ARGB32);
m_levelUnitRT.name = "LevelUnitRT";
m_levelUnitRT.Create();
cellBorder.texture = m_levelUnitRT;
cellShadow.texture = m_levelUnitRT;
}
解决方法
if (m_levelUnitRT != null)
{
var camera = CoolGame.fguiSystem.stageCamera;
var oldCullingMask = camera.cullingMask;
var oldClearFlags = camera.clearFlags;
m_levelUnitRT.DiscardContents();
camera.cullingMask = LayerMask.GetMask("LevelUnit");
camera.targetTexture = m_levelUnitRT;
camera.clearFlags = CameraClearFlags.SolidColor;
camera.Render();
camera.targetTexture = null;
camera.cullingMask = oldCullingMask;
camera.clearFlags = oldClearFlags;
}
在 camera.Render() 前将 clearFlags 修改成 CameraClearFlags.SolidColor。
参考了:https://forum.unity.com/threads/rendertexture-bug-on-android.814599/
标签:Render,安卓,texture,DiscardContents,camera,var,levelUnitRT,cullingMask From: https://www.cnblogs.com/bakabird/p/18013114/unity_rendertexture_notclear