Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public abstract class MessageData{};
- public enum MessageType {DAMAGED, HEALTHCHANGED, DIED};
- public delegate void MessageDelegate(MessageType msgType, GameObject go, MessageData msgData);
- public class MessageHandler : MonoBehaviour {
- public List<MessageType> messages;
- List<MessageDelegate> m_messageDelegates = new List<MessageDelegate>();
- public void RegisterDelegate(MessageDelegate msgDele)
- {
- m_messageDelegates.Add(msgDele);
- }
- public bool GiveMessage(MessageType msgType, GameObject go, MessageData msgData)
- {
- bool approved = false;
- for (int i = 0; i < messages.Count; i++)
- {
- if (messages[i] == msgType)
- {
- approved = true;
- break;
- }
- }
- if (!approved)
- return false;
- for (int i = 0; i < m_messageDelegates.Count; i++)
- {
- m_messageDelegates[i](msgType, go, msgData);
- }
- return true;
- }
- }
- public class DeathData : MessageData
- {
- public GameObject attacker;
- public GameObject attacked;
- }
- public class HealthData : MessageData
- {
- public int maxHealth;
- public int curHealth;
- }
- public class DamageData : MessageData
- {
- public int damage;
- }
Advertisement
Add Comment
Please, Sign In to add comment