Exemplo n.º 1
0
        public void SendTransform(Transform t, byte id)
        {
            ttosend          = new NetTransform();
            ttosend.position = t.localPosition;
            ttosend.rotation = t.localRotation.eulerAngles;
            ttosend.scale    = t.localScale;
            Packet pts = new Packet();

            pts.data = PacketUtils.Pack(ttosend.EncodeRaw(), PacketUtils.GenerateHeader(cid, NetData.TYPE_NETTRANSFORM, id, ttosend.GetLength()));
            UDPout.Enqueue(pts);
        }
Exemplo n.º 2
0
 public void OnClientTransformReceived(byte cid, NetTransform t)
 {
     //Only use data when received from client if clients have some authority over that data
     if (ClientAuthorityTransforms.Contains(t.GetID()))
     {
         //Now directly storing at the same ID, however it could be better to switch over the ID
         //And for instance if clients use a SelfTransform ID the server can store it somewhere else
         //Potentially even outside the shared datastore
         netdata.NETTRANSFORM[t.GetID()] = t;
     }
 }
Exemplo n.º 3
0
        public NetData()
        {
            //For each type of packet we need to init the array and fill in with empty objects to avoid nullreferences
            //Before a write has filled the slot with data.
            CMD = new NetCMD[Enum.GetValues(typeof(ID_CMD)).Length];
            for (int i = 0; i < Enum.GetValues(typeof(ID_CMD)).Length; i++)
            {
                CMD[i] = new NetCMD();
            }

            NETTRANSFORM = new NetTransform[Enum.GetValues(typeof(ID_NETTRANSFORM)).Length];
            for (int i = 0; i < Enum.GetValues(typeof(ID_NETTRANSFORM)).Length; i++)
            {
                NETTRANSFORM[i] = new NetTransform();
            }
        }
Exemplo n.º 4
0
        public void OnReceive(Packet p)
        {
            phtemp = PacketUtils.ReadHeader(p.data);

            switch (phtemp.type)
            {
            case NetData.TYPE_CMD:
                NetCMD cmd = new NetCMD();
                cmd.DecodeRaw(PacketUtils.Unpack(p.data));
                OnClientCommandReceived(phtemp.cid, cmd);
                break;

            case NetData.TYPE_NETTRANSFORM:
                NetTransform nt = new NetTransform();
                nt.DecodeRaw(PacketUtils.Unpack(p.data));
                OnClientTransformReceived(phtemp.cid, nt);
                break;

            default:
                DebugLog("Undefined Packet Type : " + phtemp.type);

                break;
            }
        }