Exemple #1
0
    //use UDP protocol transfer position info.
    //The UDPclient class initialized in the base class
    public override void syncData()
    {
        // BaseContol.NetworkId = id;
        print("entry synchronization function");
        SerializeUDP info = new SerializeUDP(id, playerObject.transform);

        adapter.UDPC.sendByte(ObjectToByteArray(info));
        //adapter.sendmessage(adapter.connectionId, ObjectToByteArray(info), msgType.Data);
    }
Exemple #2
0
    public void SynchronizationData(GameObject g, SerializeUDP infomation)
    {
        BaseContol operatingObj = g.GetComponent <BaseContol>();

        //  g.transform.position = new Vector3(infomation.x, infomation.y, infomation.z);
        operatingObj.setDirection(infomation.angle);
        if (!destinationList.ContainsKey(g))
        {
            destinationList.Add(g, new Vector3(infomation.x, infomation.y, infomation.z));
        }
        else
        {
            destinationList[g] = new Vector3(infomation.x, infomation.y, infomation.z);
        }
        // SyncPosition(g, new Vector3(infomation.x, infomation.y, infomation.z));
        //operatingObj.frie(infomation.state[0]); abandoned operating
    }
Exemple #3
0
    //process incoming position data
    public override void processMessage(byte[] Udpdata, IPEndPoint ipinfo)
    {
        /* print("ipinfo.Address.ToString() " + ipinfo.Address.ToString() );
         * Debug.Log(
         *   " IpToObj[ipinfo.Address.ToString()]="+IpToObj[ipinfo.Address.ToString()].ToString());
         */
        if (!IPtoId.ContainsKey(ipinfo))
        {
            string address = ipinfo.Address.ToString();
            int    IPid    = int.Parse(address.Split('.')[3]);
            IPtoId.Add(ipinfo, IPid + 1);
        }
        obj = synchronizationObj["玩家1" + IPtoId[ipinfo]];
        SerializeUDP clientInfo = (SerializeUDP)BytesToOBJ(Udpdata);

        operatingObj = obj.GetComponent <BaseTank>();
        // obj.transform.position = new Vector3(clientInfo.x, clientInfo.y,clientInfo.z);
        SyncPosition(operatingObj.transform.gameObject, new Vector3(clientInfo.x, clientInfo.y, clientInfo.z));
        operatingObj.setDirection(clientInfo.angle);
    }