EventsManager
< 返回列表时间: 2016-07-27来源:OSCHINA
using UnityEngine; using System.Collections; public class EventsManager { public delegate void OnEnemyDieEvent(int id); public static event OnEnemyDieEvent eventEnemyDie; public delegate void OnEnemyNumberChangeEvent(int number); public static event OnEnemyNumberChangeEvent eventEnemyNumberChange; public delegate void OnPlayerBloodEvent(int blood); public static event OnPlayerBloodEvent eventPlayerBloodChange; public delegate void OnChangeLevelStateEvent(int level); public static event OnChangeLevelStateEvent eventChangeLevelState; public static void EventEnemyDie(int id) { if (eventEnemyDie != null) { eventEnemyDie(id); } } public static void EventEnemyNumberChange(int number) { if (eventEnemyNumberChange != null) { eventEnemyNumberChange(number); } } public static void EventPlayerBloodChange(int blood) { if (eventPlayerBloodChange != null) { eventPlayerBloodChange(blood); } } public static void EventChangeLevelState(int level) { if (eventChangeLevelState != null) { eventChangeLevelState(level); } } } //////////////////////////////////////////////////// //更新敌人数量 EventsManager.EventEnemyNumberChange(listEnemy.Count); /////////////////////////////////////////////////// using UnityEngine; using UnityEngine.UI; using System.Collections; public class UIEnemyNumberText : MonoBehaviour { // Use this for initialization void Start () { EventsManager.eventEnemyNumberChange += RefreshUIText; } // Update is called once per frame void Update () { } void RefreshUIText(int number) { Debug.Log("number of enemy is "+number); gameObject.GetComponent().text = "敌人数量:" + number; } }
热门排行