今天遇到一个问题,就是自己用UITexture和Shader实现的一个效果。在有的UI界面上正常显示,但是在有的UI界面上Shader的效果并未显示,但是在UITexture的信息中包含该Shader且正确。最后查了一番,发现是因为控件在NGUI的ScrollView中导致的。
解决方法是,在UIDrawCall.cs文件中的CreateMaterial()方法中添加一句即可,如下
if (panel != null && panel.clipping == Clipping.TextureMask)
{
mTextureClip = true;
shader = Shader.Find("Hidden/" + shaderName + textureClip);
}
else if (mClipCount != 0)
{
shader = Shader.Find("Hidden/" + shaderName + " " + mClipCount);
if (shader == null) shader = Shader.Find(shaderName + " " + mClipCount);
// Legacy functionality
if (shader == null && mClipCount == 1)
{
mLegacyShader = true;
shader = Shader.Find(shaderName + soft);
}
}
else shader = Shader.Find(shaderName);
//新增,检测是否使用自定义Shader
if(shader == null) {
shader = Shader.Find(shaderName);
}
// Always fallback to the default shader
if(shader == null) shader = Shader.Find("Unlit/Transparent Colored");
本文解决了在Unity UI系统NGUI中,特定条件下Shader效果未能正常显示的问题。通过修改UIDrawCall.cs文件中的CreateMaterial()方法,确保了无论UI控件位于何处,自定义Shader都能正确应用。
425

被折叠的 条评论
为什么被折叠?



