unity, Graphics.Blit (null, null, mat,0);

我使用

Graphics.Blit (null, finalRT, mat);

合成出一张finalRT,然后将finalRT用在editor脚本的OnInspector中使用

Graphics.DrawTexture(rect,finalRT,mat2);

进行绘制,结果发现inspector面板中finalRT显示结果是错的,而且在游戏场景中用到finalRT作为纹理的物体纹理也变错了。

但是如果我屏蔽掉Graphics.DrawTexture(rect,finalRT,mat2),则游戏场景中用finalRT作为纹理的对象不会变错,但是当然,我在inspector中就看不到finalRT的预览了。

通过试验发现,如果在Graphics.Blit (null, finalRT, mat)后面紧跟着加一句:

#if UNITY_EDITOR
        Graphics.Blit (null, null, mat,0);//if i want to draw finalRT with a shader in editor script, i must write this line, why?
# endif

则结果就正常了。

不知道为啥。

原文地址:https://www.cnblogs.com/wantnon/p/5442773.html