This commit is contained in:
YangHua 2023-11-22 18:36:46 +08:00
parent 1a802163c0
commit 3ac7c43f30
4 changed files with 14 additions and 56 deletions

View File

@ -144,7 +144,6 @@ public class Taskpanel : MonoBehaviour
public void OnLeaveRoom()
{
//_ = AdamSync.SyncCreateRoom.SendMessageAsync($"send2room offline,{GlobalFlag.currentUser.user_id}");
string _msg = "leaveroom ";
_ = AdamSync.SyncCreateRoom.SendMessageAsync(_msg);
//SceneManager.LoadScene("SampleScene");

View File

@ -202,7 +202,7 @@ public class GameManager : MonoSingleton<GameManager>
}
break;
case "offline":
RemovePlayer(ulong.Parse(data[1]));
break;
default:
break;

View File

@ -24,10 +24,8 @@ public class UIBootstrap : MonoSingleton<UIBootstrap>
t = Jsonanalyze.FromJson<Traininginformation>(editinformation.data[i].VirtualPath);
traininginformations.Add(t);
}
AdamSync.SyncCreateRoom.getRoomsRequset += OnGetRooms;
AdamSync.SyncCreateRoom.getroomusersRequset += OnGetRoomsUsers;
AdamSync.SyncCreateRoom.send2roomRequset += OnGetRoomsInfo;
AdamSync.SyncCreateRoom.leaveRoomRequset += OnOtherPlayerOffline;
AdamSync.SyncCreateRoom.send2worldRequset += OnGetWorldInfo;
}
@ -82,72 +80,29 @@ public class UIBootstrap : MonoSingleton<UIBootstrap>
}
public void OnGetRooms(string msg)
public void OnGetWorldInfo(string msg)
{
Debug.Log("OnGetRooms====" + msg);
}
public void OnGetRoomsUsers(string msg)
{
Debug.Log("OnGetRooms====" + msg);
}
public void OnGetRoomsInfo(string msg)
{
Debug.Log("OnGetRooms====" + msg);
Debug.Log("OnGetWorldInfo====" + msg);
GameManager.Instance.RemovePlayer(ulong.Parse(msg));
}
public void OnOtherPlayerOffline(string msg)
{
string[] data = msg.Split(',');
Debug.Log(data[1]);
if (data[0] == "offline")
{
GameManager.Instance.RemovePlayer(ulong.Parse(data[1]));
_ = AdamSync.SyncCreateRoom.SendMessageAsync($"send2world {GlobalFlag.currentUser.user_id}");
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("o"))
{
string info = "getrooms ";
Debug.Log(info);
_ = AdamSync.SyncCreateRoom.SendMessageAsync(info);
}
if (Input.GetKeyDown("g"))
{
string info = "getroomusers ";
Debug.Log(info);
_ = AdamSync.SyncCreateRoom.SendMessageAsync(info);
}
if (Input.GetKeyDown("i"))
{
string info = "send2room " + "进入房间";
Debug.Log(info);
_ = AdamSync.SyncCreateRoom.SendMessageAsync(info);
}
if (Input.GetKeyDown("l"))
{
string msg = "leaveroom ";
_ = AdamSync.SyncCreateRoom.SendMessageAsync(msg);
}
}
private void OnDisable()
{
Debug.Log("OnDisable");
AdamSync.SyncCreateRoom.getRoomsRequset -= OnGetRooms;
AdamSync.SyncCreateRoom.getroomusersRequset -= OnGetRoomsUsers;
AdamSync.SyncCreateRoom.send2roomRequset -= OnGetRoomsInfo;
AdamSync.SyncCreateRoom.leaveRoomRequset -= OnOtherPlayerOffline;
}
private void OnDestory()
{
Debug.Log("OnDestory");
AdamSync.SyncCreateRoom.getRoomsRequset -= OnGetRooms;
AdamSync.SyncCreateRoom.getroomusersRequset -= OnGetRoomsUsers;
AdamSync.SyncCreateRoom.send2roomRequset -= OnGetRoomsInfo;
AdamSync.SyncCreateRoom.leaveRoomRequset -= OnOtherPlayerOffline;
}
}

View File

@ -28,6 +28,7 @@ namespace AdamSync
public static Action<string> getroomusersRequset;
public static Action<string> send2roomRequset;
public static Action<string> send2userRequset;
public static Action<string> send2worldRequset;
public static async Task StartLinkTCPServer(string serverIp, int serverPort)
@ -118,6 +119,9 @@ namespace AdamSync
case "send2user":
send2userRequset?.Invoke(commands[1]);
break;
case "send2world":
send2worldRequset?.Invoke(commands[1]);
break;
}
}
}