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); }
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; } } }
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); } } }
public async UniTask SendPacketAsync(Peer peer, byte[] data, CommandType p2PEvent = CommandType.Nothing, SocketQosType qosType = SocketQosType.Unreliable) { await SendPacketDataAsync(peer, data, p2PEvent, qosType); }
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); }
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); }
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); }
public static async UniTask SendPacketAllPeerAsync(byte[] data, CommandType eventtype, SocketQosType qostype) { foreach (Peer p in Peers) { await SendPacketAsync(p, data, eventtype, qostype); } }
public static async UniTask SendPacketAsync(Peer peer, byte[] data, CommandType eventtype, SocketQosType qostype) { await Socket.SendPacketAsync(peer, data, eventtype, qostype); }