Ejemplo n.º 1
0
    /// <summary>
    /// Runs only the client side.
    /// The Server requests that a certain scene to be loaded, and the client replies with Response
    /// confirming the scene load.
    /// </summary>
    public override void OnEvent(LoadSceneRequest evnt)
    {
        if (BoltNetwork.IsClient)
        {
            if (evnt.Load)
            {
                if (loadedScenes.Contains(evnt.SceneName) == false)
                {
                    SceneManager.LoadSceneAsync(evnt.SceneName, LoadSceneMode.Additive);
                    loadedScenes.Add(evnt.SceneName);
                }
            }
            else
            {
                SceneManager.UnloadSceneAsync(evnt.SceneName);
                loadedScenes.Remove(evnt.SceneName);
            }

            var evt = LoadSceneResponse.Create(Bolt.GlobalTargets.OnlyServer);
            evt.SceneName = evnt.SceneName;
            evt.Load      = evnt.Load;
            evt.Send();
        }
    }