using UnityEngine;
using System.Collections;
public class MessageService : MonoBehaviour {
//This object just can be construct one time.
private static MessageService __instance = null;
public MessageService()
{
if( null != __instance )
Debug.LogError( "MessageService has been constructed twice, no !" );
else
__instance = this;
DontDestroyOnLoad( this );
}
public static MessageService Instance(){ return __instance; }
//The queue hold messages witch will be send to server, we need to ensure the order
private System.Collections.Generic.List<MessageBase> mMessagesPendingToSend;
//Recieve messages from server, and wait to dispatch
private System.Collections.Generic.List<MessageBase> mMessagesRecievedFromServer;
// Use this for initialization
void Start () {
Debug.Log( "MessageService has been started." );
}
// Update is called once per frame
void Update () {
ProcessMessage();
}
private void ProcessMessage()
{
//Note: When we send any message to the server, we will recieve a feedback message immediately
//loop and pop the top message in mMessagesPendingToSend
{
//CombinMessagesInSendQueue();
//SendMessagesToServer();
//you need format the C# version message into a url string with appropriate params.
//Recieve messages from server by the send operation:
//you will recieve a JSON string that comminbed server messages in it.
//Parse the JSON message string into serveral MessageBase objects, and hold the in a list such as: "List<MessageBase> recievedMessages"
//Iter the messages recieved and dispatch them
{
//DispatchRecievedMessage( recievedMsg )
}
}
}
//Some message can be combin to a single message, combin them to reverse server performance.
private void CombinMessagesInSendQueue()
{
//If we have some class like following:
/*
class GetCoinsForBuilding
{
Generric.List<long> mBuildingInstanceIDList;
}
*/
//We can combin server same message in the queue into a single one with a combined buildingInstanceList;
}
private string SendMessagesToServer()
{
return string.Empty;
}
//Queue received message into the queue for clinent.
private void DispatchRecievedMessage( MessageBase msg )
{
}
//Client push messages witch wana be sent to server in a queue first
public void QueueMessageToServer( MessageBase msg )
{
}
}
using System.Collections;
public class MessageService : MonoBehaviour {
//This object just can be construct one time.
private static MessageService __instance = null;
public MessageService()
{
if( null != __instance )
Debug.LogError( "MessageService has been constructed twice, no !" );
else
__instance = this;
DontDestroyOnLoad( this );
}
public static MessageService Instance(){ return __instance; }
//The queue hold messages witch will be send to server, we need to ensure the order
private System.Collections.Generic.List<MessageBase> mMessagesPendingToSend;
//Recieve messages from server, and wait to dispatch
private System.Collections.Generic.List<MessageBase> mMessagesRecievedFromServer;
// Use this for initialization
void Start () {
Debug.Log( "MessageService has been started." );
}
// Update is called once per frame
void Update () {
ProcessMessage();
}
private void ProcessMessage()
{
//Note: When we send any message to the server, we will recieve a feedback message immediately
//loop and pop the top message in mMessagesPendingToSend
{
//CombinMessagesInSendQueue();
//SendMessagesToServer();
//you need format the C# version message into a url string with appropriate params.
//Recieve messages from server by the send operation:
//you will recieve a JSON string that comminbed server messages in it.
//Parse the JSON message string into serveral MessageBase objects, and hold the in a list such as: "List<MessageBase> recievedMessages"
//Iter the messages recieved and dispatch them
{
//DispatchRecievedMessage( recievedMsg )
}
}
}
//Some message can be combin to a single message, combin them to reverse server performance.
private void CombinMessagesInSendQueue()
{
//If we have some class like following:
/*
class GetCoinsForBuilding
{
Generric.List<long> mBuildingInstanceIDList;
}
*/
//We can combin server same message in the queue into a single one with a combined buildingInstanceList;
}
private string SendMessagesToServer()
{
return string.Empty;
}
//Queue received message into the queue for clinent.
private void DispatchRecievedMessage( MessageBase msg )
{
}
//Client push messages witch wana be sent to server in a queue first
public void QueueMessageToServer( MessageBase msg )
{
}
}