二丶untiy基础 4 生命周期(也是脚本流程)

1.官方脚本生命周期(地址
一下周期顺序以2019 版为标准周期(来源于官网图片地址)
在这里插入图片描述
这里上面一张图是生命周期
一一讲解一下用法(做一个脚本体现一下)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    private void Awake()
    {
        Debug.Log("Awake="+this.name);
    }

    private void OnEnable()
    {
        Debug.Log("OnEnable=" + this.name);
    }

    private void Reset()
    {
        Debug.Log("Reset=" + this.name);
    }
    private void Start()
    {
        Debug.Log("Start=" + this.name);
    }

    private void FixedUpdate()
    {
        Debug.Log("FixedUpdate=" + this.name);

    }

    private void Update()
    {
        Debug.Log("Update=" + this.name);
    }

    private void OnDrawGizmos()
    {
        Debug.Log("OnDrawGizmos=" + this.name);
    }

    private void OnGUI()
    {
        Debug.Log("OnGUI =" + this.name);
    }

    private void OnApplicationPause(bool pause)
    {
        Debug.Log("pause == "+ pause+" * " + this.name);
    }

    private void OnApplicationQuit()
    {
        Debug.Log("OnApplicationQuit == " + this.name);
    }

    private void OnDisable()
    {
        Debug.Log("OnDisable == " + this.name);
    }

    private void OnDestroy()
    {
        Debug.Log("OnDestroy == " + this.name);
    }
}

上面是测试代码,避开了来的API 生命周期Game和Event两个流程
在这里插入图片描述
测试出来结果(启动到销毁)
以上可以看出来
(来自官方解读–附上解释)
Awake: Called when the Editor is woken up.(销毁后,当场景重新加载都会执行)
上面的只跑一次的只要销毁跳转页面都会走一个完整的流程–创建 --到销毁
这个与场景加载方式和模式有关
模式:LoadSceneMode.Additive (原有的基础添加场景),LoadSceneMode.Single(销毁当前跳转新的)
加载方式:四种
上面测试使用的方法时这个: SceneManager.LoadScene(“xx场景名称”,LoadSceneMode.Single);
补充一:
使用页面跳转需要添加包 :using UnityEngine.SceneManagement;

中间有几个方法是一直执行的所有比如有什么操作可以在这些内部循环操作的地方,实现常用操作,但不能使用耗时操作,耗时可以开启协程等操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值