标签:system start 绑定 new pre eof 也会 one cti
using System;
using UnityEngine;
public class Foo:MonoBehaviour{
private void Awake(){
Debug.Log("Foo.Awake();");
}
private void OnEnable(){
Debug.Log("Foo.OnEnable();");
}
private void Start(){
Debug.Log("Foo.Start();");
}
}
using System;
using UnityEngine;
public class Test:MonoBehaviour{
public GameObject foo2;//Hierarchy面板中绑定Foo脚本的GameObject(未激活、在绑定Test脚本的GameObject上方)
private void Start(){
//Test1();
Test2();
}
private void Test1(){
GameObject fooGameObject=new GameObject("Foo",typeof(Foo));
//创建GameObject后即使立刻SetActive(false),绑定代码中的Awake与OnEnable函数也会触发
fooGameObject.SetActive(false);
/*output:
Foo.Awake();
Foo.OnEnable();
*/
Debug.Log("fooGameObject.SetActive(true); Start");
fooGameObject.SetActive(true);
Debug.Log("fooGameObject.SetActive(true); End");
//在SetActive(true)函数内调用OnEnable函数
/*output:
fooGameObject.SetActive(true); Start
Foo.OnEnable();
fooGameObject.SetActive(true); End
Foo.Start();
*/
}
private void Test2(){
Debug.Log("fooGameObject.SetActive(true); Start");
foo2.SetActive(true);
Debug.Log("fooGameObject.SetActive(true); End");
//在SetActive(true)函数内调用Awake与OnEnable函数
/*output:
fooGameObject.SetActive(true); Start
Foo.Awake();
Foo.OnEnable();
fooGameObject.SetActive(true); End
Foo.Start();
*/
}
}
标签:system start 绑定 new pre eof 也会 one cti
原文地址:https://www.cnblogs.com/kingBook/p/12870706.html