MonoBehavior lifecycle

awake 只调用一次, awake在所有obj都初始化之后被调用.
      用途:
        初始化游戏状态
          设置脚本间的引用
          

### ExecuteInEditMode 编辑模式下
```
这个模式下,脚本编译,会自动reload

[ExecuteInEditMode]
public class LifecycleTest : MonoBehaviour {}

When new component (this script) is added: Awake(), OnEnable(), Reset(), Start()
When scene is saved (CTRL+S): nothing happens but here you may see those irritating info messages
When scene is unloaded: OnDisable(), OnDestroy()
When scene is loaded: Awake(), OnEnable(), Start()
When script is modified: OnDisable(), OnEnable()
```

Awake - OnDestory
OnEnable - OnDisable

Awake只执行一次, 
OnEnable OnDisable会执行多次(reload script的时候), awake里初始化的实例将会丢失(如果没有重新加载场景的话), 报错NullReferenceExceptions

### 游戏模式
1 编辑状态,什么都不执行
2 点play之后, Awake, OnEnble, Start
3 stop后, OnDisable, Destory



### 泄露
动态创建一个材质(material)后,不添加到任何一个渲染对象身上, 被称为leaked

使用hideFlags
 material.hideFlags = HideFlags.DontSave;
 一定要这样删除
 DestroyImmediate(HideFlags)
 

转载于:https://www.cnblogs.com/lightlfyan/p/4236271.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值