Example #1
0
        private static void RecieveReserveNetId(ushort senderPlayerId, ref DataStreamReader recievePacket, ref DataStreamReader.Context ctx)
        {
            if (GamePacketManager.IsLeader)
            {
                //HostではNetIDの整合性を確認
                ushort reserveNetId = (ushort)Instance.m_identityList.Count;
                Instance.m_identityList.Add(null);

                //Clientに通達する
                using (var packet = new DataStreamWriter(3, Allocator.Temp)) {
                    packet.Write((byte)BuiltInPacket.Type.ReserveNetId);
                    packet.Write(reserveNetId);
                    GamePacketManager.Send(senderPlayerId, packet, QosType.Reliable);
                }
            }
            else
            {
                //確認されたauthorの変更を反映
                ushort reserveNetId = recievePacket.ReadUShort(ref ctx);
                if (uncheckReserveNetIdCallbacks.Count > 0)
                {
                    uncheckReserveNetIdCallbacks[0] (reserveNetId);
                    uncheckReserveNetIdCallbacks.RemoveAt(0);
                }
                else
                {
                    Debug.LogError("uncheckReserveNetIdCallbacks is 0");
                }
            }
        }
 internal void RecieveChangeAuthorInGroup(ushort netId, ushort author)
 {
     if (GamePacketManager.IsLeader)
     {
         //Hostではauthorの整合性を確認
         if (netId < m_identityList.Count)
         {
             m_identityList[netId].SetAuthor(author);
             //Clientに通達する
             using (var packet = new DataStreamWriter(9, Allocator.Temp)) {
                 packet.Write((byte)BuiltInPacket.Type.ChangeAuthor);
                 packet.Write(m_groupHash);
                 packet.Write(netId);
                 packet.Write(author);
                 GamePacketManager.Brodcast(packet, QosType.Reliable);
             }
         }
     }
     else
     {
         //確認されたauthorの変更を反映
         if (netId < m_identityList.Count)
         {
             m_identityList[netId].SetAuthor(author);
         }
     }
 }
 private void SendPacketChangeAuthor(ushort netId, ushort author)
 {
     using (var packet = new DataStreamWriter(9, Allocator.Temp)) {
         packet.Write((byte)BuiltInPacket.Type.ChangeAuthor);
         packet.Write(m_groupHash);
         packet.Write(netId);
         packet.Write(author);
         GamePacketManager.Send(0, packet, QosType.Reliable);
     }
 }
Example #4
0
        /// 所有者側は現在のTransform情報を送信する
        private void SendTransform()
        {
            if (forceUpdateTransfromFrag)
            {
                forceUpdateTransfromFrag = false;
            }
            else
            {
                float elapsedTime = (float)(RecordableIdentityManager.progressTimeSinceStartup - prevSendTime) / 1000.0f;
                if (elapsedTime <= minInterval)
                {
                    return;
                }
                //定期更新.
                if (elapsedTime <= maxInterval)
                {
                    //一定以上動いたら更新
                    float sqrDistance = Vector3.SqrMagnitude(recPosition - CacheTransform.position);
                    float diffAngle   = Quaternion.Angle(recRotation, CacheTransform.rotation);
                    if (diffAngle < deltaRotSendThreshold && sqrDistance < deltaPosSendThreshold * deltaPosSendThreshold)
                    {
                        return;
                    }
                }
                //Debug.Log ("SendTransform elapsedTime = " + elapsedTime);
            }

            //TODO できればScene単位でパケットをまとめて、type(1byte) sceneHash(4byte)の5byteのデータを削減したい
            using (var packet = new DataStreamWriter(65, Allocator.Temp)) {
                packet.Write((byte)BuiltInPacket.Type.SyncTransform);
                packet.Write(CacheRecordableIdentity.sceneHash);
                packet.Write(CacheRecordableIdentity.netId);
                packet.Write(RecordableIdentityManager.progressTimeSinceStartup);
                packet.Write(CacheTransform.position);
                packet.Write(CacheTransform.rotation);

                if (CacheRigidbody != null)
                {
                    packet.Write(CacheRigidbody.velocity);
                    packet.Write(CacheRigidbody.angularVelocity);
                }
                else
                {
                    packet.Write(Vector3.zero);
                    packet.Write(Vector3.zero);
                }

                GamePacketManager.Brodcast(packet, qosType);
            }

            SetRecTransformValue();

            prevSendTime = RecordableIdentityManager.progressTimeSinceStartup;
        }
Example #5
0
 /// <summary>
 /// Hostに問い合わせて重複しないNetIDを取得する.
 /// </summary>
 public static void ReserveNetId(System.Action <ushort> onReserveNetId)
 {
     if (GamePacketManager.IsLeader)
     {
         onReserveNetId((ushort)Instance.m_identityList.Count);
     }
     else
     {
         uncheckReserveNetIdCallbacks.Add(onReserveNetId);
         using (var packet = new DataStreamWriter(1, Allocator.Temp)) {
             packet.Write((byte)BuiltInPacket.Type.ReserveNetId);
             GamePacketManager.Send(0, packet, QosType.Reliable);
         }
     }
 }
Example #6
0
        internal void BrodcastRpc(byte componentIndex, byte methodId, DataStreamWriter rpcPacket, QosType qosType, bool important)
        {
            if (!isSyncComplete)
            {
                return;
            }
            var writer = new DataStreamWriter(rpcPacket.Length + 9, Allocator.Temp);

            CreateRpcPacket(ref writer, ref rpcPacket, componentIndex, methodId);
            GamePacketManager.Brodcast(writer, qosType);
            //if (important) {
            //    GamePacketManager.Brodcast (writer, qosType);
            //} else {
            //    GamePacketManager.Brodcast (writer, qosType, gridId);
            //}
            writer.Dispose();
        }