add 接口相关代码
This commit is contained in:
parent
dc6bcb85bf
commit
5382863b0b
BIN
xiaofang/Assets/Plugins/System.Buffers.dll
Normal file
BIN
xiaofang/Assets/Plugins/System.Buffers.dll
Normal file
Binary file not shown.
33
xiaofang/Assets/Plugins/System.Buffers.dll.meta
Normal file
33
xiaofang/Assets/Plugins/System.Buffers.dll.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 981e61f2f9d05f14080ac9c319bce628
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
xiaofang/Assets/Plugins/System.Memory.dll
Normal file
BIN
xiaofang/Assets/Plugins/System.Memory.dll
Normal file
Binary file not shown.
33
xiaofang/Assets/Plugins/System.Memory.dll.meta
Normal file
33
xiaofang/Assets/Plugins/System.Memory.dll.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da0a789a7c2e0f541b10c9faf4986ab5
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/Scenes/Tmap 1.meta
Normal file
8
xiaofang/Assets/Scenes/Tmap 1.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5b1839bbbe1e494faf78bb0559cda3a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -12660,6 +12660,68 @@ Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 434342, guid: dae965d9ed8802048877e54ec2f0be78, type: 3}
|
||||
m_PrefabInstance: {fileID: 1517804048}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &1526740600
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1526740602}
|
||||
- component: {fileID: 1526740601}
|
||||
- component: {fileID: 1526740603}
|
||||
m_Layer: 0
|
||||
m_Name: GameObject (1)
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1526740601
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1526740600}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c68b1dcfbba61b44ca68572c16b16b95, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
token:
|
||||
wEBScriptListener: {fileID: 1526740603}
|
||||
--- !u!4 &1526740602
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1526740600}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 27
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1526740603
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1526740600}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 44720823678ca7c42a08f4409ab025ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
serverIP: ws://192.168.3.110
|
||||
serverPort: 8445
|
||||
type:
|
||||
--- !u!1001 &1542437476
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
BIN
xiaofang/Assets/Scenes/Tmap 1/NavMesh.asset
Normal file
BIN
xiaofang/Assets/Scenes/Tmap 1/NavMesh.asset
Normal file
Binary file not shown.
8
xiaofang/Assets/Scenes/Tmap 1/NavMesh.asset.meta
Normal file
8
xiaofang/Assets/Scenes/Tmap 1/NavMesh.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce317dc0bb78cd54b84bef351461ff44
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 23800000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
xiaofang/Assets/Script/NewBehaviourScript.cs
Normal file
21
xiaofang/Assets/Script/NewBehaviourScript.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class NewBehaviourScript : MonoBehaviour
|
||||
{
|
||||
|
||||
public int id = 0;
|
||||
public int tpey = 90;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
xiaofang/Assets/Script/NewBehaviourScript.cs.meta
Normal file
11
xiaofang/Assets/Script/NewBehaviourScript.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1728088f42a981c4da46a58c56c1cc84
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -6,9 +6,9 @@ public class auth_login
|
||||
{
|
||||
public string clientId = "e5cd7e4891bf95d1d19206ce24a7b32e";
|
||||
public string grantType = "password";
|
||||
public string userType = "sys_user";
|
||||
public string username = "adminyyl";
|
||||
public string password = "admin123";
|
||||
public string userType = "company_user";
|
||||
public string username = "13699802230";
|
||||
public string password = "YYL2230!";
|
||||
}
|
||||
public class login : MonoBehaviour
|
||||
|
||||
@ -22,7 +22,7 @@ public class login : MonoBehaviour
|
||||
public async void loging()
|
||||
{
|
||||
auth_login auth_Login = new auth_login();
|
||||
|
||||
Debug.Log(JsonUtility.ToJson(auth_Login));
|
||||
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login));
|
||||
Debug.Log(response);
|
||||
// 解析服务器返回的数据
|
||||
|
10
xiaofang/Assets/UnityWebSocket.meta
Normal file
10
xiaofang/Assets/UnityWebSocket.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a48e5bab43b85341bcf6c0f41824959
|
||||
folderAsset: yes
|
||||
timeCreated: 1530672403
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/UnityWebSocket/Demo.meta
Normal file
8
xiaofang/Assets/UnityWebSocket/Demo.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aab4c0dd88d44cd4e817c3f1994407b4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
242
xiaofang/Assets/UnityWebSocket/Demo/DemoScene.unity
Normal file
242
xiaofang/Assets/UnityWebSocket/Demo/DemoScene.unity
Normal file
@ -0,0 +1,242 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 11
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 10
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 2
|
||||
m_BakeBackend: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVRBounces: 2
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringMode: 2
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ShowResolutionOverlay: 1
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_UseShadowmask: 1
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &516737225
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 516737226}
|
||||
- component: {fileID: 516737227}
|
||||
m_Layer: 0
|
||||
m_Name: Main
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &516737226
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 516737225}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &516737227
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 516737225}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c1b55962346f6de40bd5e924df2854fb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
address: wss://echo.websocket.events
|
||||
subProtocols: soap|wamp
|
||||
sendText: Hello UnityWebSocket!
|
||||
--- !u!1 &902376145
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 902376148}
|
||||
- component: {fileID: 902376147}
|
||||
- component: {fileID: 902376146}
|
||||
m_Layer: 0
|
||||
m_Name: Camera
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!81 &902376146
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 902376145}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &902376147
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 902376145}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 2
|
||||
m_BackGroundColor: {r: 0.3301887, g: 0.3301887, b: 0.3301887, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_GateFitMode: 2
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &902376148
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 902376145}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
7
xiaofang/Assets/UnityWebSocket/Demo/DemoScene.unity.meta
Normal file
7
xiaofang/Assets/UnityWebSocket/Demo/DemoScene.unity.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65671216fb4e42d4f89ed6eeca36060d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
200
xiaofang/Assets/UnityWebSocket/Demo/UnityWebSocketDemo.cs
Normal file
200
xiaofang/Assets/UnityWebSocket/Demo/UnityWebSocketDemo.cs
Normal file
@ -0,0 +1,200 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityWebSocket.Demo
|
||||
{
|
||||
public class UnityWebSocketDemo : MonoBehaviour
|
||||
{
|
||||
public string address = "wss://echo.websocket.events";
|
||||
public string sendText = "Hello UnityWebSocket!";
|
||||
|
||||
private IWebSocket socket;
|
||||
|
||||
private bool logMessage = true;
|
||||
private string log = "";
|
||||
private int sendCount;
|
||||
private int receiveCount;
|
||||
private Vector2 scrollPos;
|
||||
private Color green = new Color(0.1f, 1, 0.1f);
|
||||
private Color red = new Color(1f, 0.1f, 0.1f);
|
||||
private Color wait = new Color(0.7f, 0.3f, 0.3f);
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
var scale = Screen.width / 800f;
|
||||
GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scale, scale, 1));
|
||||
var width = GUILayout.Width(Screen.width / scale - 10);
|
||||
|
||||
WebSocketState state = socket == null ? WebSocketState.Closed : socket.ReadyState;
|
||||
|
||||
// draw header
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("SDK Version: " + Settings.VERSION, GUILayout.Width(Screen.width / scale - 100));
|
||||
GUI.color = green;
|
||||
GUILayout.Label($"FPS: {fps:F2}", GUILayout.Width(80));
|
||||
GUI.color = Color.white;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw websocket state
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("State: ", GUILayout.Width(36));
|
||||
GUI.color = WebSocketState.Closed == state ? red : WebSocketState.Open == state ? green : wait;
|
||||
GUILayout.Label($"{state}", GUILayout.Width(120));
|
||||
GUI.color = Color.white;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw address
|
||||
GUI.enabled = state == WebSocketState.Closed;
|
||||
GUILayout.Label("Address: ", width);
|
||||
address = GUILayout.TextField(address, width);
|
||||
|
||||
// draw connect button
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.enabled = state == WebSocketState.Closed;
|
||||
if (GUILayout.Button(state == WebSocketState.Connecting ? "Connecting..." : "Connect"))
|
||||
{
|
||||
socket = new WebSocket(address);
|
||||
socket.OnOpen += Socket_OnOpen;
|
||||
socket.OnMessage += Socket_OnMessage;
|
||||
socket.OnClose += Socket_OnClose;
|
||||
socket.OnError += Socket_OnError;
|
||||
AddLog(string.Format("Connecting..."));
|
||||
socket.ConnectAsync();
|
||||
}
|
||||
|
||||
// draw close button
|
||||
GUI.enabled = state == WebSocketState.Open;
|
||||
if (GUILayout.Button(state == WebSocketState.Closing ? "Closing..." : "Close"))
|
||||
{
|
||||
AddLog(string.Format("Closing..."));
|
||||
socket.CloseAsync();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw input message
|
||||
GUILayout.Label("Message: ");
|
||||
sendText = GUILayout.TextArea(sendText, GUILayout.MinHeight(50), width);
|
||||
|
||||
// draw send message button
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Send") && !string.IsNullOrEmpty(sendText))
|
||||
{
|
||||
socket.SendAsync(sendText);
|
||||
AddLog(string.Format("Send: {0}", sendText));
|
||||
sendCount += 1;
|
||||
}
|
||||
if (GUILayout.Button("Send Bytes") && !string.IsNullOrEmpty(sendText))
|
||||
{
|
||||
var bytes = System.Text.Encoding.UTF8.GetBytes(sendText);
|
||||
socket.SendAsync(bytes);
|
||||
AddLog(string.Format("Send Bytes ({1}): {0}", sendText, bytes.Length));
|
||||
sendCount += 1;
|
||||
}
|
||||
if (GUILayout.Button("Send x100") && !string.IsNullOrEmpty(sendText))
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var text = (i + 1).ToString() + ". " + sendText;
|
||||
socket.SendAsync(text);
|
||||
AddLog(string.Format("Send: {0}", text));
|
||||
sendCount += 1;
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button("Send Bytes x100") && !string.IsNullOrEmpty(sendText))
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var text = (i + 1).ToString() + ". " + sendText;
|
||||
var bytes = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
socket.SendAsync(bytes);
|
||||
AddLog(string.Format("Send Bytes ({1}): {0}", text, bytes.Length));
|
||||
sendCount += 1;
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw message count
|
||||
GUI.enabled = true;
|
||||
GUILayout.BeginHorizontal();
|
||||
logMessage = GUILayout.Toggle(logMessage, "Log Message");
|
||||
GUILayout.Label(string.Format("Send Count: {0}", sendCount));
|
||||
GUILayout.Label(string.Format("Receive Count: {0}", receiveCount));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// draw clear button
|
||||
if (GUILayout.Button("Clear"))
|
||||
{
|
||||
log = "";
|
||||
receiveCount = 0;
|
||||
sendCount = 0;
|
||||
}
|
||||
|
||||
// draw message content
|
||||
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.MaxHeight(Screen.height / scale - 270), width);
|
||||
GUILayout.Label(log);
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void AddLog(string str)
|
||||
{
|
||||
if (!logMessage) return;
|
||||
if (str.Length > 100) str = str.Substring(0, 100) + "...";
|
||||
log += str + "\n";
|
||||
if (log.Length > 22 * 1024)
|
||||
{
|
||||
log = log.Substring(log.Length - 22 * 1024);
|
||||
}
|
||||
scrollPos.y = int.MaxValue;
|
||||
}
|
||||
|
||||
private void Socket_OnOpen(object sender, OpenEventArgs e)
|
||||
{
|
||||
AddLog(string.Format("Connected: {0}", address));
|
||||
}
|
||||
|
||||
private void Socket_OnMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
if (e.IsBinary)
|
||||
{
|
||||
AddLog(string.Format("Receive Bytes ({1}): {0}", e.Data, e.RawData.Length));
|
||||
}
|
||||
else if (e.IsText)
|
||||
{
|
||||
AddLog(string.Format("Receive: {0}", e.Data));
|
||||
}
|
||||
receiveCount += 1;
|
||||
}
|
||||
|
||||
private void Socket_OnClose(object sender, CloseEventArgs e)
|
||||
{
|
||||
AddLog(string.Format("Closed: StatusCode: {0}, Reason: {1}", e.StatusCode, e.Reason));
|
||||
}
|
||||
|
||||
private void Socket_OnError(object sender, ErrorEventArgs e)
|
||||
{
|
||||
AddLog(string.Format("Error: {0}", e.Message));
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
if (socket != null && socket.ReadyState != WebSocketState.Closed)
|
||||
{
|
||||
socket.CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private int frame = 0;
|
||||
private float time = 0;
|
||||
private float fps = 0;
|
||||
private void Update()
|
||||
{
|
||||
frame += 1;
|
||||
time += Time.deltaTime;
|
||||
if (time >= 0.5f)
|
||||
{
|
||||
fps = frame / time;
|
||||
frame = 0;
|
||||
time = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1b55962346f6de40bd5e924df2854fb
|
||||
timeCreated: 1466599118
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
xiaofang/Assets/UnityWebSocket/Plugins.meta
Normal file
9
xiaofang/Assets/UnityWebSocket/Plugins.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4589fa9979d007040b5a807b0304b1ff
|
||||
folderAsset: yes
|
||||
timeCreated: 1466577973
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/UnityWebSocket/Plugins/WebGL.meta
Normal file
8
xiaofang/Assets/UnityWebSocket/Plugins/WebGL.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1a1a6aea65cc413faf8fb4421138b29
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
338
xiaofang/Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib
Normal file
338
xiaofang/Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib
Normal file
@ -0,0 +1,338 @@
|
||||
var WebSocketLibrary =
|
||||
{
|
||||
$webSocketManager:
|
||||
{
|
||||
/*
|
||||
* Map of instances
|
||||
*
|
||||
* Instance structure:
|
||||
* {
|
||||
* url: string,
|
||||
* ws: WebSocket,
|
||||
* subProtocols: string[],
|
||||
* }
|
||||
*/
|
||||
instances: {},
|
||||
|
||||
/* Last instance ID */
|
||||
lastId: 0,
|
||||
|
||||
/* Event listeners */
|
||||
onOpen: null,
|
||||
onMessage: null,
|
||||
onMessageStr: null,
|
||||
onError: null,
|
||||
onClose: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Set onOpen callback
|
||||
*
|
||||
* @param callback Reference to C# static function
|
||||
*/
|
||||
WebSocketSetOnOpen: function(callback)
|
||||
{
|
||||
webSocketManager.onOpen = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set onMessage callback
|
||||
*
|
||||
* @param callback Reference to C# static function
|
||||
*/
|
||||
WebSocketSetOnMessage: function(callback)
|
||||
{
|
||||
webSocketManager.onMessage = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set onMessageStr callback
|
||||
*
|
||||
* @param callback Reference to C# static function
|
||||
*/
|
||||
WebSocketSetOnMessageStr: function(callback)
|
||||
{
|
||||
webSocketManager.onMessageStr = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set onError callback
|
||||
*
|
||||
* @param callback Reference to C# static function
|
||||
*/
|
||||
WebSocketSetOnError: function(callback)
|
||||
{
|
||||
webSocketManager.onError = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set onClose callback
|
||||
*
|
||||
* @param callback Reference to C# static function
|
||||
*/
|
||||
WebSocketSetOnClose: function(callback)
|
||||
{
|
||||
webSocketManager.onClose = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Allocate new WebSocket instance struct
|
||||
*
|
||||
* @param url Server URL
|
||||
*/
|
||||
WebSocketAllocate: function(urlPtr)
|
||||
{
|
||||
var url = UTF8ToString(urlPtr);
|
||||
var id = ++webSocketManager.lastId;
|
||||
webSocketManager.instances[id] = {
|
||||
url: url,
|
||||
ws: null,
|
||||
};
|
||||
|
||||
return id;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add Sub Protocol
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
* @param protocol Sub Protocol
|
||||
*/
|
||||
WebSocketAddSubProtocol: function(instanceId, protocolPtr)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return -1;
|
||||
|
||||
var protocol = UTF8ToString(protocolPtr);
|
||||
|
||||
if (instance.subProtocols == null)
|
||||
instance.subProtocols = [];
|
||||
|
||||
instance.subProtocols.push(protocol);
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove reference to WebSocket instance
|
||||
*
|
||||
* If socket is not closed function will close it but onClose event will not be emitted because
|
||||
* this function should be invoked by C# WebSocket destructor.
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
*/
|
||||
WebSocketFree: function(instanceId)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return 0;
|
||||
|
||||
// Close if not closed
|
||||
if (instance.ws !== null && instance.ws.readyState < 2)
|
||||
instance.ws.close();
|
||||
|
||||
// Remove reference
|
||||
delete webSocketManager.instances[instanceId];
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Connect WebSocket to the server
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
*/
|
||||
WebSocketConnect: function(instanceId)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return -1;
|
||||
if (instance.ws !== null) return -2;
|
||||
|
||||
if (instance.subProtocols != null)
|
||||
instance.ws = new WebSocket(instance.url, instance.subProtocols);
|
||||
else
|
||||
instance.ws = new WebSocket(instance.url);
|
||||
|
||||
instance.ws.onopen = function()
|
||||
{
|
||||
Module.dynCall_vi(webSocketManager.onOpen, instanceId);
|
||||
};
|
||||
|
||||
instance.ws.onmessage = function(ev)
|
||||
{
|
||||
if (ev.data instanceof ArrayBuffer)
|
||||
{
|
||||
var array = new Uint8Array(ev.data);
|
||||
var buffer = _malloc(array.length);
|
||||
writeArrayToMemory(array, buffer);
|
||||
try
|
||||
{
|
||||
Module.dynCall_viii(webSocketManager.onMessage, instanceId, buffer, array.length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_free(buffer);
|
||||
}
|
||||
}
|
||||
else if (typeof ev.data == 'string')
|
||||
{
|
||||
var length = lengthBytesUTF8(ev.data) + 1;
|
||||
var buffer = _malloc(length);
|
||||
stringToUTF8(ev.data, buffer, length);
|
||||
try
|
||||
{
|
||||
Module.dynCall_vii(webSocketManager.onMessageStr, instanceId, buffer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_free(buffer);
|
||||
}
|
||||
}
|
||||
else if (typeof Blob !== 'undefined' && ev.data instanceof Blob)
|
||||
{
|
||||
var reader = new FileReader();
|
||||
reader.onload = function()
|
||||
{
|
||||
var array = new Uint8Array(reader.result);
|
||||
var buffer = _malloc(array.length);
|
||||
writeArrayToMemory(array, buffer);
|
||||
try
|
||||
{
|
||||
Module.dynCall_viii(webSocketManager.onMessage, instanceId, buffer, array.length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader = null;
|
||||
_free(buffer);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(ev.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("[JSLIB WebSocket] not support message type: ", (typeof ev.data));
|
||||
}
|
||||
};
|
||||
|
||||
instance.ws.onerror = function(ev)
|
||||
{
|
||||
var msg = "WebSocket error.";
|
||||
var length = lengthBytesUTF8(msg) + 1;
|
||||
var buffer = _malloc(length);
|
||||
stringToUTF8(msg, buffer, length);
|
||||
try
|
||||
{
|
||||
Module.dynCall_vii(webSocketManager.onError, instanceId, buffer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_free(buffer);
|
||||
}
|
||||
};
|
||||
|
||||
instance.ws.onclose = function(ev)
|
||||
{
|
||||
var msg = ev.reason;
|
||||
var length = lengthBytesUTF8(msg) + 1;
|
||||
var buffer = _malloc(length);
|
||||
stringToUTF8(msg, buffer, length);
|
||||
try
|
||||
{
|
||||
Module.dynCall_viii(webSocketManager.onClose, instanceId, ev.code, buffer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_free(buffer);
|
||||
}
|
||||
instance.ws = null;
|
||||
};
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Close WebSocket connection
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
* @param code Close status code
|
||||
* @param reasonPtr Pointer to reason string
|
||||
*/
|
||||
WebSocketClose: function(instanceId, code, reasonPtr)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return -1;
|
||||
if (instance.ws === null) return -3;
|
||||
if (instance.ws.readyState === 2) return -4;
|
||||
if (instance.ws.readyState === 3) return -5;
|
||||
|
||||
var reason = ( reasonPtr ? UTF8ToString(reasonPtr) : undefined );
|
||||
try
|
||||
{
|
||||
instance.ws.close(code, reason);
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
return -7;
|
||||
}
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Send message over WebSocket
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
* @param bufferPtr Pointer to the message buffer
|
||||
* @param length Length of the message in the buffer
|
||||
*/
|
||||
WebSocketSend: function(instanceId, bufferPtr, length)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return -1;
|
||||
if (instance.ws === null) return -3;
|
||||
if (instance.ws.readyState !== 1) return -6;
|
||||
|
||||
if (typeof HEAPU8 !== 'undefined')
|
||||
instance.ws.send(HEAPU8.buffer.slice(bufferPtr, bufferPtr + length));
|
||||
else if (typeof buffer !== 'undefined')
|
||||
instance.ws.send(buffer.slice(bufferPtr, bufferPtr + length));
|
||||
else
|
||||
return -8; // not support buffer slice
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Send message string over WebSocket
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
* @param stringPtr Pointer to the message string
|
||||
*/
|
||||
WebSocketSendStr: function(instanceId, stringPtr)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return -1;
|
||||
if (instance.ws === null) return -3;
|
||||
if (instance.ws.readyState !== 1) return -6;
|
||||
|
||||
instance.ws.send(UTF8ToString(stringPtr));
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return WebSocket readyState
|
||||
*
|
||||
* @param instanceId Instance ID
|
||||
*/
|
||||
WebSocketGetState: function(instanceId)
|
||||
{
|
||||
var instance = webSocketManager.instances[instanceId];
|
||||
if (!instance) return -1;
|
||||
if (instance.ws === null) return 3; // socket null as closed
|
||||
|
||||
return instance.ws.readyState;
|
||||
}
|
||||
};
|
||||
|
||||
autoAddDeps(WebSocketLibrary, '$webSocketManager');
|
||||
mergeInto(LibraryManager.library, WebSocketLibrary);
|
@ -0,0 +1,42 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd88770aa13fc47b08f87d2145e9ac6e
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Facebook: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
WeixinMiniGame: WeixinMiniGame
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/UnityWebSocket/Scripts.meta
Normal file
8
xiaofang/Assets/UnityWebSocket/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89cd0cf8603ef4069b2f6a5d79cbdbe1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/UnityWebSocket/Scripts/Editor.meta
Normal file
8
xiaofang/Assets/UnityWebSocket/Scripts/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb71bb4fb62590c4b975ef865b4df25f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
212
xiaofang/Assets/UnityWebSocket/Scripts/Editor/SettingsWindow.cs
Normal file
212
xiaofang/Assets/UnityWebSocket/Scripts/Editor/SettingsWindow.cs
Normal file
@ -0,0 +1,212 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Networking;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace UnityWebSocket.Editor
|
||||
{
|
||||
internal class SettingsWindow : EditorWindow
|
||||
{
|
||||
static SettingsWindow window = null;
|
||||
[MenuItem("Tools/UnityWebSocket", priority = 100)]
|
||||
internal static void Open()
|
||||
{
|
||||
if (window != null)
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
|
||||
window = GetWindow<SettingsWindow>(true, "UnityWebSocket");
|
||||
window.minSize = window.maxSize = new Vector2(600, 310);
|
||||
window.Show();
|
||||
window.BeginCheck();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawLogo();
|
||||
DrawVersion();
|
||||
DrawSeparator(80);
|
||||
DrawSeparator(186);
|
||||
DrawHelper();
|
||||
DrawFooter();
|
||||
}
|
||||
|
||||
Texture2D logoTex = null;
|
||||
private void DrawLogo()
|
||||
{
|
||||
if (logoTex == null)
|
||||
{
|
||||
logoTex = new Texture2D(66, 66);
|
||||
logoTex.LoadImage(Convert.FromBase64String(LOGO_BASE64.VALUE));
|
||||
for (int i = 0; i < 66; i++) for (int j = 0; j < 15; j++) logoTex.SetPixel(i, j, Color.clear);
|
||||
logoTex.Apply();
|
||||
}
|
||||
|
||||
var logoPos = new Rect(10, 10, 66, 66);
|
||||
GUI.DrawTexture(logoPos, logoTex);
|
||||
var title = "<color=#3A9AD8><b>UnityWebSocket</b></color>";
|
||||
var titlePos = new Rect(80, 20, 500, 50);
|
||||
GUI.Label(titlePos, title, TextStyle(24));
|
||||
}
|
||||
|
||||
private void DrawSeparator(int y)
|
||||
{
|
||||
EditorGUI.DrawRect(new Rect(10, y, 580, 1), Color.white * 0.5f);
|
||||
}
|
||||
|
||||
private GUIStyle TextStyle(int fontSize = 10, TextAnchor alignment = TextAnchor.UpperLeft, float alpha = 0.85f)
|
||||
{
|
||||
var style = new GUIStyle();
|
||||
style.fontSize = fontSize;
|
||||
style.normal.textColor = (EditorGUIUtility.isProSkin ? Color.white : Color.black) * alpha;
|
||||
style.alignment = alignment;
|
||||
style.richText = true;
|
||||
return style;
|
||||
}
|
||||
|
||||
private void DrawVersion()
|
||||
{
|
||||
GUI.Label(new Rect(440, 10, 150, 10), "Current Version: " + Settings.VERSION, TextStyle(alignment: TextAnchor.MiddleLeft));
|
||||
if (string.IsNullOrEmpty(latestVersion))
|
||||
{
|
||||
GUI.Label(new Rect(440, 30, 150, 10), "Checking for Updates...", TextStyle(alignment: TextAnchor.MiddleLeft));
|
||||
}
|
||||
else if (latestVersion == "unknown")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.Label(new Rect(440, 30, 150, 10), "Latest Version: " + latestVersion, TextStyle(alignment: TextAnchor.MiddleLeft));
|
||||
if (Settings.VERSION == latestVersion)
|
||||
{
|
||||
if (GUI.Button(new Rect(440, 50, 150, 18), "Check Update"))
|
||||
{
|
||||
latestVersion = "";
|
||||
changeLog = "";
|
||||
BeginCheck();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUI.Button(new Rect(440, 50, 150, 18), "Update to | " + latestVersion))
|
||||
{
|
||||
Application.OpenURL(Settings.GITHUB + "/releases");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHelper()
|
||||
{
|
||||
GUI.Label(new Rect(330, 200, 100, 18), "GitHub:", TextStyle(10, TextAnchor.MiddleRight));
|
||||
if (GUI.Button(new Rect(440, 200, 150, 18), "UnityWebSocket"))
|
||||
{
|
||||
Application.OpenURL(Settings.GITHUB);
|
||||
}
|
||||
|
||||
GUI.Label(new Rect(330, 225, 100, 18), "Report:", TextStyle(10, TextAnchor.MiddleRight));
|
||||
if (GUI.Button(new Rect(440, 225, 150, 18), "Report an Issue"))
|
||||
{
|
||||
Application.OpenURL(Settings.GITHUB + "/issues/new");
|
||||
}
|
||||
|
||||
GUI.Label(new Rect(330, 250, 100, 18), "Email:", TextStyle(10, TextAnchor.MiddleRight));
|
||||
if (GUI.Button(new Rect(440, 250, 150, 18), Settings.EMAIL))
|
||||
{
|
||||
var uri = new Uri(string.Format("mailto:{0}?subject={1}", Settings.EMAIL, "UnityWebSocket Feedback"));
|
||||
Application.OpenURL(uri.AbsoluteUri);
|
||||
}
|
||||
|
||||
GUI.Label(new Rect(330, 275, 100, 18), "QQ Group:", TextStyle(10, TextAnchor.MiddleRight));
|
||||
if (GUI.Button(new Rect(440, 275, 150, 18), Settings.QQ_GROUP))
|
||||
{
|
||||
Application.OpenURL(Settings.QQ_GROUP_LINK);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawFooter()
|
||||
{
|
||||
EditorGUI.DropShadowLabel(new Rect(10, 230, 400, 20), "Developed by " + Settings.AUHTOR);
|
||||
EditorGUI.DropShadowLabel(new Rect(10, 250, 400, 20), "All rights reserved");
|
||||
}
|
||||
|
||||
UnityWebRequest req;
|
||||
string changeLog = "";
|
||||
string latestVersion = "";
|
||||
void BeginCheck()
|
||||
{
|
||||
EditorApplication.update -= VersionCheckUpdate;
|
||||
EditorApplication.update += VersionCheckUpdate;
|
||||
|
||||
req = UnityWebRequest.Get(Settings.GITHUB + "/releases/latest");
|
||||
req.SendWebRequest();
|
||||
}
|
||||
|
||||
private void VersionCheckUpdate()
|
||||
{
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
if (req == null
|
||||
|| req.result == UnityWebRequest.Result.ConnectionError
|
||||
|| req.result == UnityWebRequest.Result.DataProcessingError
|
||||
|| req.result == UnityWebRequest.Result.ProtocolError)
|
||||
#elif UNITY_2018_1_OR_NEWER
|
||||
if (req == null || req.isNetworkError || req.isHttpError)
|
||||
#else
|
||||
if (req == null || req.isError)
|
||||
#endif
|
||||
{
|
||||
EditorApplication.update -= VersionCheckUpdate;
|
||||
latestVersion = "unknown";
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.isDone)
|
||||
{
|
||||
EditorApplication.update -= VersionCheckUpdate;
|
||||
latestVersion = req.url.Substring(req.url.LastIndexOf("/") + 1).TrimStart('v');
|
||||
|
||||
if (Settings.VERSION != latestVersion)
|
||||
{
|
||||
var text = req.downloadHandler.text;
|
||||
var st = text.IndexOf("content=\"" + latestVersion);
|
||||
st = st > 0 ? text.IndexOf("\n", st) : -1;
|
||||
var end = st > 0 ? text.IndexOf("\" />", st) : -1;
|
||||
if (st > 0 && end > st)
|
||||
{
|
||||
changeLog = text.Substring(st + 1, end - st - 1).Trim();
|
||||
changeLog = changeLog.Replace("\r", "");
|
||||
changeLog = changeLog.Replace("\n", "\n- ");
|
||||
changeLog = "\nCHANGE LOG: \n- " + changeLog + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class LOGO_BASE64
|
||||
{
|
||||
internal const string VALUE = "iVBORw0KGgoAAAANSUhEUgAAAEIAAABCCAMAAADUivDaAAAAq1BMVEUAAABKmtcvjtYzl" +
|
||||
"9szmNszl9syl9k0mNs0mNwzmNs0mNszl9szl9s0mNs0mNwzmNw0mNwyltk0mNw0mNwzl9s0mNsymNs0mNszmNwzmNwzm" +
|
||||
"NszmNs0mNwzl9w0mNwzmNw0mNs0mNs0mNwzl9wzmNs0mNwzmNs0mNwzl90zmNszmNszl9szmNsxmNszmNszmNw0mNwzm" +
|
||||
"Nw0mNs2neM4pe41mt43ouo2oOY5qfM+UHlaAAAAMnRSTlMAAwXN3sgI+/069MSCK6M/MA74h9qfFHB8STWMJ9OSdmNcI" +
|
||||
"8qya1IeF+/U0EIa57mqmFTYJe4AAAN3SURBVFjD7ZbpkppAFEa/bgVBREF2kEVGFNeZsM77P1kadURnJkr8k1Qlx1Khu" +
|
||||
"/pw7+2lwH/+YcgfMBBLG7VocwDamzH+wJBB8Qhjve2f0TdrGwjei6o4Ub/nM/APw5Z7vvSB/qrCrqbD6fBEVtigeMxks" +
|
||||
"fX9zWbj+z1jhqgSBplQ50eGo4614WXlRAzgrRhmtSfvxAn7pB0N5ObaKKZZuU5/d37IBcBgUQwqDuf7Z2gUmVAl4NGNr" +
|
||||
"/UeHxV5n39ulbaKLI86h6HilmM5M1aN126lpNhtl59yeTsp8nUMvpNC1J3bh5FtfVRk+bJrJunn5d4U4piJ/Vw9eXgsj" +
|
||||
"4ZpZaCjg9waZkIpnBWLJ44OwoNu60F2UnSaEkKv4XnAlCpm6B4F/aKMDiyGi2L8SEEAVdxNLuzmgV7nFwObEe2xQVuX+" +
|
||||
"RV1lWetga3w+cN1sXgvm4cJH8OEgZC1DPKhfF/BIymmQrMjq/x65FUeEkDup8GxoexZmznHCvANtXU/CAq13yimhQGtm" +
|
||||
"H4VCPnBBL1fTKo3CqEcvq7Lb/OwHxWTYlyw+JmjKoVvDLVOQB4pVsM8K8smgvLCxZDlIijwyOEc+nr/msMwK0+GQWGBd" +
|
||||
"tmhjv8icTds1s2ammaFh04QLLe69NK7guP6mTDMaw3o6nAX/Z7EXUskPSvWEWg4srVlp5NTDXv9Lce9HGN5eeG4nj5Yz" +
|
||||
"ACteU2wQLo4MBtJfd1nw5nG1/s9zwUQ6pykL1TQjqdeuvQW0naz2XKLYL4Cwzr4vj+OQdD96CSp7Lrynp4aeFF0xdm5q" +
|
||||
"6OFtFfPv7URxpWJNjd/N+3+I9+1klMav12Qtgbt9R2JaIopjkzaPtOFq4KxUpqfUMSFnQrySWjLoQzRZS4HMH84ME1ej" +
|
||||
"S1YJpQZ3B+sR1uCQJSBdGdCk1eAEgORR88KK05W8dh2MA+A/SKCYu3mCJ0Ek7HBx4HHeuwYy5G3x8hSMTJcOMFbinCsn" +
|
||||
"hO1V1aszGULvA0g4UFsb4VA0hAFcyo6cgLsAoT7uUtGAH5wQKQle0wuLyxLTaNyJEYwxw4wSljLK1TP8CAaOyhBMMEsj" +
|
||||
"OBoXgo7VGElFkSWL+vef1RF2YNXeRWYzQBTpkhC8KaZHhuIogArkQLKClBZjU26B2IZgGz+cpZkHl8g3fYUaW/YP2kb2" +
|
||||
"M/V97JY/vZN859n+QmO7XtC9Bf2jAAAAABJRU5ErkJggg==";
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c42d421cc4c34f3eae1fbd67f0dced0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "UnityWebSocket.Editor",
|
||||
"references": [
|
||||
"UnityWebSocket.Runtime"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee833745c57bd4369ab8f0ff380a96fa
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/UnityWebSocket/Scripts/Runtime.meta
Normal file
8
xiaofang/Assets/UnityWebSocket/Scripts/Runtime.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53e0ed9fdc3af42eba12a5b1b9a5f873
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/UnityWebSocket/Scripts/Runtime/Core.meta
Normal file
8
xiaofang/Assets/UnityWebSocket/Scripts/Runtime/Core.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b3a2a8f55d4a47f599b1fa3ed612389
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the event data for the <see cref="IWebSocket.OnClose"/> event.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// That event occurs when the WebSocket connection has been closed.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If you would like to get the reason for the close, you should access
|
||||
/// the <see cref="Code"/> or <see cref="Reason"/> property.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class CloseEventArgs : EventArgs
|
||||
{
|
||||
#region Internal Constructors
|
||||
|
||||
internal CloseEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
internal CloseEventArgs(ushort code)
|
||||
: this(code, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal CloseEventArgs(CloseStatusCode code)
|
||||
: this((ushort)code, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal CloseEventArgs(CloseStatusCode code, string reason)
|
||||
: this((ushort)code, reason)
|
||||
{
|
||||
}
|
||||
|
||||
internal CloseEventArgs(ushort code, string reason)
|
||||
{
|
||||
Code = code;
|
||||
Reason = reason;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status code for the close.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="ushort"/> that represents the status code for the close if any.
|
||||
/// </value>
|
||||
public ushort Code { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason for the close.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that represents the reason for the close if any.
|
||||
/// </value>
|
||||
public string Reason { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the connection has been closed cleanly.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the connection has been closed cleanly; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool WasClean { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enum value same as Code
|
||||
/// </summary>
|
||||
public CloseStatusCode StatusCode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Enum.IsDefined(typeof(CloseStatusCode), Code))
|
||||
return (CloseStatusCode)Code;
|
||||
return CloseStatusCode.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29b987d07ba15434cb1744135a7a5416
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,91 @@
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates the status code for the WebSocket connection close.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The values of this enumeration are defined in
|
||||
/// <see href="http://tools.ietf.org/html/rfc6455#section-7.4">
|
||||
/// Section 7.4</see> of RFC 6455.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// "Reserved value" cannot be sent as a status code in
|
||||
/// closing handshake by an endpoint.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public enum CloseStatusCode : ushort
|
||||
{
|
||||
Unknown = 65534,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1000. Indicates normal close.
|
||||
/// </summary>
|
||||
Normal = 1000,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1001. Indicates that an endpoint is
|
||||
/// going away.
|
||||
/// </summary>
|
||||
Away = 1001,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1002. Indicates that an endpoint is
|
||||
/// terminating the connection due to a protocol error.
|
||||
/// </summary>
|
||||
ProtocolError = 1002,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1003. Indicates that an endpoint is
|
||||
/// terminating the connection because it has received a type of
|
||||
/// data that it cannot accept.
|
||||
/// </summary>
|
||||
UnsupportedData = 1003,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1004. Still undefined. A Reserved value.
|
||||
/// </summary>
|
||||
Undefined = 1004,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1005. Indicates that no status code was
|
||||
/// actually present. A Reserved value.
|
||||
/// </summary>
|
||||
NoStatus = 1005,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1006. Indicates that the connection was
|
||||
/// closed abnormally. A Reserved value.
|
||||
/// </summary>
|
||||
Abnormal = 1006,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1007. Indicates that an endpoint is
|
||||
/// terminating the connection because it has received a message that
|
||||
/// contains data that is not consistent with the type of the message.
|
||||
/// </summary>
|
||||
InvalidData = 1007,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1008. Indicates that an endpoint is
|
||||
/// terminating the connection because it has received a message that
|
||||
/// violates its policy.
|
||||
/// </summary>
|
||||
PolicyViolation = 1008,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1009. Indicates that an endpoint is
|
||||
/// terminating the connection because it has received a message that
|
||||
/// is too big to process.
|
||||
/// </summary>
|
||||
TooBig = 1009,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1010. Indicates that a client is
|
||||
/// terminating the connection because it has expected the server to
|
||||
/// negotiate one or more extension, but the server did not return
|
||||
/// them in the handshake response.
|
||||
/// </summary>
|
||||
MandatoryExtension = 1010,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1011. Indicates that a server is
|
||||
/// terminating the connection because it has encountered an unexpected
|
||||
/// condition that prevented it from fulfilling the request.
|
||||
/// </summary>
|
||||
ServerError = 1011,
|
||||
/// <summary>
|
||||
/// Equivalent to close status 1015. Indicates that the connection was
|
||||
/// closed due to a failure to perform a TLS handshake. A Reserved value.
|
||||
/// </summary>
|
||||
TlsHandshakeFailure = 1015,
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e34ee317292e4225a10427cc35f85ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the event data for the <see cref="IWebSocket.OnError"/> event.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// That event occurs when the <see cref="IWebSocket"/> gets an error.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If you would like to get the error message, you should access
|
||||
/// the <see cref="Message"/> property.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// And if the error is due to an exception, you can get it by accessing
|
||||
/// the <see cref="Exception"/> property.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class ErrorEventArgs : EventArgs
|
||||
{
|
||||
#region Internal Constructors
|
||||
|
||||
internal ErrorEventArgs(string message)
|
||||
: this(message, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal ErrorEventArgs(string message, Exception exception)
|
||||
{
|
||||
this.Message = message;
|
||||
this.Exception = exception;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exception that caused the error.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// An <see cref="System.Exception"/> instance that represents the cause of
|
||||
/// the error if it is due to an exception; otherwise, <see langword="null"/>.
|
||||
/// </value>
|
||||
public Exception Exception { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error message.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that represents the error message.
|
||||
/// </value>
|
||||
public string Message { get; private set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 884e7db60b6444154b7200e0e436f2de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>IWebSocket indicate a network connection.</para>
|
||||
/// <para>It can be connecting, connected, closing or closed state. </para>
|
||||
/// <para>You can send and receive messages by using it.</para>
|
||||
/// <para>Register callbacks for handling messages.</para>
|
||||
/// <para> ----------------------------------------------------------- </para>
|
||||
/// <para>IWebSocket 表示一个网络连接,</para>
|
||||
/// <para>它可以是 connecting connected closing closed 状态,</para>
|
||||
/// <para>可以发送和接收消息,</para>
|
||||
/// <para>通过注册消息回调,来处理接收到的消息。</para>
|
||||
/// </summary>
|
||||
public interface IWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Establishes a connection asynchronously.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This method does not wait for the connect process to be complete.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This method does nothing if the connection has already been
|
||||
/// established.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// <para>
|
||||
/// This instance is not a client.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// -or-
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The close process is in progress.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// -or-
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// A series of reconnecting has failed.
|
||||
/// </para>
|
||||
/// </exception>
|
||||
void ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Closes the connection asynchronously.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This method does not wait for the close to be complete.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This method does nothing if the current state of the connection is
|
||||
/// Closing or Closed.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
void CloseAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Sends the specified data asynchronously using the WebSocket connection.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method does not wait for the send to be complete.
|
||||
/// </remarks>
|
||||
/// <param name="data">
|
||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||
/// </param>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// The current state of the connection is not Open.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="data"/> is <see langword="null"/>.
|
||||
/// </exception>
|
||||
void SendAsync(byte[] data);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the specified data using the WebSocket connection.
|
||||
/// </summary>
|
||||
/// <param name="text">
|
||||
/// A <see cref="string"/> that represents the text data to send.
|
||||
/// </param>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// The current state of the connection is not Open.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="text"/> is <see langword="null"/>.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// <paramref name="text"/> could not be UTF-8 encoded.
|
||||
/// </exception>
|
||||
void SendAsync(string text);
|
||||
|
||||
/// <summary>
|
||||
/// get the address which to connect.
|
||||
/// </summary>
|
||||
string Address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// get sub protocols .
|
||||
/// </summary>
|
||||
string[] SubProtocols { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current state of the connection.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <para>
|
||||
/// One of the <see cref="WebSocketState"/> enum values.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// It indicates the current state of the connection.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The default value is <see cref="WebSocketState.Closed"/>.
|
||||
/// </para>
|
||||
/// </value>
|
||||
WebSocketState ReadyState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the WebSocket connection has been established.
|
||||
/// </summary>
|
||||
event EventHandler<OpenEventArgs> OnOpen;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the WebSocket connection has been closed.
|
||||
/// </summary>
|
||||
event EventHandler<CloseEventArgs> OnClose;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="IWebSocket"/> gets an error.
|
||||
/// </summary>
|
||||
event EventHandler<ErrorEventArgs> OnError;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="IWebSocket"/> receives a message.
|
||||
/// </summary>
|
||||
event EventHandler<MessageEventArgs> OnMessage;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37ee2146eb8c34ffab8b081a632b05cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
public class MessageEventArgs : EventArgs
|
||||
{
|
||||
private byte[] _rawData;
|
||||
private string _data;
|
||||
|
||||
internal MessageEventArgs(Opcode opcode, byte[] rawData)
|
||||
{
|
||||
Opcode = opcode;
|
||||
_rawData = rawData;
|
||||
}
|
||||
|
||||
internal MessageEventArgs(Opcode opcode, string data)
|
||||
{
|
||||
Opcode = opcode;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the opcode for the message.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <see cref="Opcode.Text"/>, <see cref="Opcode.Binary"/>.
|
||||
/// </value>
|
||||
internal Opcode Opcode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message data as a <see cref="string"/>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that represents the message data if its type is
|
||||
/// text and if decoding it to a string has successfully done;
|
||||
/// otherwise, <see langword="null"/>.
|
||||
/// </value>
|
||||
public string Data
|
||||
{
|
||||
get
|
||||
{
|
||||
SetData();
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message data as an array of <see cref="byte"/>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// An array of <see cref="byte"/> that represents the message data.
|
||||
/// </value>
|
||||
public byte[] RawData
|
||||
{
|
||||
get
|
||||
{
|
||||
SetRawData();
|
||||
return _rawData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the message type is binary.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the message type is binary; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsBinary
|
||||
{
|
||||
get
|
||||
{
|
||||
return Opcode == Opcode.Binary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the message type is text.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the message type is text; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsText
|
||||
{
|
||||
get
|
||||
{
|
||||
return Opcode == Opcode.Text;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
if (_data != null) return;
|
||||
|
||||
if (RawData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_data = Encoding.UTF8.GetString(RawData);
|
||||
}
|
||||
|
||||
private void SetRawData()
|
||||
{
|
||||
if (_rawData != null) return;
|
||||
|
||||
if (_data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_rawData = Encoding.UTF8.GetBytes(_data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b44eda173b4924081bab76ae9d1b0a9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,26 @@
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates the WebSocket frame type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The values of this enumeration are defined in
|
||||
/// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">
|
||||
/// Section 5.2</see> of RFC 6455.
|
||||
/// </remarks>
|
||||
public enum Opcode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 1. Indicates text frame.
|
||||
/// </summary>
|
||||
Text = 0x1,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 2. Indicates binary frame.
|
||||
/// </summary>
|
||||
Binary = 0x2,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 8. Indicates connection close frame.
|
||||
/// </summary>
|
||||
Close = 0x8,
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eeac0ef90273544ebbae046672caf362
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
public class OpenEventArgs : EventArgs
|
||||
{
|
||||
internal OpenEventArgs()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fb6fd704bd4e4b8ba63cd0b28712955
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,12 @@
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
public static class Settings
|
||||
{
|
||||
public const string GITHUB = "https://github.com/psygames/UnityWebSocket";
|
||||
public const string QQ_GROUP = "1126457634";
|
||||
public const string QQ_GROUP_LINK = "https://qm.qq.com/cgi-bin/qm/qr?k=KcexYJ9aYwogFXbj2aN0XHH5b2G7ICmd";
|
||||
public const string EMAIL = "799329256@qq.com";
|
||||
public const string AUHTOR = "psygames";
|
||||
public const string VERSION = "2.8.5";
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e268303c7a605e343b1b132e5559f01f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,36 @@
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference html5 WebSocket ReadyState Properties
|
||||
/// Indicates the state of a WebSocket connection.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The values of this enumeration are defined in
|
||||
/// <see href="http://www.w3.org/TR/websockets/#dom-websocket-readystate">
|
||||
/// The WebSocket API</see>.
|
||||
/// </remarks>
|
||||
public enum WebSocketState : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 0. Indicates that the connection has not
|
||||
/// yet been established.
|
||||
/// </summary>
|
||||
Connecting = 0,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 1. Indicates that the connection has
|
||||
/// been established, and the communication is possible.
|
||||
/// </summary>
|
||||
Open = 1,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 2. Indicates that the connection is
|
||||
/// going through the closing handshake, or the close method has
|
||||
/// been invoked.
|
||||
/// </summary>
|
||||
Closing = 2,
|
||||
/// <summary>
|
||||
/// Equivalent to numeric value 3. Indicates that the connection has
|
||||
/// been closed or could not be established.
|
||||
/// </summary>
|
||||
Closed = 3
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f6567ad13cb147a59f8af784f1c5f60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 396c66b333d624d539153070900bb73b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c110a898ae8b0b41bcf4da49c2b0425
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,329 @@
|
||||
#if !NET_LEGACY && (UNITY_EDITOR || !UNITY_WEBGL)
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.WebSockets;
|
||||
using System.IO;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
public class WebSocket : IWebSocket
|
||||
{
|
||||
public string Address { get; private set; }
|
||||
public string[] SubProtocols { get; private set; }
|
||||
|
||||
public WebSocketState ReadyState
|
||||
{
|
||||
get
|
||||
{
|
||||
if (socket == null)
|
||||
return WebSocketState.Closed;
|
||||
switch (socket.State)
|
||||
{
|
||||
case System.Net.WebSockets.WebSocketState.Closed:
|
||||
case System.Net.WebSockets.WebSocketState.None:
|
||||
return WebSocketState.Closed;
|
||||
case System.Net.WebSockets.WebSocketState.CloseReceived:
|
||||
case System.Net.WebSockets.WebSocketState.CloseSent:
|
||||
return WebSocketState.Closing;
|
||||
case System.Net.WebSockets.WebSocketState.Connecting:
|
||||
return WebSocketState.Connecting;
|
||||
case System.Net.WebSockets.WebSocketState.Open:
|
||||
return WebSocketState.Open;
|
||||
}
|
||||
return WebSocketState.Closed;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<OpenEventArgs> OnOpen;
|
||||
public event EventHandler<CloseEventArgs> OnClose;
|
||||
public event EventHandler<ErrorEventArgs> OnError;
|
||||
public event EventHandler<MessageEventArgs> OnMessage;
|
||||
|
||||
private ClientWebSocket socket;
|
||||
private bool isOpening => socket != null && socket.State == System.Net.WebSockets.WebSocketState.Open;
|
||||
private ConcurrentQueue<SendBuffer> sendQueue = new ConcurrentQueue<SendBuffer>();
|
||||
private ConcurrentQueue<EventArgs> eventQueue = new ConcurrentQueue<EventArgs>();
|
||||
private bool closeProcessing;
|
||||
private CancellationTokenSource cts = null;
|
||||
|
||||
#region APIs
|
||||
public WebSocket(string address)
|
||||
{
|
||||
this.Address = address;
|
||||
}
|
||||
|
||||
public WebSocket(string address, string subProtocol)
|
||||
{
|
||||
this.Address = address;
|
||||
this.SubProtocols = new string[] { subProtocol };
|
||||
}
|
||||
|
||||
public WebSocket(string address, string[] subProtocols)
|
||||
{
|
||||
this.Address = address;
|
||||
this.SubProtocols = subProtocols;
|
||||
}
|
||||
|
||||
public void ConnectAsync()
|
||||
{
|
||||
if (socket != null)
|
||||
{
|
||||
HandleError(new Exception("Socket is busy."));
|
||||
return;
|
||||
}
|
||||
|
||||
WebSocketManager.Instance.Add(this);
|
||||
|
||||
socket = new ClientWebSocket();
|
||||
cts = new CancellationTokenSource();
|
||||
|
||||
// support sub protocols
|
||||
if (this.SubProtocols != null)
|
||||
{
|
||||
foreach (var protocol in this.SubProtocols)
|
||||
{
|
||||
if (string.IsNullOrEmpty(protocol)) continue;
|
||||
Log($"Add Sub Protocol {protocol}");
|
||||
socket.Options.AddSubProtocol(protocol);
|
||||
}
|
||||
}
|
||||
|
||||
Task.Run(ConnectTask);
|
||||
}
|
||||
|
||||
public void CloseAsync()
|
||||
{
|
||||
if (!isOpening) return;
|
||||
closeProcessing = true;
|
||||
}
|
||||
|
||||
public void SendAsync(byte[] data)
|
||||
{
|
||||
if (!isOpening) return;
|
||||
var buffer = new SendBuffer(data, WebSocketMessageType.Binary);
|
||||
sendQueue.Enqueue(buffer);
|
||||
}
|
||||
|
||||
public void SendAsync(string text)
|
||||
{
|
||||
if (!isOpening) return;
|
||||
var data = Encoding.UTF8.GetBytes(text);
|
||||
var buffer = new SendBuffer(data, WebSocketMessageType.Text);
|
||||
sendQueue.Enqueue(buffer);
|
||||
}
|
||||
#endregion
|
||||
|
||||
class SendBuffer
|
||||
{
|
||||
public byte[] data;
|
||||
public WebSocketMessageType type;
|
||||
public SendBuffer(byte[] data, WebSocketMessageType type)
|
||||
{
|
||||
this.data = data;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanSendQueue()
|
||||
{
|
||||
while (sendQueue.TryDequeue(out var _)) ;
|
||||
}
|
||||
|
||||
private void CleanEventQueue()
|
||||
{
|
||||
while (eventQueue.TryDequeue(out var _)) ;
|
||||
}
|
||||
|
||||
private async Task ConnectTask()
|
||||
{
|
||||
Log("Connect Task Begin ...");
|
||||
|
||||
try
|
||||
{
|
||||
var uri = new Uri(Address);
|
||||
await socket.ConnectAsync(uri, cts.Token);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleError(e);
|
||||
HandleClose((ushort)CloseStatusCode.Abnormal, e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleOpen();
|
||||
|
||||
Log("Connect Task Success !");
|
||||
|
||||
StartReceiveTask();
|
||||
StartSendTask();
|
||||
}
|
||||
|
||||
private async void StartSendTask()
|
||||
{
|
||||
Log("Send Task Begin ...");
|
||||
|
||||
try
|
||||
{
|
||||
while (!closeProcessing && socket != null && cts != null && !cts.IsCancellationRequested)
|
||||
{
|
||||
while (!closeProcessing && sendQueue.Count > 0 && sendQueue.TryDequeue(out var buffer))
|
||||
{
|
||||
Log($"Send, type: {buffer.type}, size: {buffer.data.Length}, queue left: {sendQueue.Count}");
|
||||
await socket.SendAsync(new ArraySegment<byte>(buffer.data), buffer.type, true, cts.Token);
|
||||
}
|
||||
Thread.Sleep(3);
|
||||
}
|
||||
if (closeProcessing && socket != null && cts != null && !cts.IsCancellationRequested)
|
||||
{
|
||||
CleanSendQueue();
|
||||
Log($"Close Send Begin ...");
|
||||
await socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Normal Closure", cts.Token);
|
||||
Log($"Close Send Success !");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleError(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeProcessing = false;
|
||||
}
|
||||
|
||||
Log("Send Task End !");
|
||||
}
|
||||
|
||||
private async void StartReceiveTask()
|
||||
{
|
||||
Log("Receive Task Begin ...");
|
||||
|
||||
string closeReason = "";
|
||||
ushort closeCode = 0;
|
||||
bool isClosed = false;
|
||||
var segment = new ArraySegment<byte>(new byte[8192]);
|
||||
var ms = new MemoryStream();
|
||||
|
||||
try
|
||||
{
|
||||
while (!isClosed && !cts.IsCancellationRequested)
|
||||
{
|
||||
var result = await socket.ReceiveAsync(segment, cts.Token);
|
||||
ms.Write(segment.Array, 0, result.Count);
|
||||
if (!result.EndOfMessage) continue;
|
||||
var data = ms.ToArray();
|
||||
ms.SetLength(0);
|
||||
switch (result.MessageType)
|
||||
{
|
||||
case WebSocketMessageType.Binary:
|
||||
HandleMessage(Opcode.Binary, data);
|
||||
break;
|
||||
case WebSocketMessageType.Text:
|
||||
HandleMessage(Opcode.Text, data);
|
||||
break;
|
||||
case WebSocketMessageType.Close:
|
||||
isClosed = true;
|
||||
closeCode = (ushort)result.CloseStatus;
|
||||
closeReason = result.CloseStatusDescription;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandleError(e);
|
||||
closeCode = (ushort)CloseStatusCode.Abnormal;
|
||||
closeReason = e.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ms.Close();
|
||||
}
|
||||
|
||||
HandleClose(closeCode, closeReason);
|
||||
|
||||
Log("Receive Task End !");
|
||||
}
|
||||
|
||||
private void SocketDispose()
|
||||
{
|
||||
Log("Dispose");
|
||||
WebSocketManager.Instance.Remove(this);
|
||||
CleanSendQueue();
|
||||
CleanEventQueue();
|
||||
socket.Dispose();
|
||||
socket = null;
|
||||
cts.Dispose();
|
||||
cts = null;
|
||||
}
|
||||
|
||||
private void HandleOpen()
|
||||
{
|
||||
Log("OnOpen");
|
||||
eventQueue.Enqueue(new OpenEventArgs());
|
||||
}
|
||||
|
||||
private void HandleMessage(Opcode opcode, byte[] rawData)
|
||||
{
|
||||
Log($"OnMessage, type: {opcode}, size: {rawData.Length}");
|
||||
eventQueue.Enqueue(new MessageEventArgs(opcode, rawData));
|
||||
}
|
||||
|
||||
private void HandleClose(ushort code, string reason)
|
||||
{
|
||||
Log($"OnClose, code: {code}, reason: {reason}");
|
||||
eventQueue.Enqueue(new CloseEventArgs(code, reason));
|
||||
}
|
||||
|
||||
private void HandleError(Exception exception)
|
||||
{
|
||||
Log("OnError, error: " + exception.Message);
|
||||
eventQueue.Enqueue(new ErrorEventArgs(exception.Message));
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
while (eventQueue.Count > 0 && eventQueue.TryDequeue(out var e))
|
||||
{
|
||||
if (e is CloseEventArgs)
|
||||
{
|
||||
OnClose?.Invoke(this, e as CloseEventArgs);
|
||||
SocketDispose();
|
||||
break;
|
||||
}
|
||||
else if (e is OpenEventArgs)
|
||||
{
|
||||
OnOpen?.Invoke(this, e as OpenEventArgs);
|
||||
}
|
||||
else if (e is MessageEventArgs)
|
||||
{
|
||||
OnMessage?.Invoke(this, e as MessageEventArgs);
|
||||
}
|
||||
else if (e is ErrorEventArgs)
|
||||
{
|
||||
OnError?.Invoke(this, e as ErrorEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Abort()
|
||||
{
|
||||
Log("Abort");
|
||||
if (cts != null)
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_WEB_SOCKET_LOG")]
|
||||
static void Log(string msg)
|
||||
{
|
||||
var time = DateTime.Now.ToString("HH:mm:ss.fff");
|
||||
var thread = Thread.CurrentThread.ManagedThreadId;
|
||||
UnityEngine.Debug.Log($"[{time}][UnityWebSocket][T-{thread:D3}] {msg}");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d10f88a23641b4beb8df74460fb7f705
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,74 @@
|
||||
#if !NET_LEGACY && (UNITY_EDITOR || !UNITY_WEBGL)
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[DefaultExecutionOrder(-10000)]
|
||||
internal class WebSocketManager : MonoBehaviour
|
||||
{
|
||||
private const string rootName = "[UnityWebSocket]";
|
||||
private static WebSocketManager _instance;
|
||||
public static WebSocketManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_instance) CreateInstance();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public static void CreateInstance()
|
||||
{
|
||||
GameObject go = GameObject.Find("/" + rootName);
|
||||
if (!go) go = new GameObject(rootName);
|
||||
_instance = go.GetComponent<WebSocketManager>();
|
||||
if (!_instance) _instance = go.AddComponent<WebSocketManager>();
|
||||
}
|
||||
|
||||
private readonly List<WebSocket> sockets = new List<WebSocket>();
|
||||
|
||||
public void Add(WebSocket socket)
|
||||
{
|
||||
if (!sockets.Contains(socket))
|
||||
sockets.Add(socket);
|
||||
}
|
||||
|
||||
public void Remove(WebSocket socket)
|
||||
{
|
||||
if (sockets.Contains(socket))
|
||||
sockets.Remove(socket);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (sockets.Count <= 0) return;
|
||||
for (int i = sockets.Count - 1; i >= 0; i--)
|
||||
{
|
||||
sockets[i].Update();
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDisable()
|
||||
{
|
||||
SocketAbort();
|
||||
}
|
||||
|
||||
private void SocketAbort()
|
||||
{
|
||||
for (int i = sockets.Count - 1; i >= 0; i--)
|
||||
{
|
||||
sockets[i].Abort();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99157fb5def394c83a9e5342036c92b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fb37927ec1ce4def9c5e7cff883f9f5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,147 @@
|
||||
#if !UNITY_EDITOR && UNITY_WEBGL
|
||||
using System;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
public class WebSocket : IWebSocket
|
||||
{
|
||||
public string Address { get; private set; }
|
||||
public string[] SubProtocols { get; private set; }
|
||||
public WebSocketState ReadyState { get { return (WebSocketState)WebSocketManager.WebSocketGetState(instanceId); } }
|
||||
|
||||
public event EventHandler<OpenEventArgs> OnOpen;
|
||||
public event EventHandler<CloseEventArgs> OnClose;
|
||||
public event EventHandler<ErrorEventArgs> OnError;
|
||||
public event EventHandler<MessageEventArgs> OnMessage;
|
||||
|
||||
internal int instanceId = 0;
|
||||
|
||||
public WebSocket(string address)
|
||||
{
|
||||
this.Address = address;
|
||||
AllocateInstance();
|
||||
}
|
||||
|
||||
public WebSocket(string address, string subProtocol)
|
||||
{
|
||||
this.Address = address;
|
||||
this.SubProtocols = new string[] { subProtocol };
|
||||
AllocateInstance();
|
||||
}
|
||||
|
||||
public WebSocket(string address, string[] subProtocols)
|
||||
{
|
||||
this.Address = address;
|
||||
this.SubProtocols = subProtocols;
|
||||
AllocateInstance();
|
||||
}
|
||||
|
||||
internal void AllocateInstance()
|
||||
{
|
||||
instanceId = WebSocketManager.AllocateInstance(this.Address);
|
||||
Log($"Allocate socket with instanceId: {instanceId}");
|
||||
if (this.SubProtocols == null) return;
|
||||
foreach (var protocol in this.SubProtocols)
|
||||
{
|
||||
if (string.IsNullOrEmpty(protocol)) continue;
|
||||
Log($"Add Sub Protocol {protocol}, with instanceId: {instanceId}");
|
||||
int code = WebSocketManager.WebSocketAddSubProtocol(instanceId, protocol);
|
||||
if (code < 0)
|
||||
{
|
||||
HandleOnError(GetErrorMessageFromCode(code));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~WebSocket()
|
||||
{
|
||||
Log($"Free socket with instanceId: {instanceId}");
|
||||
WebSocketManager.WebSocketFree(instanceId);
|
||||
}
|
||||
|
||||
public void ConnectAsync()
|
||||
{
|
||||
Log($"Connect with instanceId: {instanceId}");
|
||||
WebSocketManager.Add(this);
|
||||
int code = WebSocketManager.WebSocketConnect(instanceId);
|
||||
if (code < 0) HandleOnError(GetErrorMessageFromCode(code));
|
||||
}
|
||||
|
||||
public void CloseAsync()
|
||||
{
|
||||
Log($"Close with instanceId: {instanceId}");
|
||||
int code = WebSocketManager.WebSocketClose(instanceId, (int)CloseStatusCode.Normal, "Normal Closure");
|
||||
if (code < 0) HandleOnError(GetErrorMessageFromCode(code));
|
||||
}
|
||||
|
||||
public void SendAsync(string text)
|
||||
{
|
||||
Log($"Send, type: {Opcode.Text}, size: {text.Length}");
|
||||
int code = WebSocketManager.WebSocketSendStr(instanceId, text);
|
||||
if (code < 0) HandleOnError(GetErrorMessageFromCode(code));
|
||||
}
|
||||
|
||||
public void SendAsync(byte[] data)
|
||||
{
|
||||
Log($"Send, type: {Opcode.Binary}, size: {data.Length}");
|
||||
int code = WebSocketManager.WebSocketSend(instanceId, data, data.Length);
|
||||
if (code < 0) HandleOnError(GetErrorMessageFromCode(code));
|
||||
}
|
||||
|
||||
internal void HandleOnOpen()
|
||||
{
|
||||
Log("OnOpen");
|
||||
OnOpen?.Invoke(this, new OpenEventArgs());
|
||||
}
|
||||
|
||||
internal void HandleOnMessage(byte[] rawData)
|
||||
{
|
||||
Log($"OnMessage, type: {Opcode.Binary}, size: {rawData.Length}");
|
||||
OnMessage?.Invoke(this, new MessageEventArgs(Opcode.Binary, rawData));
|
||||
}
|
||||
|
||||
internal void HandleOnMessageStr(string data)
|
||||
{
|
||||
Log($"OnMessage, type: {Opcode.Text}, size: {data.Length}");
|
||||
OnMessage?.Invoke(this, new MessageEventArgs(Opcode.Text, data));
|
||||
}
|
||||
|
||||
internal void HandleOnClose(ushort code, string reason)
|
||||
{
|
||||
Log($"OnClose, code: {code}, reason: {reason}");
|
||||
OnClose?.Invoke(this, new CloseEventArgs(code, reason));
|
||||
WebSocketManager.Remove(instanceId);
|
||||
}
|
||||
|
||||
internal void HandleOnError(string msg)
|
||||
{
|
||||
Log("OnError, error: " + msg);
|
||||
OnError?.Invoke(this, new ErrorEventArgs(msg));
|
||||
}
|
||||
|
||||
internal static string GetErrorMessageFromCode(int errorCode)
|
||||
{
|
||||
switch (errorCode)
|
||||
{
|
||||
case -1: return "WebSocket instance not found.";
|
||||
case -2: return "WebSocket is already connected or in connecting state.";
|
||||
case -3: return "WebSocket is not connected.";
|
||||
case -4: return "WebSocket is already closing.";
|
||||
case -5: return "WebSocket is already closed.";
|
||||
case -6: return "WebSocket is not in open state.";
|
||||
case -7: return "Cannot close WebSocket, An invalid code was specified or reason is too long.";
|
||||
case -8: return "Not support buffer slice. ";
|
||||
default: return $"Unknown error code {errorCode}.";
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_WEB_SOCKET_LOG")]
|
||||
static void Log(string msg)
|
||||
{
|
||||
var time = DateTime.Now.ToString("HH:mm:ss.fff");
|
||||
UnityEngine.Debug.Log($"[{time}][UnityWebSocket] {msg}");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74a5b3c22251243d2a2f33e74741559d
|
||||
timeCreated: 1466578513
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,153 @@
|
||||
#if !UNITY_EDITOR && UNITY_WEBGL
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using AOT;
|
||||
|
||||
namespace UnityWebSocket
|
||||
{
|
||||
/// <summary>
|
||||
/// Class providing static access methods to work with JSLIB WebSocket
|
||||
/// </summary>
|
||||
internal static class WebSocketManager
|
||||
{
|
||||
/* Map of websocket instances */
|
||||
private static Dictionary<int, WebSocket> sockets = new Dictionary<int, WebSocket>();
|
||||
|
||||
/* Delegates */
|
||||
public delegate void OnOpenCallback(int instanceId);
|
||||
public delegate void OnMessageCallback(int instanceId, IntPtr msgPtr, int msgSize);
|
||||
public delegate void OnMessageStrCallback(int instanceId, IntPtr msgStrPtr);
|
||||
public delegate void OnErrorCallback(int instanceId, IntPtr errorPtr);
|
||||
public delegate void OnCloseCallback(int instanceId, int closeCode, IntPtr reasonPtr);
|
||||
|
||||
/* WebSocket JSLIB functions */
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketConnect(int instanceId);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketClose(int instanceId, int code, string reason);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketSend(int instanceId, byte[] dataPtr, int dataLength);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketSendStr(int instanceId, string data);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketGetState(int instanceId);
|
||||
|
||||
/* WebSocket JSLIB callback setters and other functions */
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketAllocate(string url);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebSocketAddSubProtocol(int instanceId, string protocol);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebSocketFree(int instanceId);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebSocketSetOnOpen(OnOpenCallback callback);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebSocketSetOnMessage(OnMessageCallback callback);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebSocketSetOnMessageStr(OnMessageStrCallback callback);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebSocketSetOnError(OnErrorCallback callback);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebSocketSetOnClose(OnCloseCallback callback);
|
||||
|
||||
/* If callbacks was initialized and set */
|
||||
private static bool isInitialized = false;
|
||||
|
||||
/* Initialize WebSocket callbacks to JSLIB */
|
||||
private static void Initialize()
|
||||
{
|
||||
WebSocketSetOnOpen(DelegateOnOpenEvent);
|
||||
WebSocketSetOnMessage(DelegateOnMessageEvent);
|
||||
WebSocketSetOnMessageStr(DelegateOnMessageStrEvent);
|
||||
WebSocketSetOnError(DelegateOnErrorEvent);
|
||||
WebSocketSetOnClose(DelegateOnCloseEvent);
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(OnOpenCallback))]
|
||||
public static void DelegateOnOpenEvent(int instanceId)
|
||||
{
|
||||
if (sockets.TryGetValue(instanceId, out var socket))
|
||||
{
|
||||
socket.HandleOnOpen();
|
||||
}
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(OnMessageCallback))]
|
||||
public static void DelegateOnMessageEvent(int instanceId, IntPtr msgPtr, int msgSize)
|
||||
{
|
||||
if (sockets.TryGetValue(instanceId, out var socket))
|
||||
{
|
||||
var bytes = new byte[msgSize];
|
||||
Marshal.Copy(msgPtr, bytes, 0, msgSize);
|
||||
socket.HandleOnMessage(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(OnMessageStrCallback))]
|
||||
public static void DelegateOnMessageStrEvent(int instanceId, IntPtr msgStrPtr)
|
||||
{
|
||||
if (sockets.TryGetValue(instanceId, out var socket))
|
||||
{
|
||||
string msgStr = Marshal.PtrToStringAuto(msgStrPtr);
|
||||
socket.HandleOnMessageStr(msgStr);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(OnErrorCallback))]
|
||||
public static void DelegateOnErrorEvent(int instanceId, IntPtr errorPtr)
|
||||
{
|
||||
if (sockets.TryGetValue(instanceId, out var socket))
|
||||
{
|
||||
string errorMsg = Marshal.PtrToStringAuto(errorPtr);
|
||||
socket.HandleOnError(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(OnCloseCallback))]
|
||||
public static void DelegateOnCloseEvent(int instanceId, int closeCode, IntPtr reasonPtr)
|
||||
{
|
||||
if (sockets.TryGetValue(instanceId, out var socket))
|
||||
{
|
||||
string reason = Marshal.PtrToStringAuto(reasonPtr);
|
||||
socket.HandleOnClose((ushort)closeCode, reason);
|
||||
}
|
||||
}
|
||||
|
||||
internal static int AllocateInstance(string address)
|
||||
{
|
||||
if (!isInitialized) Initialize();
|
||||
return WebSocketAllocate(address);
|
||||
}
|
||||
|
||||
internal static void Add(WebSocket socket)
|
||||
{
|
||||
if (!sockets.ContainsKey(socket.instanceId))
|
||||
{
|
||||
sockets.Add(socket.instanceId, socket);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Remove(int instanceId)
|
||||
{
|
||||
if (sockets.ContainsKey(instanceId))
|
||||
{
|
||||
sockets.Remove(instanceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 246cdc66a1e2047148371a8e56e17d3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "UnityWebSocket.Runtime",
|
||||
"references": [],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b65d8710c3b04373a41cbf6b777ee65
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
xiaofang/Assets/comm/Proto.meta
Normal file
8
xiaofang/Assets/comm/Proto.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 238d5690fe411f84da0c68ad5efd0d81
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
83
xiaofang/Assets/comm/Proto/Config.cs
Normal file
83
xiaofang/Assets/comm/Proto/Config.cs
Normal file
@ -0,0 +1,83 @@
|
||||
// <auto-generated>
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: config.proto
|
||||
// </auto-generated>
|
||||
#pragma warning disable 1591, 0612, 3021, 8981
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.Protobuf;
|
||||
using pbc = global::Google.Protobuf.Collections;
|
||||
using pbr = global::Google.Protobuf.Reflection;
|
||||
using scg = global::System.Collections.Generic;
|
||||
/// <summary>Holder for reflection information generated from config.proto</summary>
|
||||
public static partial class ConfigReflection {
|
||||
|
||||
#region Descriptor
|
||||
/// <summary>File descriptor for config.proto</summary>
|
||||
public static pbr::FileDescriptor Descriptor {
|
||||
get { return descriptor; }
|
||||
}
|
||||
private static pbr::FileDescriptor descriptor;
|
||||
|
||||
static ConfigReflection() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"Cgxjb25maWcucHJvdG8qnQEKCkVSUk9SX0NPREUSCgoGRVJSX09rEAASEAoM",
|
||||
"RVJSX05vUGxheWVyEAESDgoKRVJSX05vUm9vbRACEg0KCUVSUl9Ub2tlbhAE",
|
||||
"Eg0KCUVSUl9Mb2dpbhAFEg4KCkVSUl9BY3Rpb24QBhIOCgpFUlJfUGFyYW1z",
|
||||
"EAcSDgoKRVJSX1NlcnZlchAIEhMKD0VSUl9Ob0F1dGhvcml0eRAJQgdaBS4v",
|
||||
"O3BiYgZwcm90bzM="));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ERROR_CODE), }, null, null));
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Enums
|
||||
/// <summary>
|
||||
///错误码
|
||||
/// </summary>
|
||||
public enum ERROR_CODE {
|
||||
/// <summary>
|
||||
///OK
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_Ok")] ErrOk = 0,
|
||||
/// <summary>
|
||||
///没有这个玩家
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_NoPlayer")] ErrNoPlayer = 1,
|
||||
/// <summary>
|
||||
///加入房间失败
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_NoRoom")] ErrNoRoom = 2,
|
||||
/// <summary>
|
||||
///Token验证失败
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_Token")] ErrToken = 4,
|
||||
/// <summary>
|
||||
///登录失败
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_Login")] ErrLogin = 5,
|
||||
/// <summary>
|
||||
///操作失败
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_Action")] ErrAction = 6,
|
||||
/// <summary>
|
||||
///参数错误
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_Params")] ErrParams = 7,
|
||||
/// <summary>
|
||||
///服务器内部错误
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_Server")] ErrServer = 8,
|
||||
/// <summary>
|
||||
///没有权限
|
||||
/// </summary>
|
||||
[pbr::OriginalName("ERR_NoAuthority")] ErrNoAuthority = 9,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#endregion Designer generated code
|
11
xiaofang/Assets/comm/Proto/Config.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Config.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6249125b6bd7a964aa825c041b9cab82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1099
xiaofang/Assets/comm/Proto/Fps.cs
Normal file
1099
xiaofang/Assets/comm/Proto/Fps.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/Fps.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Fps.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 013d659005f08544cafe01b5a18e6072
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
4803
xiaofang/Assets/comm/Proto/Hall.cs
Normal file
4803
xiaofang/Assets/comm/Proto/Hall.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/Hall.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Hall.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fd26537609bdf14b8eb7d5150ef5262
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
675
xiaofang/Assets/comm/Proto/Join.cs
Normal file
675
xiaofang/Assets/comm/Proto/Join.cs
Normal file
@ -0,0 +1,675 @@
|
||||
// <auto-generated>
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: join.proto
|
||||
// </auto-generated>
|
||||
#pragma warning disable 1591, 0612, 3021, 8981
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.Protobuf;
|
||||
using pbc = global::Google.Protobuf.Collections;
|
||||
using pbr = global::Google.Protobuf.Reflection;
|
||||
using scg = global::System.Collections.Generic;
|
||||
/// <summary>Holder for reflection information generated from join.proto</summary>
|
||||
public static partial class JoinReflection {
|
||||
|
||||
#region Descriptor
|
||||
/// <summary>File descriptor for join.proto</summary>
|
||||
public static pbr::FileDescriptor Descriptor {
|
||||
get { return descriptor; }
|
||||
}
|
||||
private static pbr::FileDescriptor descriptor;
|
||||
|
||||
static JoinReflection() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"Cgpqb2luLnByb3RvIogBChBVc2VySm9pblJlc3BvbnNlEg4KBnVzZXJJZBgB",
|
||||
"IAEoAxIQCghuaWNrTmFtZRgCIAEoCRIQCghyb2xlTmFtZRgDIAEoCRIOCgZy",
|
||||
"b29tSWQYBCABKAkSDgoGb25saW5lGAUgASgIEhMKC21lc3NhZ2VUeXBlGAYg",
|
||||
"ASgFEgsKA2NtZBgHIAEoCSI3ChBSb29tVXNlclJlc3BvbnNlEiMKCHVzZXJM",
|
||||
"aXN0GAEgAygLMhEuVXNlckpvaW5SZXNwb25zZUIHWgUuLztwYmIGcHJvdG8z"));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::UserJoinResponse), global::UserJoinResponse.Parser, new[]{ "UserId", "NickName", "RoleName", "RoomId", "Online", "MessageType", "Cmd" }, null, null, null, null),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::RoomUserResponse), global::RoomUserResponse.Parser, new[]{ "UserList" }, null, null, null, null)
|
||||
}));
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
|
||||
public sealed partial class UserJoinResponse : pb::IMessage<UserJoinResponse>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<UserJoinResponse> _parser = new pb::MessageParser<UserJoinResponse>(() => new UserJoinResponse());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<UserJoinResponse> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::JoinReflection.Descriptor.MessageTypes[0]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||
get { return Descriptor; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public UserJoinResponse() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public UserJoinResponse(UserJoinResponse other) : this() {
|
||||
userId_ = other.userId_;
|
||||
nickName_ = other.nickName_;
|
||||
roleName_ = other.roleName_;
|
||||
roomId_ = other.roomId_;
|
||||
online_ = other.online_;
|
||||
messageType_ = other.messageType_;
|
||||
cmd_ = other.cmd_;
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public UserJoinResponse Clone() {
|
||||
return new UserJoinResponse(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "userId" field.</summary>
|
||||
public const int UserIdFieldNumber = 1;
|
||||
private long userId_;
|
||||
/// <summary>
|
||||
/// 用户id
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public long UserId {
|
||||
get { return userId_; }
|
||||
set {
|
||||
userId_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "nickName" field.</summary>
|
||||
public const int NickNameFieldNumber = 2;
|
||||
private string nickName_ = "";
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string NickName {
|
||||
get { return nickName_; }
|
||||
set {
|
||||
nickName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "roleName" field.</summary>
|
||||
public const int RoleNameFieldNumber = 3;
|
||||
private string roleName_ = "";
|
||||
/// <summary>
|
||||
/// 用户角色
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string RoleName {
|
||||
get { return roleName_; }
|
||||
set {
|
||||
roleName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "roomId" field.</summary>
|
||||
public const int RoomIdFieldNumber = 4;
|
||||
private string roomId_ = "";
|
||||
/// <summary>
|
||||
///房间号
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string RoomId {
|
||||
get { return roomId_; }
|
||||
set {
|
||||
roomId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "online" field.</summary>
|
||||
public const int OnlineFieldNumber = 5;
|
||||
private bool online_;
|
||||
/// <summary>
|
||||
///状态 接收这个用户是不是掉线了
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Online {
|
||||
get { return online_; }
|
||||
set {
|
||||
online_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "messageType" field.</summary>
|
||||
public const int MessageTypeFieldNumber = 6;
|
||||
private int messageType_;
|
||||
/// <summary>
|
||||
///事件状态 1 用户上线 2用户下线 3 用户加入房间
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int MessageType {
|
||||
get { return messageType_; }
|
||||
set {
|
||||
messageType_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "cmd" field.</summary>
|
||||
public const int CmdFieldNumber = 7;
|
||||
private string cmd_ = "";
|
||||
/// <summary>
|
||||
///操作指令
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string Cmd {
|
||||
get { return cmd_; }
|
||||
set {
|
||||
cmd_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as UserJoinResponse);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(UserJoinResponse other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if (UserId != other.UserId) return false;
|
||||
if (NickName != other.NickName) return false;
|
||||
if (RoleName != other.RoleName) return false;
|
||||
if (RoomId != other.RoomId) return false;
|
||||
if (Online != other.Online) return false;
|
||||
if (MessageType != other.MessageType) return false;
|
||||
if (Cmd != other.Cmd) return false;
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
if (UserId != 0L) hash ^= UserId.GetHashCode();
|
||||
if (NickName.Length != 0) hash ^= NickName.GetHashCode();
|
||||
if (RoleName.Length != 0) hash ^= RoleName.GetHashCode();
|
||||
if (RoomId.Length != 0) hash ^= RoomId.GetHashCode();
|
||||
if (Online != false) hash ^= Online.GetHashCode();
|
||||
if (MessageType != 0) hash ^= MessageType.GetHashCode();
|
||||
if (Cmd.Length != 0) hash ^= Cmd.GetHashCode();
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override string ToString() {
|
||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void WriteTo(pb::CodedOutputStream output) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
output.WriteRawMessage(this);
|
||||
#else
|
||||
if (UserId != 0L) {
|
||||
output.WriteRawTag(8);
|
||||
output.WriteInt64(UserId);
|
||||
}
|
||||
if (NickName.Length != 0) {
|
||||
output.WriteRawTag(18);
|
||||
output.WriteString(NickName);
|
||||
}
|
||||
if (RoleName.Length != 0) {
|
||||
output.WriteRawTag(26);
|
||||
output.WriteString(RoleName);
|
||||
}
|
||||
if (RoomId.Length != 0) {
|
||||
output.WriteRawTag(34);
|
||||
output.WriteString(RoomId);
|
||||
}
|
||||
if (Online != false) {
|
||||
output.WriteRawTag(40);
|
||||
output.WriteBool(Online);
|
||||
}
|
||||
if (MessageType != 0) {
|
||||
output.WriteRawTag(48);
|
||||
output.WriteInt32(MessageType);
|
||||
}
|
||||
if (Cmd.Length != 0) {
|
||||
output.WriteRawTag(58);
|
||||
output.WriteString(Cmd);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||
if (UserId != 0L) {
|
||||
output.WriteRawTag(8);
|
||||
output.WriteInt64(UserId);
|
||||
}
|
||||
if (NickName.Length != 0) {
|
||||
output.WriteRawTag(18);
|
||||
output.WriteString(NickName);
|
||||
}
|
||||
if (RoleName.Length != 0) {
|
||||
output.WriteRawTag(26);
|
||||
output.WriteString(RoleName);
|
||||
}
|
||||
if (RoomId.Length != 0) {
|
||||
output.WriteRawTag(34);
|
||||
output.WriteString(RoomId);
|
||||
}
|
||||
if (Online != false) {
|
||||
output.WriteRawTag(40);
|
||||
output.WriteBool(Online);
|
||||
}
|
||||
if (MessageType != 0) {
|
||||
output.WriteRawTag(48);
|
||||
output.WriteInt32(MessageType);
|
||||
}
|
||||
if (Cmd.Length != 0) {
|
||||
output.WriteRawTag(58);
|
||||
output.WriteString(Cmd);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(ref output);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
if (UserId != 0L) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UserId);
|
||||
}
|
||||
if (NickName.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(NickName);
|
||||
}
|
||||
if (RoleName.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(RoleName);
|
||||
}
|
||||
if (RoomId.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(RoomId);
|
||||
}
|
||||
if (Online != false) {
|
||||
size += 1 + 1;
|
||||
}
|
||||
if (MessageType != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(MessageType);
|
||||
}
|
||||
if (Cmd.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Cmd);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(UserJoinResponse other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
if (other.UserId != 0L) {
|
||||
UserId = other.UserId;
|
||||
}
|
||||
if (other.NickName.Length != 0) {
|
||||
NickName = other.NickName;
|
||||
}
|
||||
if (other.RoleName.Length != 0) {
|
||||
RoleName = other.RoleName;
|
||||
}
|
||||
if (other.RoomId.Length != 0) {
|
||||
RoomId = other.RoomId;
|
||||
}
|
||||
if (other.Online != false) {
|
||||
Online = other.Online;
|
||||
}
|
||||
if (other.MessageType != 0) {
|
||||
MessageType = other.MessageType;
|
||||
}
|
||||
if (other.Cmd.Length != 0) {
|
||||
Cmd = other.Cmd;
|
||||
}
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(pb::CodedInputStream input) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
input.ReadRawMessage(this);
|
||||
#else
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
case 8: {
|
||||
UserId = input.ReadInt64();
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
NickName = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 26: {
|
||||
RoleName = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
RoomId = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 40: {
|
||||
Online = input.ReadBool();
|
||||
break;
|
||||
}
|
||||
case 48: {
|
||||
MessageType = input.ReadInt32();
|
||||
break;
|
||||
}
|
||||
case 58: {
|
||||
Cmd = input.ReadString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||
break;
|
||||
case 8: {
|
||||
UserId = input.ReadInt64();
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
NickName = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 26: {
|
||||
RoleName = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
RoomId = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 40: {
|
||||
Online = input.ReadBool();
|
||||
break;
|
||||
}
|
||||
case 48: {
|
||||
MessageType = input.ReadInt32();
|
||||
break;
|
||||
}
|
||||
case 58: {
|
||||
Cmd = input.ReadString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
|
||||
public sealed partial class RoomUserResponse : pb::IMessage<RoomUserResponse>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<RoomUserResponse> _parser = new pb::MessageParser<RoomUserResponse>(() => new RoomUserResponse());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<RoomUserResponse> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::JoinReflection.Descriptor.MessageTypes[1]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||
get { return Descriptor; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public RoomUserResponse() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public RoomUserResponse(RoomUserResponse other) : this() {
|
||||
userList_ = other.userList_.Clone();
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public RoomUserResponse Clone() {
|
||||
return new RoomUserResponse(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "userList" field.</summary>
|
||||
public const int UserListFieldNumber = 1;
|
||||
private static readonly pb::FieldCodec<global::UserJoinResponse> _repeated_userList_codec
|
||||
= pb::FieldCodec.ForMessage(10, global::UserJoinResponse.Parser);
|
||||
private readonly pbc::RepeatedField<global::UserJoinResponse> userList_ = new pbc::RepeatedField<global::UserJoinResponse>();
|
||||
/// <summary>
|
||||
///用户列表
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public pbc::RepeatedField<global::UserJoinResponse> UserList {
|
||||
get { return userList_; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as RoomUserResponse);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(RoomUserResponse other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if(!userList_.Equals(other.userList_)) return false;
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
hash ^= userList_.GetHashCode();
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override string ToString() {
|
||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void WriteTo(pb::CodedOutputStream output) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
output.WriteRawMessage(this);
|
||||
#else
|
||||
userList_.WriteTo(output, _repeated_userList_codec);
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||
userList_.WriteTo(ref output, _repeated_userList_codec);
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(ref output);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
size += userList_.CalculateSize(_repeated_userList_codec);
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(RoomUserResponse other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
userList_.Add(other.userList_);
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(pb::CodedInputStream input) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
input.ReadRawMessage(this);
|
||||
#else
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
case 10: {
|
||||
userList_.AddEntriesFrom(input, _repeated_userList_codec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||
break;
|
||||
case 10: {
|
||||
userList_.AddEntriesFrom(ref input, _repeated_userList_codec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#endregion Designer generated code
|
11
xiaofang/Assets/comm/Proto/Join.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Join.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63abcfa0f6080534d8642cfb5eae1ac0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
525
xiaofang/Assets/comm/Proto/MessageBroadcast.cs
Normal file
525
xiaofang/Assets/comm/Proto/MessageBroadcast.cs
Normal file
@ -0,0 +1,525 @@
|
||||
// <auto-generated>
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: message_broadcast.proto
|
||||
// </auto-generated>
|
||||
#pragma warning disable 1591, 0612, 3021, 8981
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.Protobuf;
|
||||
using pbc = global::Google.Protobuf.Collections;
|
||||
using pbr = global::Google.Protobuf.Reflection;
|
||||
using scg = global::System.Collections.Generic;
|
||||
/// <summary>Holder for reflection information generated from message_broadcast.proto</summary>
|
||||
public static partial class MessageBroadcastReflection {
|
||||
|
||||
#region Descriptor
|
||||
/// <summary>File descriptor for message_broadcast.proto</summary>
|
||||
public static pbr::FileDescriptor Descriptor {
|
||||
get { return descriptor; }
|
||||
}
|
||||
private static pbr::FileDescriptor descriptor;
|
||||
|
||||
static MessageBroadcastReflection() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"ChdtZXNzYWdlX2Jyb2FkY2FzdC5wcm90byJUChdNZXNzYWdlQnJvYWRjYXN0",
|
||||
"UmVxdWVzdBIOCgZyb29tSWQYASABKAkSDAoEdHlwZRgCIAEoBRIOCgZyb2xl",
|
||||
"SWQYAyABKAkSCwoDY21kGAQgASgJIhoKGE1lc3NhZ2VCcm9hZGNhc3RSZXNw",
|
||||
"b25zZUIHWgUuLztwYmIGcHJvdG8z"));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::MessageBroadcastRequest), global::MessageBroadcastRequest.Parser, new[]{ "RoomId", "Type", "RoleId", "Cmd" }, null, null, null, null),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::MessageBroadcastResponse), global::MessageBroadcastResponse.Parser, null, null, null, null, null)
|
||||
}));
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Messages
|
||||
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
|
||||
public sealed partial class MessageBroadcastRequest : pb::IMessage<MessageBroadcastRequest>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<MessageBroadcastRequest> _parser = new pb::MessageParser<MessageBroadcastRequest>(() => new MessageBroadcastRequest());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<MessageBroadcastRequest> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::MessageBroadcastReflection.Descriptor.MessageTypes[0]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||
get { return Descriptor; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public MessageBroadcastRequest() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public MessageBroadcastRequest(MessageBroadcastRequest other) : this() {
|
||||
roomId_ = other.roomId_;
|
||||
type_ = other.type_;
|
||||
roleId_ = other.roleId_;
|
||||
cmd_ = other.cmd_;
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public MessageBroadcastRequest Clone() {
|
||||
return new MessageBroadcastRequest(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "roomId" field.</summary>
|
||||
public const int RoomIdFieldNumber = 1;
|
||||
private string roomId_ = "";
|
||||
/// <summary>
|
||||
/// 房间id
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string RoomId {
|
||||
get { return roomId_; }
|
||||
set {
|
||||
roomId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "type" field.</summary>
|
||||
public const int TypeFieldNumber = 2;
|
||||
private int type_;
|
||||
/// <summary>
|
||||
/// 消息类型 1. 文本 2. 图片 3. 语音 4. 视频
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int Type {
|
||||
get { return type_; }
|
||||
set {
|
||||
type_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "roleId" field.</summary>
|
||||
public const int RoleIdFieldNumber = 3;
|
||||
private string roleId_ = "";
|
||||
/// <summary>
|
||||
/// 角色Id 如果为空就是给所有人发
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string RoleId {
|
||||
get { return roleId_; }
|
||||
set {
|
||||
roleId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "cmd" field.</summary>
|
||||
public const int CmdFieldNumber = 4;
|
||||
private string cmd_ = "";
|
||||
/// <summary>
|
||||
/// 自定义命令
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string Cmd {
|
||||
get { return cmd_; }
|
||||
set {
|
||||
cmd_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as MessageBroadcastRequest);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(MessageBroadcastRequest other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if (RoomId != other.RoomId) return false;
|
||||
if (Type != other.Type) return false;
|
||||
if (RoleId != other.RoleId) return false;
|
||||
if (Cmd != other.Cmd) return false;
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
if (RoomId.Length != 0) hash ^= RoomId.GetHashCode();
|
||||
if (Type != 0) hash ^= Type.GetHashCode();
|
||||
if (RoleId.Length != 0) hash ^= RoleId.GetHashCode();
|
||||
if (Cmd.Length != 0) hash ^= Cmd.GetHashCode();
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override string ToString() {
|
||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void WriteTo(pb::CodedOutputStream output) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
output.WriteRawMessage(this);
|
||||
#else
|
||||
if (RoomId.Length != 0) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(RoomId);
|
||||
}
|
||||
if (Type != 0) {
|
||||
output.WriteRawTag(16);
|
||||
output.WriteInt32(Type);
|
||||
}
|
||||
if (RoleId.Length != 0) {
|
||||
output.WriteRawTag(26);
|
||||
output.WriteString(RoleId);
|
||||
}
|
||||
if (Cmd.Length != 0) {
|
||||
output.WriteRawTag(34);
|
||||
output.WriteString(Cmd);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||
if (RoomId.Length != 0) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(RoomId);
|
||||
}
|
||||
if (Type != 0) {
|
||||
output.WriteRawTag(16);
|
||||
output.WriteInt32(Type);
|
||||
}
|
||||
if (RoleId.Length != 0) {
|
||||
output.WriteRawTag(26);
|
||||
output.WriteString(RoleId);
|
||||
}
|
||||
if (Cmd.Length != 0) {
|
||||
output.WriteRawTag(34);
|
||||
output.WriteString(Cmd);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(ref output);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
if (RoomId.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(RoomId);
|
||||
}
|
||||
if (Type != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Type);
|
||||
}
|
||||
if (RoleId.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(RoleId);
|
||||
}
|
||||
if (Cmd.Length != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Cmd);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(MessageBroadcastRequest other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
if (other.RoomId.Length != 0) {
|
||||
RoomId = other.RoomId;
|
||||
}
|
||||
if (other.Type != 0) {
|
||||
Type = other.Type;
|
||||
}
|
||||
if (other.RoleId.Length != 0) {
|
||||
RoleId = other.RoleId;
|
||||
}
|
||||
if (other.Cmd.Length != 0) {
|
||||
Cmd = other.Cmd;
|
||||
}
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(pb::CodedInputStream input) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
input.ReadRawMessage(this);
|
||||
#else
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
case 10: {
|
||||
RoomId = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
Type = input.ReadInt32();
|
||||
break;
|
||||
}
|
||||
case 26: {
|
||||
RoleId = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
Cmd = input.ReadString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||
break;
|
||||
case 10: {
|
||||
RoomId = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
Type = input.ReadInt32();
|
||||
break;
|
||||
}
|
||||
case 26: {
|
||||
RoleId = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
Cmd = input.ReadString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
|
||||
public sealed partial class MessageBroadcastResponse : pb::IMessage<MessageBroadcastResponse>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<MessageBroadcastResponse> _parser = new pb::MessageParser<MessageBroadcastResponse>(() => new MessageBroadcastResponse());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<MessageBroadcastResponse> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::MessageBroadcastReflection.Descriptor.MessageTypes[1]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||
get { return Descriptor; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public MessageBroadcastResponse() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public MessageBroadcastResponse(MessageBroadcastResponse other) : this() {
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public MessageBroadcastResponse Clone() {
|
||||
return new MessageBroadcastResponse(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as MessageBroadcastResponse);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(MessageBroadcastResponse other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override string ToString() {
|
||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void WriteTo(pb::CodedOutputStream output) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
output.WriteRawMessage(this);
|
||||
#else
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(ref output);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(MessageBroadcastResponse other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(pb::CodedInputStream input) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
input.ReadRawMessage(this);
|
||||
#else
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 4) {
|
||||
// Abort on any end group tag.
|
||||
return;
|
||||
}
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#endregion Designer generated code
|
11
xiaofang/Assets/comm/Proto/MessageBroadcast.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/MessageBroadcast.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 061900a49550cc74582eb8e4598a886b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1927
xiaofang/Assets/comm/Proto/Move.cs
Normal file
1927
xiaofang/Assets/comm/Proto/Move.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/Move.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Move.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b549e9113344b542a6f785f98166927
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1921
xiaofang/Assets/comm/Proto/Prop.cs
Normal file
1921
xiaofang/Assets/comm/Proto/Prop.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/Prop.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Prop.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66a0cd6fc174b4042b409c9030c08516
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
28
xiaofang/Assets/comm/Proto/ProtoBufffer.cs
Normal file
28
xiaofang/Assets/comm/Proto/ProtoBufffer.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Google.Protobuf;
|
||||
using System;
|
||||
public class ProtoBufffer
|
||||
{
|
||||
public static byte[] Serialize(IMessage message)
|
||||
{
|
||||
return message.ToByteArray();
|
||||
}
|
||||
|
||||
public static T DeSerialize<T>(byte[] packet) where T : IMessage, new()
|
||||
{
|
||||
IMessage message = new T();
|
||||
try
|
||||
{
|
||||
return (T)message.Descriptor.Parser.ParseFrom(packet);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static T DeSerialize<T>(ByteString data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
11
xiaofang/Assets/comm/Proto/ProtoBufffer.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/ProtoBufffer.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09a7d1a0777441d489f8b7ffae5077c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
2750
xiaofang/Assets/comm/Proto/Room.cs
Normal file
2750
xiaofang/Assets/comm/Proto/Room.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/Room.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Room.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efe7f33d728ac2948956f9a0bcf43259
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
2826
xiaofang/Assets/comm/Proto/Task.cs
Normal file
2826
xiaofang/Assets/comm/Proto/Task.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/Task.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/Task.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dc2c5b09fa1821438dbc817a6f5cb74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1031
xiaofang/Assets/comm/Proto/User.cs
Normal file
1031
xiaofang/Assets/comm/Proto/User.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
xiaofang/Assets/comm/Proto/User.cs.meta
Normal file
11
xiaofang/Assets/comm/Proto/User.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89dab302d915deb4ba459f561a2a9f15
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -320,7 +320,7 @@ public sealed partial class WSMessage : pb::IMessage<WSMessage>
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a0e968aa808f743ae45f5525efa824
|
||||
guid: 6d54b057f10017a4d98893bdbd8509e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
215
xiaofang/Assets/comm/WEBScriptListener.cs
Normal file
215
xiaofang/Assets/comm/WEBScriptListener.cs
Normal file
@ -0,0 +1,215 @@
|
||||
// WebSocket
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityWebSocket;
|
||||
/// <summary>
|
||||
/// Socket连接
|
||||
/// </summary>
|
||||
public class WEBScriptListener: MonoBehaviour
|
||||
{
|
||||
public string serverIP = "ws://192.168.3.110";
|
||||
//服务器端口
|
||||
public int serverPort = 8445;
|
||||
WebSocket socket;
|
||||
public string type; // 类型
|
||||
public delegate void MyCallback(byte[] data);
|
||||
public event MyCallback OnCallback;
|
||||
public void ConcatWEBSocket()
|
||||
{
|
||||
socket = new WebSocket($"{serverIP}:{serverPort}/safety/cloud");
|
||||
socket.OnOpen += Socket_OnOpen;
|
||||
socket.OnMessage += Socket_OnMessage;
|
||||
socket.OnError += Socket_OnError;
|
||||
socket.ConnectAsync();
|
||||
Debug.Log($"执行websocket");
|
||||
}
|
||||
private void Socket_OnOpen(object sender, OpenEventArgs e)
|
||||
{
|
||||
Debug.Log("================");
|
||||
}
|
||||
void Socket_OnMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
var data = Encoding.UTF8.GetString(e.RawData);
|
||||
if (OnCallback != null)
|
||||
{
|
||||
Debug.Log(e.RawData);
|
||||
OnCallback(e.RawData);
|
||||
}
|
||||
|
||||
}
|
||||
void Socket_OnError(object sender, ErrorEventArgs e)
|
||||
{
|
||||
Debug.Log(string.Format("Error: {0}", e.Message));
|
||||
}
|
||||
public void SendMessageByte(byte[] message)
|
||||
{
|
||||
if (socket != null)
|
||||
{
|
||||
Debug.Log("发送信息");
|
||||
Debug.Log(string.Format("Error: {0}", message));
|
||||
socket.SendAsync(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("WebSocket is not connected!");
|
||||
}
|
||||
}
|
||||
public void SendMessageText(string message)
|
||||
{
|
||||
if (socket != null)
|
||||
{
|
||||
Debug.Log("发送信息");
|
||||
socket.SendAsync(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("WebSocket is not connected!");
|
||||
}
|
||||
}
|
||||
//服务器端口
|
||||
/*public string serverIP = "192.168.3.110";
|
||||
public int serverPort = 8445;
|
||||
Socket socket;
|
||||
private bool IsConnect = true;
|
||||
private string recMes = "NULL";
|
||||
private int recTimes = 0;
|
||||
private string staInfo = "NULL";
|
||||
private object s_thread;
|
||||
|
||||
public void ConcatWEBSocket()
|
||||
{
|
||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
IPAddress ip = IPAddress.Parse(serverIP);
|
||||
IPEndPoint point = new IPEndPoint(ip, serverPort);
|
||||
|
||||
socket.Connect(point);
|
||||
Debug.Log("连接成功 , " + " ip = " + ip + " port = " + serverPort);
|
||||
staInfo = ip + ":" + serverPort + " 连接成功";
|
||||
Thread r_thread = new Thread(ReceiveMessage); //开启新的线程,不停的接收服务器发来的消息
|
||||
r_thread.IsBackground = true;
|
||||
r_thread.Start();
|
||||
|
||||
Thread s_thread = new Thread(SendMessage); //开启新的线程,不停的给服务器发送消息
|
||||
s_thread.IsBackground = true;
|
||||
s_thread.Start();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Debug.Log("IP或者端口号错误......");
|
||||
staInfo = "IP或者端口号错误......";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SendMessage()
|
||||
{
|
||||
Debug.Log("发送消息!");
|
||||
byte[] data = Encoding.UTF8.GetBytes("CCDDA10100010001A448");
|
||||
socket.Send(data);
|
||||
}
|
||||
void ReceiveMessage()
|
||||
{
|
||||
while (IsConnect)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] buffer = new byte[9];
|
||||
//实际接收到的有效字节数
|
||||
int len = socket.Receive(buffer);
|
||||
if (len == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
recMes = HexDecoder.ByteArrayToString(buffer);
|
||||
Debug.Log("客户端接收到的数据 : " + len);
|
||||
Debug.Log("客户端接收到的数据 : " + recMes.ToUpper());
|
||||
|
||||
recTimes++;
|
||||
staInfo = "接收到一次数据,接收次数为 :" + recTimes;
|
||||
Debug.Log("接收次数为:" + recTimes);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
}
|
||||
// HEX 转换为16进制
|
||||
public class HexDecoder
|
||||
{
|
||||
public static string ByteArrayToString(byte[] ba)
|
||||
{
|
||||
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
||||
foreach (byte b in ba)
|
||||
hex.AppendFormat("{0:x2}", b);
|
||||
return hex.ToString();
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
/*using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
public class WEBScriptListener
|
||||
{
|
||||
public void TCPServerDemo()
|
||||
{
|
||||
//服务端的IP地址
|
||||
//请先在终端上查询服务器IP
|
||||
string serverIP = "192.168.3.218";
|
||||
//服务器端口
|
||||
int serverPort = 50000;
|
||||
|
||||
Debug.Log("本机作为服务端");
|
||||
Debug.Log($"本机IP:{serverIP},端口:{serverPort}");
|
||||
|
||||
//使用指定的地址族,套接字类型和协议实例化新的套接字
|
||||
Socket socketServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
//将字符串地址转化为网际协议地址
|
||||
IPAddress ipAddress = IPAddress.Parse(serverIP);//这里为服务器IP
|
||||
//使用指定地址和端口号实例化新的网络端点
|
||||
IPEndPoint endPoint = new IPEndPoint(ipAddress, serverPort);//ipAddress为服务器IP , 6000为服务器端口
|
||||
Debug.Log(string.Format("消息: {0}", endPoint));
|
||||
try
|
||||
{
|
||||
//socket与本地终结点相关联,绑定IP与端口
|
||||
socketServer.Bind(endPoint);
|
||||
//设置最大侦听长度,并启动侦听
|
||||
socketServer.Listen(200);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("请检查IP是否正确,或端口是否被占用?");
|
||||
socketServer.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("启动侦听,等待客户端请求连接。。。");
|
||||
//等待客户端连接,如果没有客户端连接,即会一址等待
|
||||
//1、将硬件设备为TCP_Client
|
||||
//2、将硬件的目的IP设置与 serverIP 一致的值
|
||||
//3、将硬件的目的端口设备与 serverPort 一致的值
|
||||
//如果硬件不能连接上,请检查以上参数
|
||||
Socket socket = socketServer.Accept();
|
||||
Debug.Log("连接成功");
|
||||
|
||||
string[] strs = socket.RemoteEndPoint.ToString().Split(':');
|
||||
Debug.Log("客户端IP:" + strs[0] + " 端口:" + strs[1]);
|
||||
// 以下为数据发送与接收
|
||||
|
||||
Debug.Log("测试完成");
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
11
xiaofang/Assets/comm/WEBScriptListener.cs.meta
Normal file
11
xiaofang/Assets/comm/WEBScriptListener.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44720823678ca7c42a08f4409ab025ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
347
xiaofang/Assets/comm/test.cs
Normal file
347
xiaofang/Assets/comm/test.cs
Normal file
@ -0,0 +1,347 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Sockets;
|
||||
using UnityWebSocket;
|
||||
using System.Text;
|
||||
using Google.Protobuf;
|
||||
using System.Net.WebSockets;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
public class test : MonoBehaviour
|
||||
{
|
||||
public string token;
|
||||
public WEBScriptListener wEBScriptListener;
|
||||
public class auth_login
|
||||
{
|
||||
public string clientId = "e5cd7e4891bf95d1d19206ce24a7b32e";
|
||||
public string grantType = "password";
|
||||
public string userType = "company_user";
|
||||
public string username = "13699802230";
|
||||
public string password = "YYL2230!";
|
||||
}
|
||||
public async void loging()
|
||||
{
|
||||
auth_login auth_Login = new auth_login();
|
||||
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login));
|
||||
|
||||
// 解析服务器返回的数据
|
||||
server serverData = JsonConvert.DeserializeObject<server>(response);
|
||||
token = serverData.data.access_token;
|
||||
//Debug.Log(setverData.msg);
|
||||
|
||||
}
|
||||
//登录
|
||||
void lodingWebSocket()
|
||||
{
|
||||
LoginRequest data = new LoginRequest();
|
||||
data.UserId = "1846032755921199105";
|
||||
data.Account = "13152628999";
|
||||
|
||||
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "hall";
|
||||
msg.ServiceName = "Login";
|
||||
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
LoginRequest login = ProtoBufffer.DeSerialize<LoginRequest>(deinfo.Data.ToByteArray());
|
||||
Debug.Log("登录");
|
||||
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
}
|
||||
//加入房间
|
||||
void JoinRoom()
|
||||
{
|
||||
JoinRoomRequest data = new JoinRoomRequest();
|
||||
data.RoomId = "168888";
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "hall";
|
||||
msg.ServiceName = "JoinRoom";
|
||||
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
JoinRoomRequest login = ProtoBufffer.DeSerialize<JoinRoomRequest>(deinfo.Data.ToByteArray());
|
||||
Debug.Log("加入房间");
|
||||
//BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
}
|
||||
|
||||
//void BroadcastMessage()
|
||||
//{
|
||||
// WSMessage msg = new WSMessage();
|
||||
// msg.Module = "hall";
|
||||
// msg.ServiceName = "BroadcastMessage";
|
||||
// //msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
// byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
// JoinRoomRequest login = ProtoBufffer.DeSerialize<JoinRoomRequest>(deinfo.Data.ToByteArray());
|
||||
// Debug.Log("加入房间");
|
||||
// //BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
|
||||
// wEBScriptListener.SendMessageByte(sendData);
|
||||
//}
|
||||
|
||||
//心跳
|
||||
async void Heartbeat()
|
||||
{
|
||||
//WSMessage msg = new WSMessage();
|
||||
//msg.Data = ByteString.CopyFrom(new byte[] { 1 });
|
||||
//byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
//Debug.Log("");
|
||||
while (true)
|
||||
{
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "ping";
|
||||
//msg.Data = ByteString.CopyFrom(new byte[] { 1 });
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
// 每秒执行的任务
|
||||
Debug.Log("每秒执行一次");
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
|
||||
// 等待一秒
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
//帧存储操作输入
|
||||
//void UpFps()
|
||||
//{
|
||||
// InputData data = new InputData();
|
||||
// data.RoomId = "168888";
|
||||
// data.Id = "778899";
|
||||
// data.SId = "7";
|
||||
// data.X = 7f;
|
||||
// data.Y = 5f;
|
||||
// data.Z = 4f;
|
||||
// data.RoomSeatId = 5;
|
||||
// WSMessage msg = new WSMessage();
|
||||
// msg.Module = "fps";
|
||||
// msg.ServiceName = "UpFps";
|
||||
// msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
// byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
// InputData login = ProtoBufffer.DeSerialize<InputData>(deinfo.Data.ToByteArray());
|
||||
// Debug.Log("帧存储操作输入");
|
||||
// //BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
// wEBScriptListener.SendMessageByte(sendData);
|
||||
//}
|
||||
|
||||
//拾取道具
|
||||
void PickUpProp()
|
||||
{
|
||||
PropRequest data = new PropRequest();
|
||||
data.PropId = 1001;
|
||||
data.RoomId = "168888";
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "prop";
|
||||
msg.ServiceName = "PickUpProp";
|
||||
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
|
||||
Debug.Log("拾取道具");
|
||||
//BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
}
|
||||
|
||||
//使用道具
|
||||
void StartUseProp()
|
||||
{
|
||||
PropRequest data = new PropRequest();
|
||||
data.RoomId = "168888";
|
||||
data.PropId = 1001;
|
||||
data.Action = 1;
|
||||
data.PropServerId = "MTg1OTc5MDMwOTIyODc4OTc2MA==";
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "prop";
|
||||
msg.ServiceName = "StartUseProp";
|
||||
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
|
||||
Debug.Log("使用道具");
|
||||
//BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
}
|
||||
//停止使用道具
|
||||
void StopUseProp()
|
||||
{
|
||||
PropRequest data = new PropRequest();
|
||||
data.RoomId = "168888";
|
||||
data.PropId = 1001;
|
||||
data.PropServerId = "MTg1OTc5MDMwOTIyODc4OTc2MA==";
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "prop";
|
||||
msg.ServiceName = "StopUseProp";
|
||||
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
|
||||
Debug.Log("停止使用道具");
|
||||
//BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
}
|
||||
|
||||
//创建NPC ========================暂时不需要
|
||||
//void CreateNpc()
|
||||
//{
|
||||
// PropRequest data = new PropRequest();
|
||||
// data.RoomId = "168888";
|
||||
// WSMessage msg = new WSMessage();
|
||||
// msg.Module = "move";
|
||||
// msg.ServiceName = "CreateNpc";
|
||||
// msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
// byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
// PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
|
||||
// Debug.Log("创建NPC");
|
||||
// //BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
// wEBScriptListener.SendMessageByte(sendData);
|
||||
//}
|
||||
|
||||
//推送npc和玩家的信息 ===============只需要收消息
|
||||
//void Location()
|
||||
//{
|
||||
// PropRequest data = new PropRequest();
|
||||
// data.RoomId = "168888";
|
||||
// WSMessage msg = new WSMessage();
|
||||
// msg.Module = "prop";
|
||||
// msg.ServiceName = "CreateNpc";
|
||||
// msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
// byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
// PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
|
||||
// Debug.Log("推送npc和玩家的信息");
|
||||
// //BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
// wEBScriptListener.SendMessageByte(sendData);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//开始计时
|
||||
void RoomStartTime()
|
||||
{
|
||||
JoinRoomRequest data = new JoinRoomRequest();
|
||||
data.RoomId = "168888";
|
||||
WSMessage msg = new WSMessage();
|
||||
msg.Module = "hall";
|
||||
msg.ServiceName = "RoomStartTime";
|
||||
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
|
||||
byte[] sendData = ProtoBufffer.Serialize(msg);
|
||||
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
|
||||
JoinRoomRequest login = ProtoBufffer.DeSerialize<JoinRoomRequest>(deinfo.Data.ToByteArray());
|
||||
Debug.Log("推送npc和玩家的信息");
|
||||
//BroadcastFrameMsg.FramesFieldNumber
|
||||
|
||||
wEBScriptListener.SendMessageByte(sendData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
//loging();
|
||||
wEBScriptListener.ConcatWEBSocket();
|
||||
wEBScriptListener.OnCallback += callback;
|
||||
if (wEBScriptListener != null)
|
||||
{
|
||||
lodingWebSocket();
|
||||
JoinRoom();
|
||||
//Heartbeat();
|
||||
//BroadcastMessage();
|
||||
//UpFps();
|
||||
PickUpProp();
|
||||
StartUseProp();
|
||||
StopUseProp();
|
||||
//RoomStartTime();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void callback(byte[] data)
|
||||
{
|
||||
WSResponse deinfo = ProtoBufffer.DeSerialize<WSResponse>(data);
|
||||
Debug.Log("返回数据类型:"+deinfo.MessageType);
|
||||
byte[] bytes = deinfo.Data.ToByteArray();
|
||||
switch (deinfo.MessageType)
|
||||
{
|
||||
//监听
|
||||
//登录
|
||||
case "hall.Login":
|
||||
LoginResponse user = ProtoBufffer.DeSerialize<LoginResponse>(bytes);
|
||||
Debug.Log(user.Message);
|
||||
break;
|
||||
|
||||
//加入房间
|
||||
case "hall.JoinRoom":
|
||||
JoinRoomResponse joinRoomResponse = ProtoBufffer.DeSerialize<JoinRoomResponse>(bytes);
|
||||
byte[] joinByte = joinRoomResponse.Data.ToByteArray();
|
||||
PlayerJoinResponse playerJoinResponse = ProtoBufffer.DeSerialize<PlayerJoinResponse>(joinByte);
|
||||
Debug.Log("玩家:"+playerJoinResponse.UserName+"加入房间:"+playerJoinResponse.RoomId.ToString());
|
||||
break;
|
||||
|
||||
//广播
|
||||
case "hall.BroadcastMessage":
|
||||
UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize<UserJoinResponse>(bytes);
|
||||
Debug.Log("玩家昵称:" + userJoinResponse.NickName + ",房间:" + userJoinResponse.RoomId.ToString() + ",用户角色"+ userJoinResponse.RoleName);
|
||||
break;
|
||||
|
||||
//
|
||||
case "fps.UpFps":
|
||||
InputData inputData = ProtoBufffer.DeSerialize<InputData>(bytes);
|
||||
Debug.Log("Id:" + inputData.Id + ",sId :" + inputData.SId + ",X:"+ inputData.X.ToString() + ",Y:" + inputData.Y.ToString() + ",roomSeatId :" + inputData.RoomSeatId + ",z:" + inputData.Z.ToString() + ",roomId:" + inputData.RoomId);
|
||||
break;
|
||||
|
||||
case "prop.PickUpProp":
|
||||
PropRequest propRequest = ProtoBufffer.DeSerialize<PropRequest>(bytes);
|
||||
Debug.Log("PropId:" + propRequest.PropId);
|
||||
break;
|
||||
|
||||
case "prop.StartUseProp":
|
||||
PropResponse useProp = ProtoBufffer.DeSerialize<PropResponse>(bytes);
|
||||
|
||||
Debug.Log("PropId:" + useProp);
|
||||
break;
|
||||
|
||||
case "prop.StopUseProp":
|
||||
PropResponse stopuseProp = ProtoBufffer.DeSerialize<PropResponse>(bytes);
|
||||
|
||||
Debug.Log("PropId:" + stopuseProp);
|
||||
break;
|
||||
|
||||
//case "prop.CreateNpc":
|
||||
// MoveResponse moveResponse = ProtoBufffer.DeSerialize<MoveResponse>(bytes);
|
||||
// Debug.Log("UserId:" + moveResponse.UserId + ",RoomId:" + moveResponse.RoomId + ",x:" + moveResponse.MoveData);
|
||||
// break;
|
||||
|
||||
|
||||
|
||||
//case "hall.RoomStartTime":
|
||||
// JoinRoomRequest joinRoomRequest = ProtoBufffer.DeSerialize<JoinRoomRequest>(bytes);
|
||||
// Debug.Log("PropId:" + joinRoomRequest.RoomId);
|
||||
// break;
|
||||
//case " hall.MessageToUser":
|
||||
// //JoinRoomRequest joinRoomRequest = ProtoBufffer.DeSerialize<JoinRoomRequest>(bytes);
|
||||
// //Debug.Log("PropId:" + joinRoomRequest.RoomId);
|
||||
// break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
xiaofang/Assets/comm/test.cs.meta
Normal file
11
xiaofang/Assets/comm/test.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c68b1dcfbba61b44ca68572c16b16b95
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user