/// <summary> /// 发送数据 /// </summary> /// <param name="buffer"></param> /// <returns></returns> public bool send(INetMsg message) { if (!isConnected) { return(false); } NetMsg msg = (NetMsg)message; if (msg == null) { return(false); } //序列化 msg.serialization(); NetworkStream stream = _tcp.GetStream(); if (stream.CanWrite) { try { msg.buffer.position = 0; stream.BeginWrite(msg.buffer.array, msg.buffer.position, msg.buffer.limit - msg.buffer.position, new AsyncCallback(AsyncWrite), null); } catch (Exception ex) { OnException(ex); return(false); } } return(true); }
public void ReceiveMsg(INetMsg msg, int connectionId) { var stationSelect = msg as StationSelectMsg; if (stationSelect != null) { this.ReceivedStationSelect(connectionId, stationSelect); } var startBattleMsg = msg as StartBattleMsg; if (startBattleMsg != null) { CoreNetwork.Instance.StopHostBroadcast(); switch (this.stationSelected) { case Stations.Pilot: { SceneManager.LoadScene("PilotStation"); break; } case Stations.SensorsAndWeapons: { SceneManager.LoadScene("SensorsAndWeaponsStation"); break; } default: break; } } }
public void Send(INetMsg nm) { if (m_NC != null && m_NC.Connected) { m_NC.send(nm); } }
/// <summary> /// 发送数据 /// </summary> /// <param name="buffer"></param> /// <returns></returns> public bool send(INetMsg message) { if (_nowSession == null) { return(false); } return(_nowSession.send(message)); }
public static byte[] Serialize(INetMsg msg) { var networkWriter = new NetworkWriter(); uint index = GetMsgIndexFromType( msg.GetType() ); networkWriter.WritePackedUInt32( index ); ((MessageBase)msg).Serialize(networkWriter); return networkWriter.AsArray(); }
public void ReceiveMsg(INetMsg msg, int _) { var energyCons = msg as EnergyConsumtionMsg; if (energyCons != null && energyCons.Station == this.Station) { this.Text.text = string.Format("{0}", energyCons.EnergyConsumed.ToString("F1")); } }
public static byte[] Serialize(INetMsg msg) { var networkWriter = new NetworkWriter(); uint index = GetMsgIndexFromType(msg.GetType()); networkWriter.WritePackedUInt32(index); ((MessageBase)msg).Serialize(networkWriter); return(networkWriter.AsArray()); }
public void ReceiveMsg(INetMsg msg, int _) { var scanTargetMsg = msg as ScanTargetMsg; if (scanTargetMsg == null) { return; } Debug.Log("[SensorsAndWeapons] Received :" + scanTargetMsg); switch (scanTargetMsg.Action) { case ScanTargetMsg.Type.Add: { var newSensorTargetObj = (GameObject)Instantiate(this.SensorsTargetPrefab, Vector3.zero, Quaternion.identity); newSensorTargetObj.GetComponent <SensorsTarget>().Target = scanTargetMsg.ScanTarget; newSensorTargetObj.transform.SetParent(this.TargetsTrans); newSensorTargetObj.transform.localScale = Vector3.one; break; } case ScanTargetMsg.Type.Remove: { foreach (Transform sesnorTargetObj in this.TargetsTrans) { var target = sesnorTargetObj.GetComponent <SensorsTarget>().Target; if (target.ID == scanTargetMsg.ScanTarget.ID) { Destroy(sesnorTargetObj.gameObject); break; } } break; } case ScanTargetMsg.Type.Update: { foreach (Transform sensorTargetObj in this.TargetsTrans) { var sensorTarget = sensorTargetObj.GetComponent <SensorsTarget>(); if (sensorTarget.Target.ID == scanTargetMsg.ScanTarget.ID) { sensorTarget.Target = scanTargetMsg.ScanTarget; break; } } break; } default: break; } this.OrderTargets(); }
void SetAllegiance(INetMsg msg, int connectionId) { if (msg is StationSelectMsg) { this.allegiances[connectionId] = msg.Allegiance; } else { msg.Allegiance = this.allegiances[connectionId]; } }
public void ReceiveMsg(INetMsg msg, int connectionId) { var thrusterMsg = msg as ThrusterMsg; if (thrusterMsg != null) { if (thrusterMsg.Allegiance != this.Allegiance) { return; } var thruster = this.Thrusters[(int)thrusterMsg.type]; thruster.IsActive = thrusterMsg.activate; } }
public void ReceiveMsg(INetMsg msg, int _) { var scanTargetMsg = msg as ScanTargetMsg; if (scanTargetMsg == null) return; Debug.Log("[SensorsAndWeapons] Received :" + scanTargetMsg); switch (scanTargetMsg.Action) { case ScanTargetMsg.Type.Add: { var newSensorTargetObj = (GameObject)Instantiate(this.SensorsTargetPrefab, Vector3.zero, Quaternion.identity); newSensorTargetObj.GetComponent<SensorsTarget>().Target = scanTargetMsg.ScanTarget; newSensorTargetObj.transform.SetParent( this.TargetsTrans ); newSensorTargetObj.transform.localScale = Vector3.one; break; } case ScanTargetMsg.Type.Remove: { foreach(Transform sesnorTargetObj in this.TargetsTrans) { var target = sesnorTargetObj.GetComponent<SensorsTarget>().Target; if (target.ID == scanTargetMsg.ScanTarget.ID) { Destroy( sesnorTargetObj.gameObject ); break; } } break; } case ScanTargetMsg.Type.Update: { foreach(Transform sensorTargetObj in this.TargetsTrans) { var sensorTarget = sensorTargetObj.GetComponent<SensorsTarget>(); if (sensorTarget.Target.ID == scanTargetMsg.ScanTarget.ID) { sensorTarget.Target = scanTargetMsg.ScanTarget; break; } } break; } default: break; } this.OrderTargets(); }
public void Send(INetMsg msg) { if (this.isHost) { Debug.LogFormat("[CoreNetwork] [HOST] Sending to clients : {0}", msg); } else { Debug.LogFormat("[CoreNetwork] [Client] Sending to host : {0}", msg); } byte[] data = MessageHandler.Serialize(msg); this.SendToAll(data); }
void PushMessage(int connectionId, INetMsg msg) { Debug.LogFormat("[CoreNetwork] Received message from {0} , {1}, {2}", connectionId, msg, msg.Allegiance); if (!this.isHost && msg.Allegiance != Global.Allegiance) { Debug.LogFormat("[CoreNetwork] Message ignored, different allegiance"); return; } foreach (var receiver in this.receivers) { receiver.ReceiveMsg(msg, connectionId); } }
public void ReceiveMsg(INetMsg msg, int connectionId) { }
public void Send(INetMsg msg) { }
public void Send(INetMsg msg){}
void PushMessage(int connectionId, INetMsg msg) { Debug.LogFormat("[CoreNetwork] Received message from {0} , {1}, {2}", connectionId, msg, msg.Allegiance); if (!this.isHost && msg.Allegiance != Global.Allegiance) { Debug.LogFormat("[CoreNetwork] Message ignored, different allegiance"); return; } foreach(var receiver in this.receivers) { receiver.ReceiveMsg(msg, connectionId); } }
public void Send(INetMsg msg) { if (this.isHost) { Debug.LogFormat("[CoreNetwork] [HOST] Sending to clients : {0}", msg); } else { Debug.LogFormat("[CoreNetwork] [Client] Sending to host : {0}", msg); } byte[] data = MessageHandler.Serialize(msg); this.SendToAll( data ); }