This commit is contained in:
陈向学 2024-02-27 15:58:01 +08:00
parent 1f491565a4
commit 1c478006bc
1 changed files with 8 additions and 159 deletions

View File

@ -17,38 +17,10 @@ public class LoadManage : MonoBehaviour
/// </summary>
[DisplayOnly]
public string currentRoomArea;
/// <summary>
/// 训练状态
/// </summary>
public static ProgramState programState = ProgramState.;
/// <summary>
/// 是否暂停
/// </summary>
public static bool isPause;
/// <summary>
/// 与RoomServer通信
/// </summary>
[DisplayOnly]
public MyNetMQClient RSclient;
public static Action<string> registRequset;
public static Action<string> getusersRequset;
public static Action<string> createRoomRequset;
public static Action<string> getRoomsRequset;
public static Action<string> getownRoomsRequset;
public static Action<string> joinRoomRequset;
public static Action<string> joinsRequset;
public static Action<string> leaveRoomRequset;
public static Action<string> closeRoomRequset;
public static Action<ulong, string, string> playerInfoRequset;
public static Action<string> getroomusersRequset;
public static Action<string> send2roomRequset;
public static Action<string> send2userRequset;
public static Action<string> send2worldRequset;
public Action<byte[]> reciveData;
private void Awake()
{
Instance = this;
@ -67,15 +39,15 @@ public class LoadManage : MonoBehaviour
Screen.sleepTimeout = SleepTimeout.NeverSleep;
string ip = "";
//配置
File.ReadAllLines(Application.streamingAssetsPath + "/MainSetting.txt").ToList().ForEach(line =>
File.ReadAllLines(Application.streamingAssetsPath + "/MainSetting.txt").ToList().ForEach(line =>
{
if(line.Trim(' ').StartsWith("serverIP="))
if (line.Trim(' ').StartsWith("serverIP="))
{
string[] tmps = line.Trim(' ').Split('=');
ip= tmps[1];
ip = tmps[1];
}
});
CreateRoomServerClient(string.Format("tcp://{0}:8889",ip), string.Format("tcp://{0}:8888",ip));
CreateRoomServerClient(string.Format("tcp://{0}:8889", ip), string.Format("tcp://{0}:8888", ip));
MyNetMQClient.instance._netMqListener.SubTopic("Room");
SceneManager.LoadScene("SampleScene");
}
@ -112,64 +84,7 @@ public class LoadManage : MonoBehaviour
/// <param name="stS"></param>
private void ReciveFromRoomServerInThread(st_Motions stS)
{
if (stS.area == "Room")
{
//同步消息
//if (programState == ProgramState.进行中)
//{
// if (stS.m_iOperaType == 10006)
// {
// //单值同步
// int syncid = BitConverter.ToInt32(stS.m_sOperaData, 0);
// if (LoadManage.Instance.me.SyncId != syncid)
// {
// int legth = BitConverter.ToInt32(stS.m_sOperaData, 4);
// string id = Encoding.UTF8.GetString(stS.m_sOperaData, 8, legth);
// if (OneValueSyncObject.OneAxisSyncObjectList.ContainsKey(id))
// {
// if (stS.m_sOperaData[9 + legth] == 0)
// {
// //无回调
// OneValueSyncObject.OneAxisSyncObjectList[id].SetValue(8 + legth, stS.m_sOperaData);
// }
// else
// {
// //有回调
// RSclient._netMqListener.AddToMono(stS);
// }
// }
// }
// }
// else if (stS.m_iOperaType == 10007)
// {
// //坐标角度同步
// int syncid = BitConverter.ToInt32(stS.m_sOperaData, 0);
// if (LoadManage.Instance.me.SyncId != syncid)
// {
// int legth = BitConverter.ToInt32(stS.m_sOperaData, 4);
// string id = Encoding.UTF8.GetString(stS.m_sOperaData, 8, legth);
// if (FunctionSync_PositionRoate.positionRoateSyncObejctList.ContainsKey(id))
// {
// FunctionSync_PositionRoate.positionRoateSyncObejctList[id].SetValue(8 + legth, stS.m_sOperaData);
// }
// }
// }
// else if (stS.m_iOperaType == 61)
// {
// //心跳检测
// //XinTiaoCheck();
// }
// else
// {
// RSclient._netMqListener.AddToMono(stS);
// }
//}
}
else if(stS.area == "System")
{
//系统消息
RSclient._netMqListener.AddToMono(stS);
}
RSclient._netMqListener.AddToMono(stS);
}
/// <summary>
@ -178,76 +93,10 @@ public class LoadManage : MonoBehaviour
/// <param name="data"></param>
public void ReciveFromRoomServerInMono(st_Motions stS)
{
#if !UNITY_EDITOR
try
if (reciveData != null)
{
#endif
string message = Encoding.UTF8.GetString(stS.m_sOperaData);
string[] commands = message.Split(' ');
if (commands.Length > 0)
{
//Debug.Log($"<color=green>commands[0]===={commands[0]}</color>");
switch (commands[0])
{
case "regist":
registRequset?.Invoke(commands[1]);
break;
case "getusers":
getusersRequset?.Invoke(commands[1]);
break;
case "createroom":
createRoomRequset?.Invoke(commands[1]);
break;
case "getrooms":
getRoomsRequset?.Invoke(commands[1]);
break;
case "getownrooms":
getownRoomsRequset?.Invoke(commands[1]);
break;
case "joinroom":
joinRoomRequset?.Invoke(commands[1]);
break;
case "joins":
joinsRequset?.Invoke(commands[1]);
break;
case "leaveroom":
leaveRoomRequset?.Invoke(commands[1]);
break;
case "closeroom":
closeRoomRequset?.Invoke(commands[1]);
break;
case "player":
string[] data = commands[1].Split(';');
if (data.Length == 3)
{
playerInfoRequset?.Invoke(ulong.Parse(data[0]), data[1], data[2]);
}
break;
case "getroomusers":
getroomusersRequset?.Invoke(commands[1]);
break;
case "send2room":
send2roomRequset?.Invoke(commands[1]);
break;
case "send2user":
send2userRequset?.Invoke(commands[1]);
break;
case "send2world":
send2worldRequset?.Invoke(commands[1]);
break;
}
reciveData(stS.m_sOperaData);
}
#if !UNITY_EDITOR
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
#endif
}
private void OnDestroy()