Unity基本流程

Unity运行模型

class UnityEnginexxx
{
    public static void Main()
    {
        Init();  //初始化
        LoadFirstScene();  //加载首个场景
        List<MonoBehaviour> list = new List<MonoBehaviour>();
        
        foreach (GameObject gameobject in scene)
        {
            var s = gameobject.GetComponents<MonoBehaviour>();  //加载场景中的对象(无序)的组件列表(无序)
            if (s != null)
            {
                list.AddRange(s);
            }
        }

        //awake:初始化内容
        foreach (var monoBehaviour in list)
        {
            monoBehaviour.Awake();
        }

        //start:引用信息
        foreach (var monoBehaviour in list)
        {
            monoBehaviour.Start();
        }

        //update:主循环中的每一轮,可以称为一般意义上的“游戏中的一帧"。
        while (true)
        {
            //读取用户输入,进行处理
            //动画系统

            //开发者逻辑:Engine.logic();
            foreach (var monoBehaviour in list)
            {
                monoBehaviour.Update();  //各组件内部逻辑
            }

            //渲染
            Engine.render();
			
			if(exit)   break;
        }
        exit();
    }
}

  对于开发者来说,有了游戏引擎,所需要做的事情就是实现游戏引擎暴露出来的各种接口/回调。

  logic()和render()可以在两个独立的线程中并发执行,渲染当前帧的同时,计算下一帧.

脚本组件逻辑

public class NewBehaviourScript : MonoBehaviour
{
    private int _aa;
  
    [SerializeField]  //令私有变量可在unity editor中被调节
    [Tooltip("怪物")]  //在unity editor中显示的注释
    private GameObject _monster;

    public NewBehaviourScript xxx;  //可在Unity Editor的Inspector窗口中进行拖动赋值

    [Tooltip("怪物aa1")]
    public GameObject Monster1;
    public GameObject Monster2;

    void Awake()
    {
        Transform t = transform.Find("Cell (1)/Cell (5)");  //获取子项的子项的transform组件,层级结构,通过路径定位
        bb = t.GetComponent<BoxCollider>();  //实际为t.GameObject.GetComponent<BoxCollider>();  因为t和t.GameObject的对应关系具有唯一性,所以省略了GameObject
    }

    public BoxCollider bb;

    // Start is called before the first frame update
    void Start()
    {
        Test22(10);
        _aa = 10;
        int I = 0;
        int j = I + 10;

        _monster =  GameObject.Find("Monster");
    }

    private void Test22(int i)
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        //watch

        //make decision

        //act
        transform.position = _monster.transform.position + d;
        Monster1.gameObject.transform
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值