[ExecuteInEditMode] 和 [RequireComponent(typeof(UIRoot))]理解
来源:互联网 发布:关于淘宝规则的变更 编辑:程序博客网 时间:2024/05/16 00:47
/*
当我们为MonoBehavior定义了[ExecuteInEditMode]后,我们需要关心Awake和Start在编辑器中的执行状况。
1、当该MonoBehavior在编辑器中被赋于给GameObject的时候,Awake, Start 将被执行。
2、当Play按钮被按下游戏开始以后,Awake, Start 将被执行。
3、当Play按钮停止后,Awake, Start将再次被执行。
4、当在编辑器中打开包含有该MonoBehavior的场景的时候,Awake, Start将被执行。
*/
[ExecuteInEditMode]
[RequireComponent(typeof(UIRoot))]
ExecuteInEditMode 编辑模式调用Update
当我们为MonoBehavior定义了[ExecuteInEditMode]后,我们需要关心Awake和Start在编辑器中的执行状况。
1、当该MonoBehavior在编辑器中被赋于给GameObject的时候,Awake, Start 将被执行。
2、当Play按钮被按下游戏开始以后,Awake, Start 将被执行。
3、当Play按钮停止后,Awake, Start将再次被执行。
4、当在编辑器中打开包含有该MonoBehavior的场景的时候,Awake, Start将被执行。
*/
[ExecuteInEditMode]
[RequireComponent(typeof(UIRoot))]
//[RequireComponent (typeof (ClassName))] 就是在你把被这句话标记的类拖到(或者AddComponent)GameObject上时,自动再给你加上“ClassName”这个类
参考地址: [Unity3D]脚本中Start()和Awake()的区别http://www.cnblogs.com/xpvincent/p/3178042.html
http://tieba.baidu.com/p/2820568128
借用原文
[置顶] unity3D 功能脚本备忘【2】(属性)
原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 Unity3D引擎技术交流QQ群:【119706192】本文链接地址: unity3D 功能脚本备忘【2】(属性)
- unity3D 功能脚本备忘【1】(方法)
-------------------------------------------------------------割-------------------------------------------------------------------
编译器属性
属性介绍用例AddComponentMenu在Component菜单中添加新的菜单项[AddComponentMenu("Duan/Script/TestScript")]ContextMenu在当前脚本的组件中添加右键菜单内容 ExecuteInEditMode让当前脚本可以在运行模式中实时更新修改 HideInInspector是变量在检测时不被显示,但是会被实例化[HideInInspector]public int a;NonSerialized 标记一个变量不会被序列化? RPC RenderBeforeQueues附加一个自定义渲染 在整个引擎渲染队列之前 RequireComponent强制添加一个组件,(限定一定要有这个个组件),并且不能删除[RequireComponent(typeof(Rigidbody))]Serializable序列化一个类 (js继承Object类默认就是会被序列化) SerializeField序列化一个字段 (当unity序列你的脚本,它只会序列化公共字段。如果除了那些也想序列化私有字段,你可以添加SerializeField属性。)[SerializeField]private int a;
AddComponentMenu 添加组件菜单项
在编辑器添加一个用于添加组件的菜单项,将拥有该属性的脚本添加到选中的物体上。(用法:[AddComponentMenu("Duan/Script_Mobile/BreakAndEnd")])
例:在当前脚本中加入AddComponentMenu属性,选中某物体后,将拥有该属性的脚本添加到选中的物体上。
using UnityEngine;using System.Collections;/// <summary>/// 按返回退出应用 /// </summary>[AddComponentMenu("Duan/Script_Mobile/BreakAndEnd")]public class BreakAndEnd : MonoBehaviour {// Update is called once per framevoid Update () {endGame();}void endGame(){if ( Application.platform == RuntimePlatform.Android &&(Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home)) ) {//Home键好像不一定能用。。默认就是把程序挂到后台<span style="color: white; background-color: rgb(136, 0, 0);">,</span>并不是退出。 Application.Quit(); }}}
MenuItem 自定义菜单项
在编辑器添加一个自定义菜单项(用法:[MenuItem("DuanEditor/init Scenes")])
例:菜单项启动一个自定义的编辑器窗口(EditorWindow ),该窗口试用OnGUI布局。
using UnityEngine;using System.Collections;using UnityEditor;public class initScenes : EditorWindow{ [MenuItem("DuanEditor/init Scenes")] static void Init() { initScenes window = (initScenes)EditorWindow.GetWindow(typeof(initScenes)); window.Show(); } void OnGUI() { if (GUI.Button(new Rect(10<span style="color: white; background-color: rgb(136, 0, 0);">,</span>10<span style="color: white; background-color: rgb(136, 0, 0);">,</span>200<span style="color: white; background-color: rgb(136, 0, 0);">,</span>20)<span style="color: white; background-color: rgb(136, 0, 0);">,</span>"hello world")) { Debug.Log("hello world"); } }}
ExecuteInEditMode 编辑模式调用Update
[ExecuteInEditMode]写在类上方来通知编译器,该类的OnGUI和Update等函数在编辑模式也也会被调用
0 0
- [ExecuteInEditMode] 和 [RequireComponent(typeof(UIRoot))]理解
- AddComponentMenu ContextMenu ExecuteInEditMode HideInInspector NonSerialized RPC RequireComponent Se
- 销毁物体和ExecuteInEditMode
- ExecuteInEditMode
- NGUI深入理解-----------------UIRoot
- 深入理解javascript之typeof和instanceof
- javascript var和typeof用法理解
- UIRoot
- linux kernel中typeof和container_of的理解
- 自己不官方的理解typeof和instanceof
- js基础2-深入理解javascript之typeof和instanceof
- typeof的理解
- typedef和typeof
- typeof、undefined 和 null
- javaScript typeof 和数据类型
- Javascript typeof 和instanceof
- getType() 和Typeof()
- typeof 和 instanceof
- [ural1057]Amount of Degrees && 数位DP
- display:none; display:block; display:inline和display:inline-block;
- oracle 11g backupgroud process and archtecture
- $(document).ready()、 $(function(){})、$().ready(function(){})和window.onload的区别
- 杭电acm1004
- [ExecuteInEditMode] 和 [RequireComponent(typeof(UIRoot))]理解
- JavaScript导出到word、excel !!!
- 黑马程序员——Java基础---面向对象(封装、构造函数、this关键字)--第5天--第67-73集
- 刚刚接手的一个项目要用oracle数据库。把一些SQL SERVER2005的表导入过去以后发现查询时有问题,比如登陆时的查询
- C++复习题
- poj 1562(Deposits)水题(八连通)
- POJ1061 青蛙的约会 扩展欧几里得
- webx小结
- linux svn服务器启动停止命令