websocket相关代码改动

This commit is contained in:
huyulong 2024-11-29 20:05:55 +08:00
parent 03d13f552b
commit b025a98b33
6 changed files with 87 additions and 24 deletions

View File

@ -4488,8 +4488,9 @@ MonoBehaviour:
panelContent: {fileID: 1145997501} panelContent: {fileID: 1145997501}
personItemPrefab: {fileID: 8573669611114071623, guid: d1942d5ee12cbec428172f221efb03cc, type: 3} personItemPrefab: {fileID: 8573669611114071623, guid: d1942d5ee12cbec428172f221efb03cc, type: 3}
scenePanelPrefab: {fileID: 6740850324693622957, guid: a15ee694d5f79864d816998fae77116d, type: 3} scenePanelPrefab: {fileID: 6740850324693622957, guid: a15ee694d5f79864d816998fae77116d, type: 3}
scrollRect: {fileID: 1435623615} peopleWindowsPrefab: {fileID: 0}
sceneText: {fileID: 0} sceneText: {fileID: 0}
scrollRect: {fileID: 1435623615}
--- !u!1 &618256458 --- !u!1 &618256458
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -16532,6 +16533,7 @@ MonoBehaviour:
panel: {fileID: 618256462} panel: {fileID: 618256462}
personnelPrefabs: {fileID: 6013369223040019574, guid: f04ec64a2be229743b6f9e94c0082cea, type: 3} personnelPrefabs: {fileID: 6013369223040019574, guid: f04ec64a2be229743b6f9e94c0082cea, type: 3}
classPrefab: {fileID: 3487660197001363887, guid: e01c09bf4e995934e9ae95f586ed76e9, type: 3} classPrefab: {fileID: 3487660197001363887, guid: e01c09bf4e995934e9ae95f586ed76e9, type: 3}
content: {fileID: 311481292}
--- !u!1001 &1667194939 --- !u!1001 &1667194939
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -3451,7 +3451,9 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 1068997307} - component: {fileID: 1068997307}
- component: {fileID: 1068997310}
- component: {fileID: 1068997306} - component: {fileID: 1068997306}
- component: {fileID: 1068997309}
- component: {fileID: 1068997305} - component: {fileID: 1068997305}
- component: {fileID: 1068997308} - component: {fileID: 1068997308}
m_Layer: 0 m_Layer: 0
@ -3547,6 +3549,35 @@ MonoBehaviour:
verticalAimingSpeed: 6 verticalAimingSpeed: 6
maxVerticalAngle: 30 maxVerticalAngle: 30
minVerticalAngle: -60 minVerticalAngle: -60
--- !u!114 &1068997309
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1068997304}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c68b1dcfbba61b44ca68572c16b16b95, type: 3}
m_Name:
m_EditorClassIdentifier:
token:
wEBScriptListener: {fileID: 1068997310}
--- !u!114 &1068997310
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1068997304}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 44720823678ca7c42a08f4409ab025ff, type: 3}
m_Name:
m_EditorClassIdentifier:
serverIP: ws://124.221.149.22
serverPort: 38445
type:
--- !u!1 &1120021972 --- !u!1 &1120021972
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -7914,3 +7945,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ea3c4e24ebc42194181651236cdf30f1, type: 3} m_Script: {fileID: 11500000, guid: ea3c4e24ebc42194181651236cdf30f1, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nstate: 1

View File

@ -3,7 +3,6 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Unity.VisualScripting.Antlr3.Runtime; using Unity.VisualScripting.Antlr3.Runtime;
using UnityEditor.PackageManager;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
@ -48,7 +47,7 @@ public class LoginPanel : MonoBehaviour
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody)); string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody));
Debug.Log("登录" + response); Debug.Log("登录" + response);
// 解析服务器返回的数据 // 解析服务器返回的数据
server serverData = JsonConvert.DeserializeObject<server>(response); loginResponse serverData = JsonConvert.DeserializeObject<loginResponse>(response);
//token = serverData.data.access_token; //token = serverData.data.access_token;
Debug.Log(serverData.data.access_token); Debug.Log(serverData.data.access_token);

View File

@ -12,9 +12,10 @@ using UnityWebSocket;
/// </summary> /// </summary>
public class WEBScriptListener: MonoBehaviour public class WEBScriptListener: MonoBehaviour
{ {
public string serverIP = "ws://192.168.3.110"; //public string serverIP = "ws://192.168.3.110";
public string serverIP = "ws://124.221.149.22";
//服务器端口 //服务器端口
public int serverPort = 8445; public int serverPort = 38445;
WebSocket socket; WebSocket socket;
public string type; // 类型 public string type; // 类型
public delegate void MyCallback(byte[] data); public delegate void MyCallback(byte[] data);
@ -22,6 +23,7 @@ public class WEBScriptListener: MonoBehaviour
public void ConcatWEBSocket() public void ConcatWEBSocket()
{ {
socket = new WebSocket($"{serverIP}:{serverPort}/safety/cloud"); socket = new WebSocket($"{serverIP}:{serverPort}/safety/cloud");
Debug.Log($"{serverIP}:{serverPort}/safety/cloud");
socket.OnOpen += Socket_OnOpen; socket.OnOpen += Socket_OnOpen;
socket.OnMessage += Socket_OnMessage; socket.OnMessage += Socket_OnMessage;
socket.OnError += Socket_OnError; socket.OnError += Socket_OnError;

View File

@ -21,23 +21,23 @@ public class test : MonoBehaviour
public string username = "13699802230"; public string username = "13699802230";
public string password = "YYL2230!"; public string password = "YYL2230!";
} }
public async void loging() //public async void loging()
{ //{
auth_login auth_Login = new auth_login(); // auth_login auth_Login = new auth_login();
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login)); // string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login));
// ½âÎö·þÎñÆ÷·µ»ØµÄÊý¾Ý // // 解析服务器返回的数据
server serverData = JsonConvert.DeserializeObject<server>(response); // server serverData = JsonConvert.DeserializeObject<server>(response);
token = serverData.data.access_token; // token = serverData.data.access_token;
//Debug.Log(setverData.msg); // //Debug.Log(setverData.msg);
} //}
//登录 //登录
void lodingWebSocket() void lodingWebSocket()
{ {
LoginRequest data = new LoginRequest(); LoginRequest data = new LoginRequest();
data.UserId = "1846032755921199105"; data.UserId = "1845037177556934657";
data.Account = "13152628999"; data.Account = "17311259169";
WSMessage msg = new WSMessage(); WSMessage msg = new WSMessage();
@ -246,6 +246,23 @@ public class test : MonoBehaviour
wEBScriptListener.SendMessageByte(sendData); wEBScriptListener.SendMessageByte(sendData);
} }
void Location()
{
MoveResponse data = new MoveResponse();
data.RoomId = "168888";
WSMessage msg = new WSMessage();
msg.Module = "move";
msg.ServiceName = "Location";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
MoveResponse login = ProtoBufffer.DeSerialize<MoveResponse>(deinfo.Data.ToByteArray());
Debug.Log("推送npc和玩家的信息");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
@ -262,14 +279,15 @@ public class test : MonoBehaviour
if (wEBScriptListener != null) if (wEBScriptListener != null)
{ {
lodingWebSocket(); lodingWebSocket();
JoinRoom(); //JoinRoom();
//Heartbeat(); //Heartbeat();
//BroadcastMessage(); //BroadcastMessage();
//UpFps(); //UpFps();
PickUpProp(); //PickUpProp();
StartUseProp(); //StartUseProp();
StopUseProp(); //StopUseProp();
//RoomStartTime(); //RoomStartTime();
//Location();
} }
} }
@ -284,6 +302,7 @@ public class test : MonoBehaviour
//监听 //监听
//登录 //登录
case "hall.Login": case "hall.Login":
Debug.Log("-=====--");
LoginResponse user = ProtoBufffer.DeSerialize<LoginResponse>(bytes); LoginResponse user = ProtoBufffer.DeSerialize<LoginResponse>(bytes);
Debug.Log(user.Message); Debug.Log(user.Message);
break; break;
@ -301,6 +320,7 @@ public class test : MonoBehaviour
UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize<UserJoinResponse>(bytes); UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize<UserJoinResponse>(bytes);
Debug.Log("玩家昵称:" + userJoinResponse.NickName + ",房间:" + userJoinResponse.RoomId.ToString() + ",用户角色"+ userJoinResponse.RoleName); Debug.Log("玩家昵称:" + userJoinResponse.NickName + ",房间:" + userJoinResponse.RoomId.ToString() + ",用户角色"+ userJoinResponse.RoleName);
Debug.Log(userJoinResponse.IncidentPosition); Debug.Log(userJoinResponse.IncidentPosition);
Debug.Log(userJoinResponse);
break; break;
// //
@ -325,6 +345,12 @@ public class test : MonoBehaviour
Debug.Log("PropId:" + stopuseProp); Debug.Log("PropId:" + stopuseProp);
break; break;
case "move.Location":
Debug.Log("move.Location接受到了");
MoveResponse moveResponse = ProtoBufffer.DeSerialize<MoveResponse>(bytes);
Debug.Log(moveResponse.MoveData);
break;
//case "prop.CreateNpc": //case "prop.CreateNpc":
// MoveResponse moveResponse = ProtoBufffer.DeSerialize<MoveResponse>(bytes); // MoveResponse moveResponse = ProtoBufffer.DeSerialize<MoveResponse>(bytes);
@ -342,6 +368,7 @@ public class test : MonoBehaviour
// //Debug.Log("PropId:" + joinRoomRequest.RoomId); // //Debug.Log("PropId:" + joinRoomRequest.RoomId);
// break; // break;
} }
} }

View File

@ -13,6 +13,7 @@ using UnityEngine.Networking;
public class web : MonoBehaviour public class web : MonoBehaviour
{ {
public const string URL = "http://192.168.3.103:8089"; // 被注释掉的服务器地址(常量) public const string URL = "http://192.168.3.103:8089"; // 被注释掉的服务器地址(常量)
//public const string URL = "ws://124.221.149.22:38445/safety/cloud"; // 被注释掉的服务器地址(常量)
// 存储服务器返回的Cookie // 存储服务器返回的Cookie
private static Dictionary<string, string> cookieJar = new Dictionary<string, string>(); private static Dictionary<string, string> cookieJar = new Dictionary<string, string>();