Пример #1
0
        public static async UniTask Destroy(Object obj, SocketQosType qostype = SocketQosType.Unreliable)
        {
            var gameObject = (GameObject)obj;
            await UniP2PManager.SendPacketAllPeerAsync(CreatePacket(DataEventPacket.Destroy, null, gameObject.GetComponent <SyncGameObject>().InstanceID), CommandType.DataEvent, qostype);

            Object.Destroy(gameObject);
        }
Пример #2
0
        public async UniTask SendPacketDataAsync(Peer peer, byte[] data, CommandType p2PEvent = CommandType.Nothing, SocketQosType qosType = SocketQosType.Unreliable)
        {
            foreach (var connection in UdpConnections)
            {
                if (connection.Peer == peer)
                {
                    await SendAsync(GetUdpConnection(peer.ID), data, p2PEvent, qosType);

                    PacketCapture.Write(peer.IPEndPoint.ToString(), data.Length, "PacketData");
                    return;
                }
            }
        }
Пример #3
0
        public async UniTask SendAsync(UdpConnection udp, byte[] data, CommandType p2PEvent = CommandType.Nothing, SocketQosType qosType = SocketQosType.Unreliable)
        {
            Command packetObject = new Command();

            packetObject.P2PEventType = p2PEvent;
            packetObject.Value        = data;
            if (udp != null)
            {
                if (qosType == SocketQosType.Reliable)
                {
                    await udp.AddReliableCommand(packetObject);
                }
                else if (qosType == SocketQosType.Unreliable)
                {
                    udp.AddUnreliableCommand(packetObject);
                }
            }
        }
Пример #4
0
 public async UniTask SendPacketAsync(Peer peer, byte[] data, CommandType p2PEvent = CommandType.Nothing, SocketQosType qosType = SocketQosType.Unreliable)
 {
     await SendPacketDataAsync(peer, data, p2PEvent, qosType);
 }
Пример #5
0
        public static async UniTask <Object> Instantiate(string resourcepath, Vector3 position, Quaternion quaternion, string peerid, SocketQosType qostype = SocketQosType.Unreliable)
        {
            var sendpeer = UniP2PManager.GetPeer(peerid);
            var obj      = Object.Instantiate(Resources.Load(resourcepath), position, quaternion);
            var gobj     = (GameObject)obj;
            var id       = gobj.GetComponent <SyncGameObject>().Instance(UniP2PManager.MyPeerID);
            var buf      = Serializer.Serialize(new InstantiateInfomation {
                Position = position, Quaternion = quaternion, ResourcePath = resourcepath
            });

            if (sendpeer == null)
            {
                return(obj);
            }
            await UniP2PManager.SendPacketAsync(sendpeer, CreatePacket(DataEventPacket.Instantiate, buf, id), CommandType.DataEvent, qostype);

            return(obj);
        }
Пример #6
0
 public static async UniTask SendStreamAllPeer(string instanceid, string eventname, string typename, byte[] value, SocketQosType qostype = SocketQosType.Unreliable)
 {
     await UniP2PManager.SendPacketAllPeerAsync(CreatePacket(eventname, value, instanceid, typename),
                                                CommandType.DataEvent, qostype);
 }
Пример #7
0
        public static async UniTask SendStream(string instanceid, string eventname, string typename, byte[] value, SocketQosType qostype = SocketQosType.Unreliable, string peerid = "")
        {
            var peer = UniP2PManager.GetPeer(peerid);

            if (peer == null)
            {
                return;
            }
            await UniP2PManager.SendPacketAsync(peer, CreatePacket(eventname, value, instanceid, typename), CommandType.DataEvent, qostype);
        }
Пример #8
0
 public static async UniTask SendPacketAllPeerAsync(byte[] data, CommandType eventtype, SocketQosType qostype)
 {
     foreach (Peer p in Peers)
     {
         await SendPacketAsync(p, data, eventtype, qostype);
     }
 }
Пример #9
0
 public static async UniTask SendPacketAsync(Peer peer, byte[] data, CommandType eventtype, SocketQosType qostype)
 {
     await Socket.SendPacketAsync(peer, data, eventtype, qostype);
 }