public static void BroadcastEvent(OnlineGameEvent _ge)
 {
     Initialize();
     foreach (MonoBehaviour _subscriber in evtSubscribers [(int)_ge.gameEvent]) {
         _subscriber.SendMessage ("HandleOnlineEvent", _ge);
     }
 }
 public static void BroadcastEvent(EOnlineGameEvent _e, object _eventProperty)
 {
     Initialize();
     OnlineGameEvent ge = new OnlineGameEvent (_e, _eventProperty);
     foreach (MonoBehaviour _subscriber in evtSubscribers [(int)_e]) {
         _subscriber.SendMessage ("HandleOnlineEvent", ge);
     }
 }
 public void HandleOnlineEvent(OnlineGameEvent _event)
 {
     switch(_event.gameEvent) {
     case EOnlineGameEvent.ONL_EVT_START_MATCH:
         Debug.Log ("Start Match");
         _Restart();
         break;
     case EOnlineGameEvent.ONL_EVT_SWITCH_TURN:
         Debug.Log ("Switch Match");
         break;
     case EOnlineGameEvent.ONL_EVT_PLAYER_MOVED:
         Debug.Log ("Player Moved");
         break;
     }
 }
Beispiel #4
0
    public static byte[] BuildBytes_OnlineEvent( OnlineGameEvent _ge )
    {
        SimpleJSON.JSONClass obj = new SimpleJSON.JSONClass();
        obj.Add("sender", AppWarp.localusername);
        obj.Add("type", "online_event");
        obj.Add("gE", (int)_ge.gameEvent);
        if( _ge.gameEventProperty != null ) {
            obj.Add("hasEP", true);
            obj.Add("gEP", _ge.gameEventProperty);
        }
        else {
            obj.Add("hasEP", false);
            obj.Add("gEP", "");
        }

        byte[] retVal = System.Text.Encoding.UTF8.GetBytes(obj.ToString());
        return retVal;
    }
        public void onUpdatePeersReceived(UpdateEvent eventObj)
        {
            Log ("onUpdatePeersReceived");

            OnlineMessage msg = OnlineMessage.DecodeMessage(eventObj.getUpdate());

            if (msg.type == "new_match")
            {
                Application.LoadLevel (AppWarp.gameplaySceneStr);
                if(AppWarp.isFirstPlayer) {
                    AppWarp.name_player2 = msg.sender;
            //					// Tell second player to start match
            //					AppWarp.warpClient.SendUpdatePeers(OnlineMessage.BuildBytes_NewMatch());
                }
                else {
                    AppWarp.name_player1 = msg.sender;
                }

                OnlineGameEvent ge = new OnlineGameEvent(EOnlineGameEvent.ONL_EVT_START_MATCH);
                AppWarp.warpClient.SendUpdatePeers(OnlineMessage.BuildBytes_OnlineEvent(ge));
            }
            else if (msg.type == "oppName")
            {
                if(!AppWarp.isFirstPlayer) {
                    AppWarp.name_player1 = msg.sender;
                }
            }
            else if (msg.type == "move")
            {
                if((AppWarp.isFirstPlayer && msg.sender != AppWarp.name_player1) ||
                   (!AppWarp.isFirstPlayer && msg.sender != AppWarp.name_player2)) {
            //					AppWarp.gameplayObj.UpdateSceneFromMove(msg);
                }
            }
            else if (msg.type == "online_event")
            {
                if( msg.sender != AppWarp.localusername) {
                    OnlineGameEventsHandler.BroadcastEvent(msg.onlineEvent);
                }
            }
            else {
                Debug.Log ("Invalid Message Type Received");
            }
        }