public void Stop() { this.gameClient.ClientReceivedMessage -= this.ClientReceivedMessage; this.gameClient.ClientConnectedToServer -= this.ClientConnected; this.gameClient.ClientDisconnectedFromServer -= this.ClientDisconnected; this.sceneNetworkObjectsList.Clear(); this.sceneNetworkObjectsHash.Clear(); if (Platform.IsApplicationQuitting == false) { // Destroy all dynamic objects foreach (var dynamic in this.dynamicNetworkObjectsList) { if (dynamic && dynamic.gameObject) { Pooler.Destroy(dynamic.gameObject); } } this.dynamicNetworkObjectsList.Clear(); this.dynamicNetworkObjectsHash.Clear(); } SceneManager.sceneLoaded -= this.OnSceneLoaded; }
protected override void OnDestroy() { //obliterate pooler if (_pooler != null) { _pooler.Destroy(); _pooler = null; } //unload ball AssetService.UnloadAsset(_ballPrefab.name, true); }
public void StopService(ServiceLocator application) { if (poller != null) { poller.Destroy(); } serviceStopped.OnNext(this); serviceConfigured.Dispose(); serviceStarted.Dispose(); serviceStopped.Dispose(); }
public void ClientReceivedMessage(Message message) { switch (message.GetId()) { case NetworkIdentityUpdate.Id: { var networkIdentityUpdatedMessage = (NetworkIdentityUpdate)message; if (this.sceneNetworkObjectsHash.TryGetValue(networkIdentityUpdatedMessage.NetworkId, out NetworkIdentity sceneIdentity)) { if (sceneIdentity) { networkIdentityUpdatedMessage.PopulateNetworkIdentity(sceneIdentity, false); } else { Debug.LogError($"Scene NetworkIdentity {networkIdentityUpdatedMessage.NetworkId} has been destoryed, but still getting updates."); } } else if (this.dynamicNetworkObjectsHash.TryGetValue(networkIdentityUpdatedMessage.NetworkId, out NetworkIdentity dynamicIdentity)) { networkIdentityUpdatedMessage.PopulateNetworkIdentity(dynamicIdentity, false); } else { if (string.IsNullOrEmpty(networkIdentityUpdatedMessage.ResourceName) == false) { var newIdentity = this.CreateDynamicNetworkIdentity( networkIdentityUpdatedMessage.ResourceName, networkIdentityUpdatedMessage.NetworkId, networkIdentityUpdatedMessage.OwnerId, networkIdentityUpdatedMessage.Position, networkIdentityUpdatedMessage.Rotation); networkIdentityUpdatedMessage.PopulateNetworkIdentity(newIdentity, true); } } break; } case NetworkBehaviourMessage.Id: { var networkBehaviourMessage = (NetworkBehaviourMessage)message; NetworkIdentity identity = this.GetNetworkIdentity(networkBehaviourMessage.NetworkId); if (identity && identity.IsOwner == false) { Reader.Replace(networkBehaviourMessage.DataBytes); identity.Behaviours[networkBehaviourMessage.BehaviourIndex].Deserialize(Reader); } break; } case NetworkBehaviourDataMessage.Id: { var networkBehaviourDataMessage = (NetworkBehaviourDataMessage)message; NetworkIdentity identity = this.GetNetworkIdentity(networkBehaviourDataMessage.NetworkId); if (identity) { identity.Behaviours[networkBehaviourDataMessage.BehaviourIndex].OnReceiveNetworkData(networkBehaviourDataMessage.DataKey, networkBehaviourDataMessage.DataValue); } break; } case NetworkIdentitiesDestroyed.Id: { var networkIdentitiesDestoryed = (NetworkIdentitiesDestroyed)message; foreach (long networkId in networkIdentitiesDestoryed.DestroyedNetworkIds) { NetworkIdentity identity = this.GetNetworkIdentity(networkId); if (identity) { Pooler.Destroy(identity.gameObject); } } break; } } }