// Update is called once per frame void OnGUI() { if (GUI.Button(new Rect(0, 0, 78, 24), "connect")) { NetSystem.getInstance().Connect("127.0.0.1", 30000, OnConnect); } if (GUI.Button(new Rect(78, 0, 78, 24), "close")) { NetSystem.getInstance().Close(); } if (GUI.Button(new Rect(0, 24, 78, 24), "send->")) { SendTest(); } if (GUI.Button(new Rect(0, 24 * 2, 78, 24), "start send->")) { isSend = true; } if (GUI.Button(new Rect(0, 24 * 3, 78, 24), "stop send->")) { isSend = false; } }
private void processPacket() { if (!NetSystem.getInstance().m_isConnected) { //如果链接已经关闭,则不处理之后的消息 return; } if (m_messageQueue.Count <= 0) { return; } if (m_isPacketProcessing) { Debug.LogError("消息出现阻塞"); return; } m_isPacketProcessing = true; int _msgCount = m_messageQueue.Count; //一次将消息队列中堆积的消息都处理掉 for (int i = 0; i < _msgCount; ++i) { DispenseMsg(); } m_isPacketProcessing = false; MESSAGE_COUNT = m_messageQueue.Count; //回调执行下一条消息 //processPacket(); }
// Use this for initialization void Start() { //NetSystem.getInstance ().testZIP (); NetSystem.getInstance().Register(new Msg_SC_Data()); NetSystem.getInstance().SetOnCmdCallBack(OnCmd); }
public IEnumerator WorldTestWithEnumeratorPasses() { UnityEngine.SceneManagement.SceneManager.LoadScene("MainScene"); yield return(null); NetSystem NetSys = GameObject.FindObjectOfType <NetSystem>(); Assert.NotNull(NetSys); PlayerClient PC = GameObject.FindObjectOfType <PlayerClient>(); Assert.NotNull(PC); MultiMenu MM = GameObject.FindObjectOfType <MultiMenu>(); Assert.NotNull(MM); Assert.AreSame(NetSys, MM.NetSystem, "MultiMenu and the Scene have Diffrent NetSystems"); yield return(null); MM.HostGame(); Color PlayerColor = Random.ColorHSV(); Debug.Log($"Random Color Selected: {PlayerColor}"); PC.CP.C = PlayerColor; yield return(new WaitUntil(() => MM.NetSystem.isNetworkActive)); Assert.AreEqual(PlayerColor, PC.NP.Color); Assert.AreEqual(PlayerColor, PC.PB.Body.GetComponent <SpriteRenderer>().color); yield return(new WaitForSeconds(10)); Assert.Less(PC.PB.Body.rb.velocity.magnitude, .01f, "The player was moving after one second with no interaction"); }
public static NetSystem getInstance() { if (instance == null) { GameObject gameObject = new GameObject("NetSystem"); DontDestroyOnLoad(gameObject); instance = gameObject.AddComponent <NetSystem>(); } return(instance); }
public virtual void EnterScene(string psid) { var entity = GetPlayer(psid); if (entity == null) { return; } NetSystem.all2me(entity); }
public void Send() { if (sendBuffer == null) { //typeof(this);// this.GetType (); sendBuffer = new BytesBuffer(512); } serialize(); NetSystem.getInstance().sendCmd(this); }
public virtual void EnterScene(string psid) { var entity = GetPlayer(psid); if (entity == null) { return; } entity.enabled = true; NetSystem.all2me(entity); NetSystem.me2all(entity); enabled = true; OnStart(); //重置开始时间 }
void OnGUI() { //Base Settings GUILayout.Label("Base Settings", EditorStyles.boldLabel); arSystem = (ARSystem)EditorGUILayout.EnumPopup("AR System", arSystem); netSystem = (NetSystem)EditorGUILayout.EnumPopup("Networking System", netSystem); if (GUILayout.Button("Change Settings")) { SetupARSystem(arSystem); SetupNetSystem(netSystem); } if (GUILayout.Button("Setup Scene")) { AWSceneConfig.SetupScene(); } }
void SendHeartCmd() { if (Time.time - HeartSendTime > 5f) { if (HeartCount > 3) { //心跳超过3次没有回应 断线 NetSystem.getInstance().Close(); return; } /* * userSceneHeartCmd send = new userSceneHeartCmd(); * send.serialize(); * send.SendCmd(); */ HeartSendTime = Time.time; HeartBegin = Time.time; HeartCount++; } }
void DispenseMsg() { //解析消息的协议头 BytesBuffer _msgBuffer = m_messageQueue.Dequeue(); if (_msgBuffer.bytes.Length < 4) { m_isPacketProcessing = false; MESSAGE_COUNT = m_messageQueue.Count; Debug.LogError("收到错误的协议,抛弃"); return; } byte _cmd = _msgBuffer.readByte(); byte _para = _msgBuffer.readByte(); uint _dwTime = _msgBuffer.readUInt32(); Debug.Log("[RECV]cmd :" + _cmd.ToString() + " para : " + _para.ToString()); if (_cmd == 2 && _para == 15) { //心跳协议 不需要处理 RecvHeartCmd(); return; } if (NetSystem.getInstance().GetSendLock) { //发送加锁 需要判断收到的消息是否可以进行解锁 if (GET_MESSAGE_KEY(_cmd, _para) == NetSystem.getInstance().GetUnLockKey) { NetSystem.getInstance().sendUnLock(); } } StartCoroutine(TriigerEvent(GET_MESSAGE_KEY(_cmd, _para), _cmd, _para, _msgBuffer)); }
public void Send(int _lock_cmd) { NetSystem.getInstance().sendCmd_And_Lock(this, _lock_cmd); }
void SetupNetSystem(NetSystem netSystem) { AWSceneConfig.netSystem = netSystem; Debug.Log("Networking System changed to " + AWSceneConfig.netSystem); }
public static void Postfix() => NetSystem.Reset();