protected virtual void OnSceneUnloaded(Scene pScene) { NetworkSceneItem item = FindNetworkSceneItemInStaticScenes(pScene.name); bool isStaticScene = (item != null); if (!isStaticScene) { item = FindNetworkSceneItemInDynamicScenes(pScene.name); } if (item == null) { return; } if (_isServer && !isStaticScene && _enableRegisterDynamicScenes) { UnregisterDynamicScene(item.SceneTemplate.SceneName); } item.RaiseUnloaded(); if (isStaticScene) { _scenesStatic.Remove(pScene.name); } else { _usedDynamicPorts.Free(GetPortFromSetting(item.SceneTemplate.Settings)); _scenesDynamic.Remove(pScene.name); } }
protected virtual void ReadBinaryClient(NetworkingPlayer pPlayer, Binary pFrame, NetWorker pSender) { if (pFrame.GroupId == CustomMessageGroupIds.PLAYER_CHANGE_NETWORK_SCENE) { byte[] data = pFrame.StreamData.byteArr; RPCPlayerChangeNetworkScene changeSceneRPC = data.ByteArrayToObject <RPCPlayerChangeNetworkScene>(); NetworkSceneTemplate sceneTemplate = RPCPlayerChangeNetworkScene.ToNetworkSceneTemplate(changeSceneRPC); MainThreadManager.Run(() => { if (NodeManager.IsInitialized) { NodeManager.Instance.UnloadNetworkScenes(true, true); NodeManager.Instance.RaisePlayerChangingNetworkScene(sceneTemplate); NetworkSceneItem item = NodeManager.Instance.CreateNetworkScene(sceneTemplate, true); if (item == null) { NodeManager.Instance.PlayerChangingSceneFailed(item); return; } if (item.IsReady) { NodeManager.Instance.PlayerChangingSceneSucceeded(item); } else { item.OnReady += NodeManager.Instance.PlayerChangingSceneSucceeded; item.OnUnloaded += NodeManager.Instance.PlayerChangingSceneFailed; } } }); return; } }
protected virtual void RaisePendingSceneTimeout(int pIndex, NetworkSceneItem pItem) { if (OnPendingSceneTimeout != null) { OnPendingSceneTimeout(pIndex, pItem); } }
public virtual void RaisePlayerChangingNetworkSceneFailed(NetworkSceneItem pItem) { if (OnPlayerChangingNetworkSceneFailed != null) { OnPlayerChangingNetworkSceneFailed(pItem); } }
public virtual NetworkSceneItem CreateNetworkScene(NetworkSceneTemplate pSceneTemplate, bool pIsSceneStatic, byte[] pNetworkSceneMetaData = null) { ushort port = GetPortFromSetting(pSceneTemplate.Settings); if (!pIsSceneStatic && _usedDynamicPorts.Contains(port)) { return(null); } // Check if we already have created a scene with that name NetworkSceneTemplate existingScene = FindNetworkSceneTemplate(pSceneTemplate.SceneName, false, true, true, true); if (existingScene != null) { return(null); } // Create an empty Scene and put a new NetworkSceneManager in it NetworkSceneManager manager = CreateEmptyNetworkScene(pSceneTemplate); manager.NetworkSceneMetaData = pNetworkSceneMetaData; // Create the Scene with the 'BuildIndex' and queue it up to be merged with our empty Scene NetworkSceneItem newItem = new NetworkSceneItem(pSceneTemplate, manager); if (pSceneTemplate.BuildIndex > 0) { SceneManager.LoadScene(pSceneTemplate.BuildIndex, LoadSceneMode.Additive); _pendingScenes.Add(newItem); } else { newItem.IsCreated = true; } // Add the newItem to the respective collection if (pIsSceneStatic) { _scenesStatic.Add(pSceneTemplate.SceneName, newItem); } else { _usedDynamicPorts.Add(port); _scenesDynamic.Add(pSceneTemplate.SceneName, newItem); } // If the scene is 'dynamic' we need to register it so other Nodes know the scene is taken if (_isServer && !pIsSceneStatic && _enableRegisterDynamicScenes) { RegisterDynamicScene(_registerDynamicScenesRequireConfirmation, pSceneTemplate); newItem.IsRegistered = !_registerDynamicScenesRequireConfirmation; } else { newItem.IsRegistered = true; } ReadyNetworkScene(newItem); return(newItem); }
public virtual void PlayerChangingSceneFailed(NetworkSceneItem item = null) { if (item != null) { item.OnReady -= PlayerChangingSceneSucceeded; item.OnUnloaded -= PlayerChangingSceneFailed; } RaisePlayerChangingNetworkSceneFailed(item); }
public virtual NetworkSceneManager FindNetworkSceneManager(string pSceneName) { NetworkSceneItem item = FindNetworkSceneItem(pSceneName, true, true); if (item == null || !item.HasManager) { return(null); } return(item.Manager); }
public virtual NetworkBehavior InstantiateInScene(string pSceneName, int pCreateCode = -1, IRPCSerializable pBehaviorData = null, Vector3?pPosition = null, Quaternion?pRotation = null, bool pSendTransform = true) { NetworkSceneItem item = FindNetworkSceneItem(pSceneName, true, true); if (item == null || !item.HasManager) { return(null); } return(item.Manager.InstantiateNetworkBehavior(pCreateCode, pBehaviorData, pPosition, pRotation, pSendTransform)); }
public virtual bool TryGetNetworkSceneManager(string pSceneName, out NetworkSceneManager pNetworkSceneManager) { NetworkSceneItem item = FindNetworkSceneItem(pSceneName, true, true); if (item == null || !item.HasManager) { pNetworkSceneManager = null; return(false); } pNetworkSceneManager = item.Manager; return(true); }
public virtual void UnloadNetworkScene(NetworkSceneItem pItem) { if (pItem == null || !pItem.HasManager) { return; } if (pItem.IsCreated) { SceneManager.UnloadSceneAsync(pItem.Manager.gameObject.scene.name); } else { //The scene is still being created. If we mark it as "IsUnregistered" it will be deleted right after it has been instantiated. pItem.IsUnregistered = true; } }
public virtual NetworkSceneItem[] CreateNetworkScenes(NetworkSceneTemplate[] pSceneTemplates, bool pIsSceneStatic, byte[] pNetworkSceneMetaData = null) { List <NetworkSceneItem> items = new List <NetworkSceneItem>(); for (int i = 0; i < pSceneTemplates.Length; i++) { NetworkSceneItem item = CreateNetworkScene(pSceneTemplates[i], pIsSceneStatic, pNetworkSceneMetaData); if (item == null) { continue; } items.Add(item); } return(items.ToArray()); }
public virtual void ReadyNetworkScene(NetworkSceneItem pItem) { if (!pItem.IsCreated || !pItem.IsRegistered || pItem.IsUnregistered || pItem.IsReady) { return; } if (_isServer) { pItem.Manager.StartAsServer(); } else { pItem.Manager.StartAsClient(); } pItem.IsReady = true; pItem.RaiseReady(); }
protected virtual void ConfirmRegisterDynamicScene(ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> pCallback) { NetworkSceneItem item = FindNetworkSceneItemInDynamicScenes(pCallback.RequestDataOfT.sceneName); if (item == null) { return; } if (pCallback.ResponseDataOfT == ServiceCallbackStateEnum.RESPONSE_SUCCESS) { item.IsRegistered = true; item.RaiseRegistered(); ReadyNetworkScene(item); } else { item.IsUnregistered = true; item.RaiseUnregistered(); UnloadNetworkScene(item); } }
public virtual NetworkSceneItem FindNetworkSceneItem(string pSceneName, bool pSearchScenesStatic, bool pSearchScenesDynamic) { //check our static scenes if (pSearchScenesStatic) { NetworkSceneItem item = FindNetworkSceneItemInStaticScenes(pSceneName); if (item != null) { return(item); } } //check our dynamic scenes if (pSearchScenesDynamic) { NetworkSceneItem item = FindNetworkSceneItemInDynamicScenes(pSceneName); if (item != null) { return(item); } } return(null); }
public virtual void PlayerChangingSceneSucceeded(NetworkSceneItem item) { item.OnReady -= PlayerChangingSceneSucceeded; item.OnUnloaded -= PlayerChangingSceneFailed; RaisePlayerChangingNetworkSceneCompleted(item); }