// Start is called before the first frame update void Start() { udpm = new _UDPManager(); udpm.DefaultTarget = this; //Add listeners on the instance of UDPManager udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.BOUND, (UDPManagerEvent e) => { listeners.OnBound?.Invoke(e); }); udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_CANCELED, (UDPManagerEvent e) => { listeners.OnDataCanceled?.Invoke(e); }); udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_DELIVERED, (UDPManagerEvent e) => { listeners.OnDataDelivered?.Invoke(e); }); udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_RECEIVED, (UDPManagerEvent e) => { listeners.OnDataReceived?.Invoke(e); }); udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_RETRIED, (UDPManagerEvent e) => { listeners.OnDataRetried?.Invoke(e); }); udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_SENT, (UDPManagerEvent e) => { listeners.OnDataSent?.Invoke(e); }); channels.ForEach((UChannel uc) => { udpm.AddChannel(uc.Name, uc.GuarantiesDelivery, uc.MaintainOrder, uc.RetryTime, uc.CancelTime); }); udpm.Bind(port); }
/// <summary> /// Add a UDPChannel on the instance</summary> /// <param name='channelName'>The name of the channel you want to create.</param> /// <c>It must be unique on this instance, if a channel with the same name has already been added the method will throw an exception!</c> /// <remarks>You can check if the name is already used by calling <see cref="GetChannelByName"/></remarks> /// <param name='guarantiesDelivery'>If true the messages sent though this channel will wait for a receipt from the target that will guaranty the delivery. It will wait during the time specified on <paramref name="retryTime"/> until what it will retry sending the message, etc... If false the message is sent once without guranty of delivery. Default is false.<remarks>The guaranty of the delivery works only if the target uses the same library (C#,AS3 or JS) to communicate over UDP!</remarks></param> /// <param name='maintainOrder'>If true it will wait for a message to be delivered before sending the next one.<remarks> Only works if <paramref name="guarantiesDelivery"/> is true</remarks></param> /// <param name='retryTime'>The number of milliseconds the channel will wait before retrying sending the message if not delivered. Default is 30.</param> /// <param name='cancelTime'>The number of milliseconds the channel will wait before canceling the message if not delivered. Default is 500.</param> public void AddChannel(string channelName, bool guarantiesDelivery = false, bool maintainOrder = false, float retryTime = 30, float cancelTime = 500) { _udpManager.AddChannel(channelName, guarantiesDelivery, maintainOrder, retryTime, cancelTime); }