Ejemplo n.º 1
0
        internal SyncProto GetChangeData()
        {
            SyncProto proto = new SyncProto();

            for (int i = 0; i < valueList.Count; i++)
            {
                IValueData unit = valueList[i];

                if (unit.IsChange())
                {
                    proto.valueChangeList.Add(unit.GetChangeData());
                }
            }

            for (int i = 0; i < dicList.Count; i++)
            {
                IDicValueData unit = dicList[i];

                if (unit.IsChange())
                {
                    proto.dicChangeList.Add(unit.GetChangeData());
                }
            }

            return(proto);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 检查消息队列,将消息分发
        /// </summary>
        protected void CheckMessageQueue()
        {
            if (syncClient != null)
            {
                if (syncClient.Running)
                {
                    while (syncClient.SyncQueue.GetCount() > 0)
                    {
                        byte[] messageBytes = syncClient.SyncQueue.Dequeue();

                        SyncProto proto = null;

                        if (messageType == CollaborationMessageType.JSON)
                        {
                            string json = Encoding.UTF8.GetString(messageBytes);
                            //Debug.Log(json);

                            proto = JsonUtil.Deserialize <SyncProto>(json);
                            //Debug.Log("Msg[" + proto.msg_id + "]  objs:" + proto.sync_msg.msg_entry);
                        }
                        else
                        {
                            proto = SyncProto.Parser.ParseFrom(messageBytes);
                        }

                        //Debug.Log("[Receive] " + proto);

                        // 处理消息
                        DealMessage(proto);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 将消息转发给所有的Handler
 /// </summary>
 /// <param name="proto"></param>
 protected virtual void DealMessage(SyncProto proto)
 {
     for (int i = 0; i < messageHandlerList.Count; i++)
     {
         messageHandlerList[i].DealMessage(proto);
     }
 }
Ejemplo n.º 4
0
        public bool SendCommand(BroadcastMsg msg)
        {
            if (syncClient == null)
            {
                return(false);
            }

            if (!syncClient.Running)
            {
                return(false);
            }

            SyncProto syncProto = new SyncProto();

            syncProto.BrdMsg = msg;

            if (messageType == CollaborationMessageType.JSON)
            {
                string msgData = JsonUtil.Serialize(syncProto, false, false);
                syncClient.SendMessage(msgData);
            }
            else if (messageType == CollaborationMessageType.ProtoBuf)
            {
                syncClient.SendMessage(syncProto.ToByteArray());
            }

            //Debug.Log("Send Command: " + syncProto);

            return(true);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// processes the messages
    /// </summary>
    /// <param name="proto"></param>
    void DealMessage(SyncProto proto)
    {
        Google.Protobuf.Collections.RepeatedField <MsgEntry> messages = proto.SyncMsg.MsgEntry;
        //Debug.Log("deal message");
        if (messages == null)
        {
            return;
        }
        for (int i = 0; i < messages.Count; i++)
        {
            MsgEntry msgEntry = messages[i];
            if (msgEntry.ShowId == showObject.ShowId)
            {
                //ChangeCubeColor((ColorType)((int)msgEntry.Vec[0]));
                Debug.Log("I am deal message");
            }
            if (msgEntry.ShowId == "000")
            {
                string s         = msgEntry.Info.ToString();
                string ipAddress = s.Substring(14, collaborationManager.clientId.Length);
                //the devices' IP are extracted and inserted in idList
                //the ip is used to diversify clearly one player to the other
                idList.Add(ipAddress);
            }

            if (msgEntry.ShowId == playerA.id)
            {
                string s    = msgEntry.Info.ToString();
                string cell = s.Substring(14, 5);
                //Debug.Log(cell);
                ChangeCubeColor((CType)((int)msgEntry.Vec[0]), cell, msgEntry.Pr[0]);
                NoWinner(msgEntry.Pr[1]);
            }

            if (msgEntry.ShowId == playerB.id)
            {
                string s    = msgEntry.Info.ToString();
                string cell = s.Substring(14, 5);
                ChangeCubeColor((CType)((int)msgEntry.Vec[0]), cell, msgEntry.Pr[0]);
                NoWinner(msgEntry.Pr[1]);
            }

            if (msgEntry.ShowId == "001")
            {
                string s = msgEntry.Info.ToString();
                waiting = s.Substring(14, collaborationManager.clientId.Length);
                Debug.Log("Waiting is :" + waiting);
                VerifyCurrentPlayer(waiting);
            }
        }
    }
Ejemplo n.º 6
0
 void DealMessage(SyncProto proto)
 {
     Google.Protobuf.Collections.RepeatedField <MsgEntry> messages = proto.SyncMsg.MsgEntry;
     //Debug.Log("deal message");
     if (messages == null)
     {
         return;
     }
     for (int i = 0; i < messages.Count; i++)
     {
         MsgEntry msgEntry = messages[i];
         if (msgEntry.ShowId == showObject.ShowId)
         {
             ChangeCubeColor((ColorType)((int)msgEntry.Vec[0]));
         }
     }
 }
Ejemplo n.º 7
0
    public void DealMessage(SyncProto proto)
    {
        Google.Protobuf.Collections.RepeatedField <MsgEntry> messages = proto.SyncMsg.MsgEntry;
        if (messages == null)
        {
            return;
        }

        for (int i = 0; i < messages.Count; i++)
        {
            MsgEntry msg = messages[i];
            cube.transform.position    = new Vector3(msg.Pr[0], msg.Pr[1], msg.Pr[2]);
            cube.transform.eulerAngles = new Vector3(msg.Pr[3], msg.Pr[4], msg.Pr[5]);

            Debug.Log("Receive Message! " + msg.Pr);
        }
    }
Ejemplo n.º 8
0
    public void RefreshObjectEntryData(Transform trans, SyncProto proto)
    {
        Google.Protobuf.Collections.RepeatedField <MsgEntry> messages = proto.SyncMsg.MsgEntry;
        if (messages == null)
        {
            return;
        }

        for (int i = 0; i < messages.Count; i++)
        {
            MsgEntry msg = messages[i];
            if (msg.ShowId == this.objectShowId)
            {
                trans.position    = new Vector3(msg.Pr[0], msg.Pr[1], msg.Pr[2]);
                trans.eulerAngles = new Vector3(msg.Pr[3], msg.Pr[4], msg.Pr[5]);
            }
        }
    }
Ejemplo n.º 9
0
    protected void DealMessage(SyncProto proto)
    {
        Google.Protobuf.Collections.RepeatedField <MsgEntry> messages = proto.SyncMsg.MsgEntry;

        if (messages == null)
        {
            return;
        }

        MsgEntryLocal[] messages_local = new MsgEntryLocal[messages.Count];
        for (int i = 0; i < messages.Count; i++)
        {
            float[] Pr_message = new float[messages[i].Pr.Count];
            for (int prI = 0; prI < messages[i].Pr.Count; prI++)
            {
                Pr_message[prI] = messages[i].Pr[prI];
            }

            messages_local[i] = new MsgEntryLocal(messages[i].ShowId, messages[i].Info.ObjType, Pr_message);
        }
        DealMsgEntries(messages_local, proto.SyncMsg.IsFull);
    }
Ejemplo n.º 10
0
    private void ReponseFromServer(SyncProto proto)
    {
        Google.Protobuf.Collections.RepeatedField <MsgEntry> messages = proto.SyncMsg.MsgEntry;

        if (messages == null)
        {
            return;
        }

        for (int i = 0; i < messages.Count; i++)
        {
            MsgEntry msgEntry = messages[i];
            if (msgEntry.ShowId == m_showObject.ShowId)
            {
                BehaviourType t_type = (BehaviourType)((int)msgEntry.Vec[0]);
                if (t_type == BehaviourType.FingerDrag)
                {
                    this.transform.position    = new Vector3(msgEntry.Pr[0], msgEntry.Pr[1], msgEntry.Pr[2]);
                    this.transform.eulerAngles = new Vector3(msgEntry.Pr[3], msgEntry.Pr[4], msgEntry.Pr[5]);
                    //Debug.LogFormat("The unet object id {0} which state is {1}.", m_showObject.ShowId,"draging");
                }
            }
        }
    }
Ejemplo n.º 11
0
 void DealMessage(SyncProto proto)
 {
     Google.Protobuf.Collections.RepeatedField <MsgEntry> messages =
         proto.SyncMsg.MsgEntry;
     //Debug.Log("deal message");
     if (messages == null)
     {
         return;
     }
     for (int i = 0; i < messages.Count; i++)
     {
         MsgEntry msgEntry = messages[i];
         if (msgEntry.ShowId == showObject.ShowId)
         {
             Debug.Log(msgEntry);
             CreateLineRenderer(msgEntry);
             StartCoroutine(DrawLine(msgEntry));
         }
         if (msgEntry.ShowId == "showId002")
         {
             DeleteAction(msgEntry);
         }
     }
 }
Ejemplo n.º 12
0
 void IMessageHandler.DealMessage(SyncProto proto)
 {
     this.DealMessage(proto);
 }
Ejemplo n.º 13
0
 void IMessageHandler.DealMessage(SyncProto proto)
 {
     this.ReponseFromServer(proto);
 }
Ejemplo n.º 14
0
    private void SyncHandler(SyncProto dd)
    {
        dd.SetData(PlayerData.Instance);

        int a = 1;
    }