void SendNetSync() { if (!GameMgr.instance)//GameMgr.instance没被初始化,则此时是离线状态 { return; } //消息 ProtocolBytes proto = new ProtocolBytes(); proto.AddString("BroadCast"); proto.AddString(sync_id + "NetSyncController"); //sync_id proto.AddString(sync_id); //sync_scripts for (int i = 0; i < sync_scripts.Count; i++) { //移除禁用脚本 if (((MonoBehaviour)sync_scripts[i]).enabled == false) { sync_scripts.Remove(sync_scripts[i]); } Component temp = sync_scripts[i]; SyncData data = (temp as NetSyncInterface).SendData(); //加入空检测 if (data == null) { continue; } proto.AddSyncData(data); } NetMgr.srvConn.Send(proto); }