首页 > 其他 > 详细

【转】NGUI创建UIRoot后报NullReferenceException的解决办法

时间:2016-12-29 19:45:56      阅读:211      评论:0      收藏:0      [点我收藏+]

本文参考自 http://forum.china.unity3d.com/thread-1099-1-1.html

使用NGUI版本3.7.5。

在创建了一个UIRoot后,有时会报NullReferenceException的错误,如下图。虽然报错但是不影响运行。

技术分享

 

截取部分报错输出是

 

[html] view plain copy
 
  1. NullReferenceException: Object reference not set to an instance of an object  
  2. UIPanel.get_worldCorners () (at Assets/NGUI/Scripts/UI/UIPanel.cs:623)  
  3. UIPanelInspector.OnSceneGUI () (at Assets/NGUI/Scripts/Editor/UIPanelInspector.cs:87)  
  4. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)  
  5. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.  
  6. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at  


双击错误进入NGUI的UIPanel脚本,会定位到这段代码

 

 

[csharp] view plain copy
 
  1. if (anchorOffset && mCam == null || mCam.transform.parent != cachedTransform)  

 

 

将这段代码修改为下面的代码即可修复此错误

 

[csharp] view plain copy
 
    1. if (anchorOffset && (mCam == null || mCam.transform.parent != cachedTransform))  

【转】NGUI创建UIRoot后报NullReferenceException的解决办法

原文:http://www.cnblogs.com/mimime/p/6233976.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!