Skip to content

Instantly share code, notes, and snippets.

@smallrice45
Created July 4, 2015 13:29
Show Gist options
  • Save smallrice45/c39d579ecb10de71a69b to your computer and use it in GitHub Desktop.
Save smallrice45/c39d579ecb10de71a69b to your computer and use it in GitHub Desktop.
委託與監聽範本
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class DataManager : MonoBehaviour {
public delegate void DataLoaderHandler();
public event DataLoaderHandler onLoaderComplete;
void Start(){
DoSomething();
}
void DoSomething (){
OnLoaderComplete();
}
void OnLoaderComplete (){
if (onLoaderComplete != null){
onLoaderComplete ();
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class EventTriggerManager : MonoBehaviour {
private DataManager m_DataManager;
void Start(){
m_DataManager = GetComponent<DataManager>();
m_DataManager.onLoaderComplete += LoadDataToManager;
}
// Use this for initialization
public void LoadDataToManager () {
// DoSomething
Debug.Log("LoadDataToManager");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment