Unity3D中Awake和Start方式和方法的区别别

【好羞涩嘢】Update Start Awake的专业术语叫做什么【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:74,033贴子:
求学要严谨.Update Start Awake是我们每天都在用的, 但是他们在Unity的专业术语中到底叫什么?Message? 回调? 还是事件? 还是其他的叫法?另外, Unity的工作原理中, 到底是用什么方式调用Update的? 是SendMessage这种? 还是Observer? 还是反射? 还是其他的调用方法?
Unity3D会把C#之类的解释称IL,在这个过程中会做出处理。说白了,既不是通过回调,也不是事件。是一个内部的机制。楼主可以参考下这个博客。
HOW UPDATE IS CALLEDNo, Unity doesn’t use System.Reflection to find a magic method every time it needs to call one.Instead, the first time a MonoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either Mono or IL2CPP) whether it has any magic methods defined and this information is cached. If a MonoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.During the game Unity just iterates through these lists and executes methods from it — that simple. Also, this is why it doesn’t matter if your Update method is public or private.这是博客里的原文
Update是如何被调用的不,Unity没有在每次调用的时候用System.Reflection来搜索这些神奇的方法。当Unity解析你的继承自MonoBehaviour的脚本时,会把诸如Update这样的函数做一个缓存(如果你定义了的话)。这样当每次Unity想要调用这些神奇的方法时,只是简单的遍历它内部缓存用的数组,就是这么简单!也正是这样,无论这些方法是private还是public,Unity都可以正确的调用它。感觉不少人有这个问题,就翻译了一下。说不上是翻译,就是按自己的理解复述了一下
登录百度帐号推荐应用当前位置: >
Awake()跟Start()差在哪?
时间: 08:59 来源:互联网 作者:脚印 浏览:
刚开始学Unity的时候,最难搞定的就是这两个functions的差异,依照官方文件所描述的:Awake(): Awake is called when the script instance is being loaded.Start(): Start is called just before any of the Update methods is called the first time.习惯C++人来说,这根本是“小三”的颠倒!为什么要这样分搞不懂。后来写久了遇到问题了才了解原来继承MonoBehaviour的class:Awake() == C++的Construct进一步想,我们在写C++的class时,不也有时候会自己写Init()的Member Fucntion吗?所以Start()也可想成自订的Init()就好!在使用上的基本原则就是,如果你有class的member参考其它Component,就在Awake里设定好,例如:&protected&void&Awake&()&
  thisTrans&=&
  item&=&GetComponent();
}这是确保当我们在Start()里需要呼叫member所参考component中的function时,这个参考已经建立而非NULL。当然你也可以说你在Start()的一开始先做GetComponent的动作,这也是OK的。不过开发到后来系统class彼此间的连结越来越强时,因该就会慢慢体会到Awake()的重要,因为Unity里物件的建立顺序无法控制,所以保险一点还是将GetComponent这件事留在Awake比较好一点。
(责任编辑:脚印)
免责声明:Unity之家部分内容来源于互联网,如有侵权,请联系我们,本站将立即进行处理。
猜你也喜欢看这些 ??????
其他类型的Unity入门 ??????鏌ョ湅: 3481|鍥炲?: 12
Unity涓瑼wake鍜孲tart鏈変粈涔堝尯鍒?紵
褰撳墠绂荤嚎
涓婚?甯栧瓙璐$尞
鐢垫?鐩磋揪
& & 绗?竴娆℃帴瑙?nity鏃讹紝涓嶇悊瑙h繖涓や釜鍑芥暟鍒板簳鏈変綍鍖哄埆锛屼互涓嬫槸瀹樻柟鏂囨。鐨勮В閲婏細
Awake[size=0.875em]() Awake is called when the script instance is being loaded.
[size=0.875em]Start() Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
Awake()鏄?敤鏉ュ垵濮嬪寲娓告垙涓?殑鍙橀噺鐨勶紝鐩稿綋浜庢瀯閫犲櫒鐨勫姛鑳斤紝Awake涓嶈兘澶熶娇鐢ㄥ崗鍚屻

我要回帖

更多关于 方法重载和重写的区别 的文章

 

随机推荐