using System; using System.Collections.Generic; using System.Text; using UnityEngine; using UnityEngine.SceneManagement; using System.Linq; using System.Collections; using System.IO; using Newtonsoft.Json.Linq; public class LoadManage : MonoBehaviour { public static LoadManage Instance; /// /// 房间域 "Room" /// [DisplayOnly] public string currentRoomArea; [DisplayOnly] public MyNetMQClient RSclient; public Action reciveData; private void Awake() { Instance = this; DontDestroyOnLoad(gameObject); #if UNITY_EDITOR UnityEngine.Debug.unityLogger.logEnabled = true; #else UnityEngine.Debug.unityLogger.logEnabled = false; #endif } void Start() { //设置不休眠 Screen.sleepTimeout = SleepTimeout.NeverSleep; string ip = ""; //配置 File.ReadAllLines(Application.streamingAssetsPath + "/MainSetting.txt").ToList().ForEach(line => { if (line.Trim(' ').StartsWith("serverIP=")) { string[] tmps = line.Trim(' ').Split('='); ip = tmps[1]; } }); CreateRoomServerClient(string.Format("tcp://{0}:8889", ip), string.Format("tcp://{0}:8888", ip)); //MyNetMQClient.instance._netMqListener.SubTopic("Room"); SceneManager.LoadScene("SampleScene"); } /// /// 创建与roomServer通信的客户端 /// public void CreateRoomServerClient(string roomServerSubIP, string roomServerPubIP) { if (RSclient == null) { //测试 //roomServerPubIP = "tcp://192.168.1.125:56987"; // roomServerSubIP = "tcp://192.168.1.125:56991"; RSclient = gameObject.AddComponent(); RSclient.Init(roomServerPubIP, roomServerSubIP, ReciveFromRoomServerInThread, ReciveFromRoomServerInMono, "roomServer"); Debug.Log("开启roomServer:" + roomServerPubIP + "------" + roomServerSubIP); } } public void RemoveRoomServerClient() { if (RSclient != null) { RSclient.Destroy(); // RSclient = null; Debug.Log("RSclient置空"); } } /// /// RoomServer,mono /// /// private void ReciveFromRoomServerInThread(st_Motions stS) { RSclient._netMqListener.AddToMono(stS); } /// /// RoomServer,mono /// /// public void ReciveFromRoomServerInMono(st_Motions stS) { if (reciveData != null) { reciveData(stS.m_sOperaData); } } private void OnDestroy() { Debug.Log("OnDestroy"); if (RSclient != null) { RSclient.Destroy(); } } }