Skip to content

Commit eda8304

Browse files
committed
Add inheritance support. Update demo scene.
1 parent d943a87 commit eda8304

File tree

6 files changed

+196
-62
lines changed

6 files changed

+196
-62
lines changed

Assets/MyWebSocketServer.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
using WebSocketServer;
6+
7+
public class MyWebSocketServer : WebSocketServer.WebSocketServer
8+
{
9+
override public void OnOpen(WebSocketConnection connection) {
10+
// Here, (string)connection.id gives you a unique ID to identify the client.
11+
Debug.Log(connection.id);
12+
}
13+
14+
override public void OnMessage(WebSocketMessage message) {
15+
// (WebSocketConnection)message.connection gives you the connection that send the message.
16+
// (string)message.id gives you a unique ID for the message.
17+
// (string)message.data gives you the message content.
18+
Debug.Log(message.connection.id);
19+
Debug.Log(message.id);
20+
Debug.Log(message.data);
21+
}
22+
23+
override public void OnClose(WebSocketConnection connection) {
24+
// Here is the same as OnOpen
25+
Debug.Log(connection.id);
26+
}
27+
28+
public void onMessageReceived (WebSocketMessage message) {
29+
Debug.Log("Received new message: " + message.data);
30+
}
31+
}
File renamed without changes.

Assets/Scenes/SampleScene.unity

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,19 @@ MonoBehaviour:
232232
m_GameObject: {fileID: 944133941}
233233
m_Enabled: 1
234234
m_EditorHideFlags: 0
235-
m_Script: {fileID: 11500000, guid: 4ac217db4dad5436d9927ea08182cd9b, type: 3}
235+
m_Script: {fileID: 11500000, guid: 5cae6cd5a80444e79b49b1b23e819bb0, type: 3}
236236
m_Name:
237237
m_EditorClassIdentifier:
238238
address: 127.0.0.1
239239
port: 8175
240+
onOpen:
241+
m_PersistentCalls:
242+
m_Calls: []
240243
onMessage:
241244
m_PersistentCalls:
242245
m_Calls:
243-
- m_Target: {fileID: 1126526572}
244-
m_TargetAssemblyTypeName: SomeDemoScript, Assembly-CSharp
246+
- m_Target: {fileID: 944133942}
247+
m_TargetAssemblyTypeName: MyWebSocketServer, Assembly-CSharp
245248
m_MethodName: onMessageReceived
246249
m_Mode: 0
247250
m_Arguments:
@@ -252,6 +255,9 @@ MonoBehaviour:
252255
m_StringArgument:
253256
m_BoolArgument: 0
254257
m_CallState: 2
258+
onClose:
259+
m_PersistentCalls:
260+
m_Calls: []
255261
--- !u!4 &944133943
256262
Transform:
257263
m_ObjectHideFlags: 0
@@ -266,46 +272,3 @@ Transform:
266272
m_Father: {fileID: 0}
267273
m_RootOrder: 1
268274
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
269-
--- !u!1 &1126526571
270-
GameObject:
271-
m_ObjectHideFlags: 0
272-
m_CorrespondingSourceObject: {fileID: 0}
273-
m_PrefabInstance: {fileID: 0}
274-
m_PrefabAsset: {fileID: 0}
275-
serializedVersion: 6
276-
m_Component:
277-
- component: {fileID: 1126526573}
278-
- component: {fileID: 1126526572}
279-
m_Layer: 0
280-
m_Name: Some Other GameObject
281-
m_TagString: Untagged
282-
m_Icon: {fileID: 0}
283-
m_NavMeshLayer: 0
284-
m_StaticEditorFlags: 0
285-
m_IsActive: 1
286-
--- !u!114 &1126526572
287-
MonoBehaviour:
288-
m_ObjectHideFlags: 0
289-
m_CorrespondingSourceObject: {fileID: 0}
290-
m_PrefabInstance: {fileID: 0}
291-
m_PrefabAsset: {fileID: 0}
292-
m_GameObject: {fileID: 1126526571}
293-
m_Enabled: 1
294-
m_EditorHideFlags: 0
295-
m_Script: {fileID: 11500000, guid: 5cae6cd5a80444e79b49b1b23e819bb0, type: 3}
296-
m_Name:
297-
m_EditorClassIdentifier:
298-
--- !u!4 &1126526573
299-
Transform:
300-
m_ObjectHideFlags: 0
301-
m_CorrespondingSourceObject: {fileID: 0}
302-
m_PrefabInstance: {fileID: 0}
303-
m_PrefabAsset: {fileID: 0}
304-
m_GameObject: {fileID: 1126526571}
305-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
306-
m_LocalPosition: {x: 0, y: 0, z: 0}
307-
m_LocalScale: {x: 1, y: 1, z: 1}
308-
m_Children: []
309-
m_Father: {fileID: 0}
310-
m_RootOrder: 2
311-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

Assets/SomeDemoScript.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Assets/WebSocketServer/WebSocketServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ private void ListenForTcpConnection () {
101101
// return WebSocketProtocol.DecodeMessage(bytes);
102102
// }
103103

104-
public void OnOpen(WebSocketConnection connection) {}
104+
public virtual void OnOpen(WebSocketConnection connection) {}
105105

106-
public void OnMessage(WebSocketMessage message) {}
106+
public virtual void OnMessage(WebSocketMessage message) {}
107107

108-
public void OnClose(WebSocketConnection connection) {}
108+
public virtual void OnClose(WebSocketConnection connection) {}
109109

110-
public void OnError(WebSocketConnection connection) {}
110+
public virtual void OnError(WebSocketConnection connection) {}
111111

112112

113113
// private void SendMessage() {

Logs/AssetImportWorker0.log

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,3 +2072,155 @@ System memory in use after: 168.1 MB.
20722072
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2646.
20732073
Total: 3.040585 ms (FindLiveObjects: 0.363364 ms CreateObjectMapping: 0.067130 ms MarkObjects: 2.459490 ms DeleteObjects: 0.149128 ms)
20742074

2075+
========================================================================
2076+
Received Prepare
2077+
Registering precompiled user dll's ...
2078+
Registered in 0.000789 seconds.
2079+
Begin MonoManager ReloadAssembly
2080+
Native extension for OSXStandalone target not found
2081+
Refreshing native plugins compatible for Editor in 0.53 ms, found 2 plugins.
2082+
Preloading 0 native plugins for Editor in 0.00 ms.
2083+
Mono: successfully reloaded assembly
2084+
- Completed reload, in 1.062 seconds
2085+
Platform modules already initialized, skipping
2086+
Refreshing native plugins compatible for Editor in 0.36 ms, found 2 plugins.
2087+
Preloading 0 native plugins for Editor in 0.00 ms.
2088+
Unloading 1807 Unused Serialized files (Serialized files now loaded: 0)
2089+
System memory in use before: 168.3 MB.
2090+
System memory in use after: 168.3 MB.
2091+
2092+
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2650.
2093+
Total: 2.968602 ms (FindLiveObjects: 0.387611 ms CreateObjectMapping: 0.084138 ms MarkObjects: 2.366874 ms DeleteObjects: 0.128467 ms)
2094+
2095+
========================================================================
2096+
Received Import Request.
2097+
Time since last request: 9715.452427 seconds.
2098+
path: Assets/SomeDemoScript.cs
2099+
artifactKey: Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b)
2100+
Start importing Assets/SomeDemoScript.cs using Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b) -> (artifact id: '08ef17481a6c464d7cb9eda9f1298668') in 0.013014 seconds
2101+
Import took 0.017623 seconds .
2102+
2103+
========================================================================
2104+
Received Prepare
2105+
Registering precompiled user dll's ...
2106+
Registered in 0.001007 seconds.
2107+
Begin MonoManager ReloadAssembly
2108+
Native extension for OSXStandalone target not found
2109+
Refreshing native plugins compatible for Editor in 0.37 ms, found 2 plugins.
2110+
Preloading 0 native plugins for Editor in 0.00 ms.
2111+
Mono: successfully reloaded assembly
2112+
- Completed reload, in 1.105 seconds
2113+
Platform modules already initialized, skipping
2114+
Refreshing native plugins compatible for Editor in 0.35 ms, found 2 plugins.
2115+
Preloading 0 native plugins for Editor in 0.00 ms.
2116+
Unloading 1807 Unused Serialized files (Serialized files now loaded: 0)
2117+
System memory in use before: 168.5 MB.
2118+
System memory in use after: 168.5 MB.
2119+
2120+
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2654.
2121+
Total: 2.613195 ms (FindLiveObjects: 0.348336 ms CreateObjectMapping: 0.065173 ms MarkObjects: 2.075172 ms DeleteObjects: 0.123462 ms)
2122+
2123+
========================================================================
2124+
Received Import Request.
2125+
Time since last request: 10.735902 seconds.
2126+
path: Assets/MyWebSocketServer.cs
2127+
artifactKey: Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b)
2128+
Start importing Assets/MyWebSocketServer.cs using Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b) -> (artifact id: '01de21e644be05b7c5228c8563e8af1c') in 0.004918 seconds
2129+
Import took 0.008345 seconds .
2130+
2131+
========================================================================
2132+
Received Prepare
2133+
Registering precompiled user dll's ...
2134+
Registered in 0.000454 seconds.
2135+
Begin MonoManager ReloadAssembly
2136+
Native extension for OSXStandalone target not found
2137+
Refreshing native plugins compatible for Editor in 0.47 ms, found 2 plugins.
2138+
Preloading 0 native plugins for Editor in 0.00 ms.
2139+
Mono: successfully reloaded assembly
2140+
- Completed reload, in 1.164 seconds
2141+
Platform modules already initialized, skipping
2142+
Refreshing native plugins compatible for Editor in 0.36 ms, found 2 plugins.
2143+
Preloading 0 native plugins for Editor in 0.00 ms.
2144+
Unloading 1807 Unused Serialized files (Serialized files now loaded: 0)
2145+
System memory in use before: 168.7 MB.
2146+
System memory in use after: 168.7 MB.
2147+
2148+
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2658.
2149+
Total: 3.096174 ms (FindLiveObjects: 0.367049 ms CreateObjectMapping: 0.116191 ms MarkObjects: 2.463152 ms DeleteObjects: 0.146323 ms)
2150+
2151+
========================================================================
2152+
Received Prepare
2153+
Registering precompiled user dll's ...
2154+
Registered in 0.000668 seconds.
2155+
Begin MonoManager ReloadAssembly
2156+
Native extension for OSXStandalone target not found
2157+
Refreshing native plugins compatible for Editor in 0.39 ms, found 2 plugins.
2158+
Preloading 0 native plugins for Editor in 0.00 ms.
2159+
Mono: successfully reloaded assembly
2160+
- Completed reload, in 1.044 seconds
2161+
Platform modules already initialized, skipping
2162+
Refreshing native plugins compatible for Editor in 0.37 ms, found 2 plugins.
2163+
Preloading 0 native plugins for Editor in 0.00 ms.
2164+
Unloading 1807 Unused Serialized files (Serialized files now loaded: 0)
2165+
System memory in use before: 168.9 MB.
2166+
System memory in use after: 168.9 MB.
2167+
2168+
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2662.
2169+
Total: 2.453224 ms (FindLiveObjects: 0.258689 ms CreateObjectMapping: 0.068659 ms MarkObjects: 2.005193 ms DeleteObjects: 0.118142 ms)
2170+
2171+
========================================================================
2172+
Received Import Request.
2173+
Time since last request: 28.467701 seconds.
2174+
path: Assets/MyWebSocketServer.cs
2175+
artifactKey: Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b)
2176+
Start importing Assets/MyWebSocketServer.cs using Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b) -> (artifact id: '5dc23b7bda2f559c184f6c557216688b') in 0.005424 seconds
2177+
Import took 0.009599 seconds .
2178+
2179+
========================================================================
2180+
Received Prepare
2181+
Registering precompiled user dll's ...
2182+
Registered in 0.000776 seconds.
2183+
Begin MonoManager ReloadAssembly
2184+
Native extension for OSXStandalone target not found
2185+
Refreshing native plugins compatible for Editor in 0.42 ms, found 2 plugins.
2186+
Preloading 0 native plugins for Editor in 0.00 ms.
2187+
Mono: successfully reloaded assembly
2188+
- Completed reload, in 1.046 seconds
2189+
Platform modules already initialized, skipping
2190+
Refreshing native plugins compatible for Editor in 0.36 ms, found 2 plugins.
2191+
Preloading 0 native plugins for Editor in 0.00 ms.
2192+
Unloading 1807 Unused Serialized files (Serialized files now loaded: 0)
2193+
System memory in use before: 169.2 MB.
2194+
System memory in use after: 169.2 MB.
2195+
2196+
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2666.
2197+
Total: 2.833412 ms (FindLiveObjects: 0.362339 ms CreateObjectMapping: 0.077103 ms MarkObjects: 2.253779 ms DeleteObjects: 0.138391 ms)
2198+
2199+
========================================================================
2200+
Received Import Request.
2201+
Time since last request: 11.544332 seconds.
2202+
path: Assets/MyWebSocketServer.cs
2203+
artifactKey: Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b)
2204+
Start importing Assets/MyWebSocketServer.cs using Guid(5cae6cd5a80444e79b49b1b23e819bb0) Importer(815301076,1909f56bfc062723c751e8b465ee728b) -> (artifact id: 'f087be4315f257bc6c813ea2db02d357') in 0.004746 seconds
2205+
Import took 0.008162 seconds .
2206+
2207+
========================================================================
2208+
Received Prepare
2209+
Registering precompiled user dll's ...
2210+
Registered in 0.000971 seconds.
2211+
Begin MonoManager ReloadAssembly
2212+
Native extension for OSXStandalone target not found
2213+
Refreshing native plugins compatible for Editor in 0.39 ms, found 2 plugins.
2214+
Preloading 0 native plugins for Editor in 0.00 ms.
2215+
Mono: successfully reloaded assembly
2216+
- Completed reload, in 1.277 seconds
2217+
Platform modules already initialized, skipping
2218+
Refreshing native plugins compatible for Editor in 0.48 ms, found 2 plugins.
2219+
Preloading 0 native plugins for Editor in 0.00 ms.
2220+
Unloading 1807 Unused Serialized files (Serialized files now loaded: 0)
2221+
System memory in use before: 169.3 MB.
2222+
System memory in use after: 169.3 MB.
2223+
2224+
Unloading 12 unused Assets to reduce memory usage. Loaded Objects now: 2670.
2225+
Total: 2.702876 ms (FindLiveObjects: 0.293419 ms CreateObjectMapping: 0.073950 ms MarkObjects: 2.210569 ms DeleteObjects: 0.123410 ms)
2226+

0 commit comments

Comments
 (0)