using DevelopEngine; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace XFramework.NetOuter { public class NetUDPManager : MonoSingleton, IUDPHander { private UdpOuter udpOuter;//UDP通讯类 void Awake() { //DontDestroyOnLoad(this.gameObject);// } /// /// 初始化UDP通讯类 /// /// 目标IP /// 目标端口 /// 自身监听端口 /// 组播/点播 public void InitUdp(string ip, int otherPort, int localport, UDPType type) { udpOuter = new UdpOuter(ip, otherPort, localport, type); } private void FixedUpdate() { udpOuter.ExtractingMsg(); } public void AddListener(string eventName, INetExcute MsgExcute, bool isOnce = false) { udpOuter.AddListener(eventName, MsgExcute, isOnce); } //主动关闭 public void Close() { udpOuter.Close(); Destroy(this.gameObject); } public void ExtractingMsg() { udpOuter.ExtractingMsg(); } public void RemovListener(string eventName) { udpOuter.RemovListener(eventName); } /// /// 发送消息到指定地址 /// /// /// /// public void SendNetMess(string ip, int port, ProtocolBase protocol) { udpOuter?.SendNetMess(ip, port, protocol); } /// /// 发送消息到默认地址 /// /// public void SendNetMess(ProtocolBase proto) { udpOuter?.SendNetMess(proto); } //程序结束自动关闭 void OnDestroy() { udpOuter?.Close(); } } }