Exemplo n.º 1
0
 private void DestroyChild()
 {
     GameObject.Destroy(child);
     week.RemoveListeners();
     week = null;
     // GC 会在任意时刻调用, ~TestInst 被调用
 }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     if (!isInitialid)
     {
         isInitialid = true;
         child       = new GameObject("Child");
         EventTest test = child.AddComponent <EventTest>();
         test.AddEvent();
         InvokeRepeating("Send", 2, 2);
         Invoke("DestroyChild", 5);
         week = new TestInst();
         week.AddListeners();
         // 实际上,这里还是会调用 week 注册的事件
         // 一定要 注销事件
         // week = null;
     }
 }