Ejemplo n.º 1
0
 private void OnDestroy()
 {
     if (Instance == this)
     {
         NGLogger.LogDebug("Socket is Closed.");
         Socket.Close();
     }
 }
Ejemplo n.º 2
0
        public void ResponseProcessor(ResponseOperationMessage rmsg)
        {
            switch (rmsg.MsgType)
            {
            case MessageType.CreateRoom:
                var crParams = rmsg.CrrParams;
                switch (crParams.ReturnValue)
                {
                case (uint)ResponseMessageInfo.CreateRoomSuccess:
                    LocalPlayer = new NGPlayer(true, crParams.PeerId);
                    NGEvent.OnCreatedRoom();
                    break;

                case (uint)ResponseMessageInfo.CreateRoomAlreadyExist:
                    NGEvent.OnCreateRoomFailed(crParams.Message);
                    break;
                }
                break;

            case MessageType.JoinRoom:

                var jrrParams = rmsg.JrrParams;

                switch (jrrParams.ReturnValue)
                {
                case (uint)ResponseMessageInfo.JoinRoomSuccess:
                    NGLogger.LogDebug("JoinRoomSuccess responsee");
                    LocalPlayer = new NGPlayer(true, jrrParams.PeerId);
                    NGEvent.OnJoinedRoom();
                    break;

                case (uint)ResponseMessageInfo.JoinRoomAlreadyInRoom:
                    NGEvent.OnJoinRoomFailed();
                    break;

                case (uint)ResponseMessageInfo.JoinRoomFull:
                    NGEvent.OnJoinRoomFailed();
                    break;

                default:
                    NGLogger.LogError("The return value from JoinRoom or JoinOrCreateRoom" + jrrParams.ReturnValue + " cannot be identified.");
                    break;
                }
                break;

            case MessageType.LeaveRoom:
                var lrParams = rmsg.LrrParams;
                switch (lrParams.ReturnValue)
                {
                case (uint)ResponseMessageInfo.LeaveRoomSuccess:

                    NGEvent.OnLeftRoom();
                    break;
                }
                break;
            }
        }
Ejemplo n.º 3
0
 void Update()
 {
     // Touch notifications
     if (Input.touchCount > 0)
     {
         Touch touch = Input.GetTouch(0);
         if (touch.phase != TouchPhase.Began &&
             touch.phase != TouchPhase.Moved &&
             touch.phase != TouchPhase.Stationary)
         {
             SendOnClick(touch.position);
         }
     }
     else
     {
         if (Input.GetMouseButtonUp(0))
         {
             NGLogger.LogDebug("on Click");
             SendOnClick(Input.mousePosition);
         }
     }
 }
Ejemplo n.º 4
0
 public override void OnConnected()
 {
     Status = SocketStatus.Connected;
     NGLogger.LogDebug("On connected");
 }
Ejemplo n.º 5
0
        private void ProcessRecieveData(byte[] data)
        {
            //NGLogger.LogInfo("Receive a message");
            Stream stream = new MemoryStream(data);

            ReceiveMessage message = ReadMessage <ReceiveMessage>(stream);

            switch (message.ReceiveMsgType)
            {
            case ReceiveMessageType.ResponseSocketStatus:
                switch (message.RssMsg.SStatus)
                {
                case SocketStatus.Connected:
                    NGNetwork.Status = SocketStatus.Connected;
                    NGNetworkEvent.OnConnected();
                    break;
                }
                break;

            case ReceiveMessageType.ResponseOperation:

                ResponseOperationMessage rmsg = message.RoMsg;
                NGInterface.CurrentRoom().ResponseProcessor(rmsg);
                break;

            case ReceiveMessageType.Forward:

                ForwardMessage fmsg   = message.FMsg;
                uint           peerId = fmsg.PeerId;
                switch (fmsg.MsgType)
                {
                case MessageType.JoinRoom:
                    var      jrParams  = fmsg.JrfParams;
                    NGPlayer newplayer = new NGPlayer(false, peerId);
                    NGInterface.CurrentRoom().AddPlayer(newplayer);
                    NGEvent.OnOtherPlayerEnteredRoom(newplayer);
                    break;

                case MessageType.JoinOrCreateRoom:
                    var      jocParams = fmsg.JocrfParams;
                    NGPlayer player    = new NGPlayer(false, peerId);
                    NGInterface.CurrentRoom().AddPlayer(player);
                    NGEvent.OnOtherPlayerEnteredRoom(player);
                    break;

                case MessageType.LeaveRoom:
                    var lParams = fmsg.LrfParams;
                    NGLogger.LogDebug("LeaveRoom" + peerId);

                    var leaveplayer = NGInterface.CurrentRoom().GetNGPlayer(peerId);
                    NGEvent.OnOtherPlayerLeftRoom(leaveplayer);
                    Destroy(leaveplayer.GO);
                    NGInterface.CurrentRoom().RemovePlayer(peerId);

                    break;

                case MessageType.Rpc:
                    var     rpcparams = fmsg.RfParams;
                    NGAny[] objs      = NGProtobufConverter <NGAny> .RepeatedField2Array(rpcparams.Parameters);

                    NGRPC.ExcuteRPC(rpcparams.ViewID, rpcparams.MethodName, objs);
                    break;

                case MessageType.Instantiation:
                    var i   = fmsg.IfParams;
                    var ids = NGProtobufConverter <uint> .RepeatedField2Array(i.ViewIDs);

                    NGInterface.CurrentRoom().Instantiate(peerId, false, ids, i.PrefabName, i.Position, i.Rotation);
                    break;

                case MessageType.ViewSync:
                    var             viewsyncparams = fmsg.VsfParams;
                    var             viewParams     = viewsyncparams.VsdParams;
                    NGViewContainer container      = new NGViewContainer();
                    container.DeserializeAll(viewParams);
                    break;

                case MessageType.CustomEvent:
                    var ceParams = fmsg.CeParams;
                    NGEvent.OnCustomEvent(ceParams.EventID, NGProtobufConverter <NGAny> .RepeatedField2Array(ceParams.CustomData));
                    break;
                }
                break;
            }
        }
Ejemplo n.º 6
0
 public virtual void OnJoinRoomFailed()
 {
     NGLogger.LogDebug("Join room failed ");
 }
Ejemplo n.º 7
0
 public virtual void OnJoinedRoom()
 {
     NGLogger.LogDebug("On Joined Room. ");
 }
Ejemplo n.º 8
0
 public virtual void OnGreateRoomFailed(string errmsg)
 {
     NGLogger.LogDebug("Create room failed " + errmsg);
 }