Unreliable
How do I use Unreliable
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonConverter.cs
Copy
351 static int ConvertNetworkView(NetworkView[] netViews, bool isScene)
352 {
353 for (int i = netViews.Length - 1; i >= 0; i--)
354 {
355 NetworkView netView = netViews[i];
356 PhotonView view = netView.gameObject.AddComponent
357 if (isScene)
358 {
359 //Get scene ID
360 string str = netView.viewID.ToString().Replace("SceneID: ", "");
361 int firstSpace = str.IndexOf(" ");
362 str = str.Substring(0, firstSpace);
363 int oldViewID = int.Parse(str);
364
365 view.viewID = oldViewID;
366 EditorUtility.SetDirty(view);
367 EditorUtility.SetDirty(view.gameObject);
368 }
369 view.observed = netView.observed;
370 if (netView.stateSynchronization == NetworkStateSynchronization.Unreliable)
371 {
372 view.synchronization = ViewSynchronization.Unreliable;
373 }
374 else if (netView.stateSynchronization == NetworkStateSynchronization.ReliableDeltaCompressed)
375 {
376 view.synchronization = ViewSynchronization.ReliableDeltaCompressed;
377 }
378 else
379 {
380 view.synchronization = ViewSynchronization.Off;
381 }
382 DestroyImmediate(netView, true);
383 }
384 AssetDatabase.Refresh();
385 AssetDatabase.SaveAssets();
386
387 return netViews.Length;
388 }
File name: PhotonViewInspector.cs
Copy
209 void DrawOldObservedItem()
210 {
211 EditorGUILayout.BeginHorizontal();
212
213 // Using a lower version then 3.4? Remove the TRUE in the next line to fix an compile error
214 string typeOfObserved = string.Empty;
215 if( m_Target.observed != null )
216 {
217 int firstBracketPos = m_Target.observed.ToString().LastIndexOf( '(' );
218 if( firstBracketPos > 0 )
219 {
220 typeOfObserved = m_Target.observed.ToString().Substring( firstBracketPos );
221 }
222 }
223
224
225 Component componenValue = (Component)EditorGUILayout.ObjectField( "Observe: " + typeOfObserved, m_Target.observed, typeof( Component ), true );
226 if( m_Target.observed != componenValue )
227 {
228 if( m_Target.observed == null )
229 {
230 m_Target.synchronization = ViewSynchronization.UnreliableOnChange; // if we didn't observe anything yet. use unreliable on change as default
231 }
232 if( componenValue == null )
233 {
234 m_Target.synchronization = ViewSynchronization.Off;
235 }
236
237 m_Target.observed = componenValue;
238 }
239
240 EditorGUILayout.EndHorizontal();
241 }
File name: PhotonViewInspector.cs
Copy
258 void DrawObservedComponentsList()
259 {
260 GUILayout.Space( 5 );
261 SerializedProperty listProperty = serializedObject.FindProperty( "ObservedComponents" );
262
263 if( listProperty == null )
264 {
265 return;
266 }
267
268 float containerElementHeight = 22;
269 float containerHeight = listProperty.arraySize * containerElementHeight;
270
271 bool isOpen = PhotonGUI.ContainerHeaderFoldout( "Observed Components (" + GetObservedComponentsCount() + ")", serializedObject.FindProperty( "ObservedComponentsFoldoutOpen" ).boolValue );
272 serializedObject.FindProperty( "ObservedComponentsFoldoutOpen" ).boolValue = isOpen;
273
274 if( isOpen == false )
275 {
276 containerHeight = 0;
277 }
278
279 //Texture2D statsIcon = AssetDatabase.LoadAssetAtPath( "Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonViewStats.png", typeof( Texture2D ) ) as Texture2D;
280
281 Rect containerRect = PhotonGUI.ContainerBody( containerHeight );
282 bool wasObservedComponentsEmpty = m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0;
283 if( isOpen == true )
284 {
285 for( int i = 0; i < listProperty.arraySize; ++i )
286 {
287 Rect elementRect = new Rect( containerRect.xMin, containerRect.yMin + containerElementHeight * i, containerRect.width, containerElementHeight );
288 {
289 Rect texturePosition = new Rect( elementRect.xMin + 6, elementRect.yMin + elementRect.height / 2f - 1, 9, 5 );
290 ReorderableListResources.DrawTexture( texturePosition, ReorderableListResources.texGrabHandle );
291
292 Rect propertyPosition = new Rect( elementRect.xMin + 20, elementRect.yMin + 3, elementRect.width - 45, 16 );
293 EditorGUI.PropertyField( propertyPosition, listProperty.GetArrayElementAtIndex( i ), new GUIContent() );
294
295 //Debug.Log( listProperty.GetArrayElementAtIndex( i ).objectReferenceValue.GetType() );
296 //Rect statsPosition = new Rect( propertyPosition.xMax + 7, propertyPosition.yMin, statsIcon.width, statsIcon.height );
297 //ReorderableListResources.DrawTexture( statsPosition, statsIcon );
298
299 Rect removeButtonRect = new Rect( elementRect.xMax - PhotonGUI.DefaultRemoveButtonStyle.fixedWidth,
300 elementRect.yMin + 2,
301 PhotonGUI.DefaultRemoveButtonStyle.fixedWidth,
302 PhotonGUI.DefaultRemoveButtonStyle.fixedHeight );
303
304 GUI.enabled = listProperty.arraySize > 1;
305 if( GUI.Button( removeButtonRect, new GUIContent( ReorderableListResources.texRemoveButton ), PhotonGUI.DefaultRemoveButtonStyle ) )
306 {
307 listProperty.DeleteArrayElementAtIndex( i );
308 }
309 GUI.enabled = true;
310
311 if( i < listProperty.arraySize - 1 )
312 {
313 texturePosition = new Rect( elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1 );
314 PhotonGUI.DrawSplitter( texturePosition );
315 }
316 }
317 }
318 }
319
320 if( PhotonGUI.AddButton() )
321 {
322 listProperty.InsertArrayElementAtIndex( Mathf.Max( 0, listProperty.arraySize - 1 ) );
323 }
324
325 serializedObject.ApplyModifiedProperties();
326
327 bool isObservedComponentsEmpty = m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0;
328
329 if( wasObservedComponentsEmpty == true && isObservedComponentsEmpty == false && m_Target.synchronization == ViewSynchronization.Off )
330 {
331 m_Target.synchronization = ViewSynchronization.UnreliableOnChange;
332 EditorUtility.SetDirty( m_Target );
333 serializedObject.Update();
334 }
335
336 if( wasObservedComponentsEmpty == false && isObservedComponentsEmpty == true )
337 {
338 m_Target.synchronization = ViewSynchronization.Off;
339 EditorUtility.SetDirty( m_Target );
340 serializedObject.Update();
341 }
342
343 }
File name: NetworkingPeer.cs
Copy
144 private readonly Dictionary145 private readonly Dictionary
152 internal protected ServerConnection server { get; private set; }
File name: NetworkingPeer.cs
Copy
185 public NetworkingPeer(IPhotonPeerListener listener, string playername, ConnectionProtocol connectionProtocol) : base(listener, connectionProtocol)
186 {
187 #if !UNITY_EDITOR && (UNITY_WINRT)
188 // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
189 Debug.LogWarning("Using PingWindowsStore");
190 PhotonHandler.PingImplementation = typeof(PingWindowsStore); // but for ping, we have to set the implementation explicitly to Win 8 Store/Phone
191 #endif
192
193 #pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
194 if (PhotonPeer.NoSocket)
195 {
196 #if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
197 Debug.Log("Using class SocketUdpNativeDynamic");
198 this.SocketImplementation = typeof(SocketUdpNativeDynamic);
199 PhotonHandler.PingImplementation = typeof(PingNativeDynamic);
200 #elif !UNITY_EDITOR && UNITY_IPHONE
201 Debug.Log("Using class SocketUdpNativeStatic");
202 this.SocketImplementation = typeof(SocketUdpNativeStatic);
203 PhotonHandler.PingImplementation = typeof(PingNativeStatic);
204 #elif !UNITY_EDITOR && (UNITY_WINRT)
205 // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
206 #else
207 this.SocketImplementation = typeof (SocketUdp);
208 PhotonHandler.PingImplementation = typeof(PingMonoEditor);
209 #endif
210
211 if (this.SocketImplementation == null)
212 {
213 Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
214 }
215 }
216 #pragma warning restore 0162
217
218 if (PhotonHandler.PingImplementation == null)
219 {
220 PhotonHandler.PingImplementation = typeof(PingMono);
221 }
222
223 this.Listener = this;
224 this.lobby = TypedLobby.Default;
225 this.LimitOfUnreliableCommands = 40;
226
227 // don't set the field directly! the listener is passed on to other classes, which get updated by the property set method
228 this.externalListener = listener;
229 this.PlayerName = playername;
230 this.mLocalActor = new PhotonPlayer(true, -1, this.playername);
231 this.AddNewPlayer(this.mLocalActor.ID, this.mLocalActor);
232
233 // RPC shortcut lookup creation (from list of RPCs, which is updated by Editor scripts)
234 rpcShortcuts = new Dictionary
235 for (int index = 0; index < PhotonNetwork.PhotonServerSettings.RpcList.Count; index++)
236 {
237 var name = PhotonNetwork.PhotonServerSettings.RpcList[index];
238 rpcShortcuts[name] = index;
239 }
240
241 this.State = global::PeerState.PeerCreated;
242 }
File name: NetworkingPeer.cs
Copy
1411 public void OnStatusChanged(StatusCode statusCode)
1412 {
1413 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1414 Debug.Log(string.Format("OnStatusChanged: {0}", statusCode.ToString()));
1415
1416 switch (statusCode)
1417 {
1418 case StatusCode.Connect:
1419 if (this.State == global::PeerState.ConnectingToNameServer)
1420 {
1421 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1422 Debug.Log("Connected to NameServer.");
1423
1424 this.server = ServerConnection.NameServer;
1425 if (this.CustomAuthenticationValues != null)
1426 {
1427 this.CustomAuthenticationValues.Secret = null; // when connecting to NameServer, invalidate any auth values
1428 }
1429 }
1430
1431 if (this.State == global::PeerState.ConnectingToGameserver)
1432 {
1433 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1434 Debug.Log("Connected to gameserver.");
1435
1436 this.server = ServerConnection.GameServer;
1437 this.State = global::PeerState.ConnectedToGameserver;
1438 }
1439
1440 if (this.State == global::PeerState.ConnectingToMasterserver)
1441 {
1442 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1443 Debug.Log("Connected to masterserver.");
1444
1445 this.server = ServerConnection.MasterServer;
1446 this.State = global::PeerState.ConnectedToMaster;
1447
1448 if (this.IsInitialConnect)
1449 {
1450 this.IsInitialConnect = false; // after handling potential initial-connect issues with special messages, we are now sure we can reach a server
1451 SendMonoMessage(PhotonNetworkingMessage.OnConnectedToPhoton);
1452 }
1453 }
1454
1455 this.EstablishEncryption(); // always enable encryption
1456
1457 if (this.IsAuthorizeSecretAvailable)
1458 {
1459 // if we have a token we don't have to wait for encryption (it is encrypted anyways, so encryption is just optional later on)
1460 this.didAuthenticate = this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, this.CloudRegion.ToString());
1461 if (this.didAuthenticate)
1462 {
1463 this.State = global::PeerState.Authenticating;
1464 }
1465 }
1466 break;
1467
1468 case StatusCode.EncryptionEstablished:
1469 // on nameserver, the "process" is stopped here, so the developer/game can either get regions or authenticate with a specific region
1470 if (this.server == ServerConnection.NameServer)
1471 {
1472 this.State = global::PeerState.ConnectedToNameServer;
1473
1474 if (!this.didAuthenticate && this.CloudRegion == CloudRegionCode.none)
1475 {
1476 // this client is not setup to connect to a default region. find out which regions there are!
1477 this.OpGetRegions(this.mAppId);
1478 }
1479 }
1480
1481 // we might need to authenticate automatically now, so the client can do anything at all
1482 if (!this.didAuthenticate && (!this.IsUsingNameServer || this.CloudRegion != CloudRegionCode.none))
1483 {
1484 // once encryption is availble, the client should send one (secure) authenticate. it includes the AppId (which identifies your app on the Photon Cloud)
1485 this.didAuthenticate = this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, this.CloudRegion.ToString());
1486 if (this.didAuthenticate)
1487 {
1488 this.State = global::PeerState.Authenticating;
1489 }
1490 }
1491 break;
1492
1493 case StatusCode.EncryptionFailedToEstablish:
1494 Debug.LogError("Encryption wasn't established: " + statusCode + ". Going to authenticate anyways.");
1495 this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, this.CloudRegion.ToString()); // TODO: check if there are alternatives
1496 break;
1497
1498 case StatusCode.Disconnect:
1499 this.didAuthenticate = false;
1500 this.isFetchingFriends = false;
1501 if (server == ServerConnection.GameServer) this.LeftRoomCleanup();
1502 if (server == ServerConnection.MasterServer) this.LeftLobbyCleanup();
1503
1504 if (this.State == global::PeerState.DisconnectingFromMasterserver)
1505 {
1506 if (this.Connect(this.mGameserver, ServerConnection.GameServer))
1507 {
1508 this.State = global::PeerState.ConnectingToGameserver;
1509 }
1510 }
1511 else if (this.State == global::PeerState.DisconnectingFromGameserver || this.State == global::PeerState.DisconnectingFromNameServer)
1512 {
1513 if (this.Connect(this.MasterServerAddress, ServerConnection.MasterServer))
1514 {
1515 this.State = global::PeerState.ConnectingToMasterserver;
1516 }
1517 }
1518 else
1519 {
1520 if (this.CustomAuthenticationValues != null)
1521 {
1522 this.CustomAuthenticationValues.Secret = null; // invalidate any custom auth secrets
1523 }
1524
1525 this.State = global::PeerState.PeerCreated; // if we set another state here, we could keep clients from connecting in OnDisconnectedFromPhoton right here.
1526 SendMonoMessage(PhotonNetworkingMessage.OnDisconnectedFromPhoton);
1527 }
1528 break;
1529
1530 case StatusCode.SecurityExceptionOnConnect:
1531 case StatusCode.ExceptionOnConnect:
1532 this.State = global::PeerState.PeerCreated;
1533 if (this.CustomAuthenticationValues != null)
1534 {
1535 this.CustomAuthenticationValues.Secret = null; // invalidate any custom auth secrets
1536 }
1537
1538 DisconnectCause cause = (DisconnectCause)statusCode;
1539 SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, cause);
1540 break;
1541
1542 case StatusCode.Exception:
1543 if (this.IsInitialConnect)
1544 {
1545 Debug.LogError("Exception while connecting to: " + this.ServerAddress + ". Check if the server is available.");
1546 if (this.ServerAddress == null || this.ServerAddress.StartsWith("127.0.0.1"))
1547 {
1548 Debug.LogWarning("The server address is 127.0.0.1 (localhost): Make sure the server is running on this machine. Android and iOS emulators have their own localhost.");
1549 if (this.ServerAddress == this.mGameserver)
1550 {
1551 Debug.LogWarning("This might be a misconfiguration in the game server config. You need to edit it to a (public) address.");
1552 }
1553 }
1554
1555 this.State = global::PeerState.PeerCreated;
1556 cause = (DisconnectCause)statusCode;
1557 SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, cause);
1558 }
1559 else
1560 {
1561 this.State = global::PeerState.PeerCreated;
1562
1563 cause = (DisconnectCause)statusCode;
1564 SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, cause);
1565 }
1566
1567 this.Disconnect();
1568 break;
1569
1570 case StatusCode.TimeoutDisconnect:
1571 case StatusCode.ExceptionOnReceive:
1572 case StatusCode.DisconnectByServer:
1573 case StatusCode.DisconnectByServerLogic:
1574 case StatusCode.DisconnectByServerUserLimit:
1575 if (this.IsInitialConnect)
1576 {
1577 Debug.LogWarning(statusCode + " while connecting to: " + this.ServerAddress + ". Check if the server is available.");
1578
1579 cause = (DisconnectCause)statusCode;
1580 SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, cause);
1581 }
1582 else
1583 {
1584 cause = (DisconnectCause)statusCode;
1585 SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, cause);
1586 }
1587 if (this.CustomAuthenticationValues != null)
1588 {
1589 this.CustomAuthenticationValues.Secret = null; // invalidate any custom auth secrets
1590 }
1591
1592 this.Disconnect();
1593 break;
1594
1595 case StatusCode.SendError:
1596 // this.mListener.clientErrorReturn(statusCode);
1597 break;
1598
1599 case StatusCode.QueueOutgoingReliableWarning:
1600 case StatusCode.QueueOutgoingUnreliableWarning:
1601 case StatusCode.QueueOutgoingAcksWarning:
1602 case StatusCode.QueueSentWarning:
1603 // this.mListener.warningReturn(statusCode);
1604 break;
1605
1606 case StatusCode.QueueIncomingReliableWarning:
1607 case StatusCode.QueueIncomingUnreliableWarning:
1608 Debug.Log(statusCode + ". This client buffers many incoming messages. This is OK temporarily. With lots of these warnings, check if you send too much or execute messages too slow. " + (PhotonNetwork.isMessageQueueRunning? "":"Your isMessageQueueRunning is false. This can cause the issue temporarily.") );
1609 break;
1610
1611 // // TCP "routing" is an option of Photon that's not currently needed (or supported) by PUN
1612 //case StatusCode.TcpRouterResponseOk:
1613 // break;
1614 //case StatusCode.TcpRouterResponseEndpointUnknown:
1615 //case StatusCode.TcpRouterResponseNodeIdUnknown:
1616 //case StatusCode.TcpRouterResponseNodeNotReady:
1617
1618 // this.DebugReturn(DebugLevel.ERROR, "Unexpected router response: " + statusCode);
1619 // break;
1620
1621 default:
1622
1623 // this.mListener.serverErrorReturn(statusCode.value());
1624 Debug.LogError("Received unknown status code: " + statusCode);
1625 break;
1626 }
1627
1628 this.externalListener.OnStatusChanged(statusCode);
1629 }
File name: NetworkingPeer.cs
Copy
3147 public void RunViewUpdate()
3148 {
3149 if (!PhotonNetwork.connected || PhotonNetwork.offlineMode)
3150 {
3151 return;
3152 }
3153
3154 if (this.mActors == null ||
3155#if !PHOTON_DEVELOP
3156 this.mActors.Count <= 1
3157#endif
3158 )
3159 {
3160 return; // No need to send OnSerialize messages (these are never buffered anyway)
3161 }
3162
3163 dataPerGroupReliable.Clear();
3164 dataPerGroupUnreliable.Clear();
3165
3166 /* Format of the data hashtable:
3167 * Hasthable dataPergroup*
3168 * [(byte)0] = this.ServerTimeInMilliSeconds;
3169 * OPTIONAL: [(byte)1] = currentLevelPrefix;
3170 * + data
3171 */
3172
3173 foreach (KeyValuePair
3174 {
3175 PhotonView view = kvp.Value;
3176
3177 if (view.synchronization != ViewSynchronization.Off)
3178 {
3179 // Fetch all sending photonViews
3180 if (view.isMine)
3181 {
3182 #if UNITY_2_6_1 || UNITY_2_6 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3183 if (!view.gameObject.active)
3184 {
3185 continue; // Only on actives
3186 }
3187 #else
3188 if (!view.gameObject.activeInHierarchy)
3189 {
3190 continue; // Only on actives
3191 }
3192 #endif
3193
3194 if (this.blockSendingGroups.Contains(view.group))
3195 {
3196 continue; // Block sending on this group
3197 }
3198
3199 // Run it trough its OnSerialize
3200 Hashtable evData = this.OnSerializeWrite(view);
3201 if (evData == null)
3202 {
3203 continue;
3204 }
3205
3206 if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed || view.mixedModeIsReliable)
3207 {
3208 if (!evData.ContainsKey((byte)1) && !evData.ContainsKey((byte)2))
3209 {
3210 // Everything has been removed by compression, nothing to send
3211 }
3212 else
3213 {
3214 if (!dataPerGroupReliable.ContainsKey(view.group))
3215 {
3216 dataPerGroupReliable[view.group] = new Hashtable();
3217 dataPerGroupReliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3218 if (currentLevelPrefix >= 0)
3219 {
3220 dataPerGroupReliable[view.group][(byte)1] = this.currentLevelPrefix;
3221 }
3222 }
3223 Hashtable groupHashtable = dataPerGroupReliable[view.group];
3224 groupHashtable.Add((short)groupHashtable.Count, evData);
3225 }
3226 }
3227 else
3228 {
3229 if (!dataPerGroupUnreliable.ContainsKey(view.group))
3230 {
3231 dataPerGroupUnreliable[view.group] = new Hashtable();
3232 dataPerGroupUnreliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3233 if (currentLevelPrefix >= 0)
3234 {
3235 dataPerGroupUnreliable[view.group][(byte)1] = this.currentLevelPrefix;
3236 }
3237 }
3238 Hashtable groupHashtable = dataPerGroupUnreliable[view.group];
3239 groupHashtable.Add((short)groupHashtable.Count, evData);
3240 }
3241 }
3242 else
3243 {
3244 // Debug.Log(" NO OBS on " + view.name + " " + view.owner);
3245 }
3246 }
3247 else
3248 {
3249 }
3250 }
3251
3252 //Send the messages: every group is send in it's own message and unreliable and reliable are split as well
3253 RaiseEventOptions options = new RaiseEventOptions();
3254
3255#if PHOTON_DEVELOP
3256 options.Receivers = ReceiverGroup.All;
3257#endif
3258
3259 foreach (KeyValuePair
3260 {
3261 options.InterestGroup = (byte)kvp.Key;
3262 this.OpRaiseEvent(PunEvent.SendSerializeReliable, kvp.Value, true, options);
3263 }
3264 foreach (KeyValuePair
3265 {
3266 options.InterestGroup = (byte)kvp.Key;
3267 this.OpRaiseEvent(PunEvent.SendSerialize, kvp.Value, false, options);
3268 }
3269 }
File name: NetworkingPeer.cs
Copy
3271 // calls OnPhotonSerializeView (through ExecuteOnSerialize)
3273 private Hashtable OnSerializeWrite(PhotonView view)
3274 {
3275 PhotonStream pStream = new PhotonStream( true, null );
3276 PhotonMessageInfo info = new PhotonMessageInfo( this.mLocalActor, this.ServerTimeInMilliSeconds, view );
3277
3278 // each view creates a list of values that should be sent
3279 view.SerializeView( pStream, info );
3280
3281 if( pStream.Count == 0 )
3282 {
3283 return null;
3284 }
3285
3286 object[] dataArray = pStream.data.ToArray();
3287
3288 if (view.synchronization == ViewSynchronization.UnreliableOnChange)
3289 {
3290 if (AlmostEquals(dataArray, view.lastOnSerializeDataSent))
3291 {
3292 if (view.mixedModeIsReliable)
3293 {
3294 return null;
3295 }
3296
3297 view.mixedModeIsReliable = true;
3298 view.lastOnSerializeDataSent = dataArray;
3299 }
3300 else
3301 {
3302 view.mixedModeIsReliable = false;
3303 view.lastOnSerializeDataSent = dataArray;
3304 }
3305 }
3306
3307 // EVDATA:
3308 // 0=View ID (an int, never compressed cause it's not in the data)
3309 // 1=data of observed type (different per type of observed object)
3310 // 2=compressed data (in this case, key 1 is empty)
3311 // 3=list of values that are actually null (if something was changed but actually IS null)
3312 Hashtable evData = new Hashtable();
3313 evData[(byte)0] = (int)view.viewID;
3314 evData[(byte)1] = dataArray; // this is the actual data (script or observed object)
3315
3316
3317 if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
3318 {
3319 // compress content of data set (by comparing to view.lastOnSerializeDataSent)
3320 // the "original" dataArray is NOT modified by DeltaCompressionWrite
3321 // if something was compressed, the evData key 2 and 3 are used (see above)
3322 bool somethingLeftToSend = this.DeltaCompressionWrite(view, evData);
3323
3324 // buffer the full data set (for next compression)
3325 view.lastOnSerializeDataSent = dataArray;
3326
3327 if (!somethingLeftToSend)
3328 {
3329 return null;
3330 }
3331 }
3332
3333 return evData;
3334 }
File name: PhotonNetwork.cs
Copy
730 /// Used once per dispatch to limit unreliable commands per channel (so after a pause, many channels can still cause a lot of unreliable commands)
733 {
734 get
735 {
736 return networkingPeer.LimitOfUnreliableCommands;
737 }
738
739 set
740 {
741 networkingPeer.LimitOfUnreliableCommands = value;
742 }
743 }
File name: PhotonNetwork.cs
Copy
1025 /// Connect(serverAddress, 1036 public static void SwitchToProtocol(ConnectionProtocol cp)
1037 {
1038 if (networkingPeer.UsedProtocol == cp)
1039 {
1040 return;
1041 }
1042 try
1043 {
1044 networkingPeer.Disconnect();
1045 networkingPeer.StopThread();
1046 }
1047 catch
1048 {
1049
1050 }
1051
1052 // set up a new NetworkingPeer
1053 NetworkingPeer newPeer = new NetworkingPeer(photonMono, String.Empty, cp);
1054 newPeer.mAppVersion = networkingPeer.mAppVersion;
1055 newPeer.CustomAuthenticationValues = networkingPeer.CustomAuthenticationValues;
1056 newPeer.PlayerName= networkingPeer.PlayerName;
1057 newPeer.mLocalActor = networkingPeer.mLocalActor;
1058 newPeer.DebugOut = networkingPeer.DebugOut;
1059 newPeer.CrcEnabled = networkingPeer.CrcEnabled;
1060 newPeer.lobby = networkingPeer.lobby;
1061 newPeer.LimitOfUnreliableCommands = networkingPeer.LimitOfUnreliableCommands;
1062 newPeer.SentCountAllowance = networkingPeer.SentCountAllowance;
1063 newPeer.TrafficStatsEnabled = networkingPeer.TrafficStatsEnabled;
1064
1065 networkingPeer = newPeer;
1066 Debug.LogWarning("Protocol switched to: " + cp + ".");
1067 }
Unreliable 137 lượt xem
Gõ tìm kiếm nhanh...