/// <summary> /// Send out any delayed message. This method is called each time through the main game loop /// </summary> public void DispatchDelayedMessage(int GameTime) { foreach (Telegram item in m_hMessages) { if (item.DispatchTime <= 0) { GameObject pReceiver = MyEntityManager.Instance().GetGameObjectFromID(item.RecieverID); Discharge(pReceiver, item); // remove item m_hMessages.Remove(item); } else { item.DispatchTime -= GameTime; } } }
/// <summary> /// Send a message to specific object by receiverid /// </summary> /// <param name="delay">Time delay (milisecond)</param> /// <param name="senderid">Send ID</param> /// <param name="receiverid">Receiver ID</param> /// <param name="message">Message Code</param> /// <param name="ExtraInfo">More Infor</param> public void DispatchMessage(int delay, int senderid, int receiverid, int message, GameObject ExtraInfo) { Telegram _message = new Telegram(); _message.DispatchTime = delay; _message.ExtraInfo = ExtraInfo; _message.Msg = message; _message.RecieverID = receiverid; _message.SenderID = senderid; // if delay <= 0 then we send message immediately if (delay <= 0) { GameObject pReceiver = MyEntityManager.Instance().GetGameObjectFromID(receiverid); Discharge(pReceiver, _message); } else { m_hMessages.Add(_message); } }