[英]Unity Mirror - How To Perform Individual Scene Traveling?
I'm a little stuck on what to do here.我有点坚持在这里做什么。 I haven't gotten any help from the discord server so I'm turning here in hopes someone has some insight for me.我没有从 discord 服务器获得任何帮助,所以我转向这里希望有人对我有一些见解。
Background:背景:
Here is what I'm trying to accomplish.这是我想要完成的。 I want to have a server+client
host (using Unity Mirror) but allow all clients to travel back and forth between scenes separately.我想要一个server+client
主机(使用 Unity Mirror),但允许所有客户端分别在场景之间来回移动。 The concept seems simple enough but I haven't found a good solution yet.这个概念似乎很简单,但我还没有找到一个好的解决方案。 Please note that I have server reconciliation setup for player movement.请注意,我为玩家移动设置了服务器协调设置。
What I Have Tried:我试过的:
Every time a client wants to travel to a new scene he sends a request to the server.每次客户端想要前往一个新场景时,他都会向服务器发送一个请求。 The server will additively load the scene and send an RPC back to the client who will also additively load the scene.服务器将附加加载场景并将 RPC 发送回客户端,客户端也将附加加载场景。 Then the scene has been successfully loaded, either by the client or the server it will call the MoveObjects command (on the SceneManager) to move the player character to the new scene.然后场景已经成功加载,无论是客户端还是服务器都会调用 MoveObjects 命令(在 SceneManager 上)将玩家角色移动到新场景。 So that means that reconcilation should* still be okay.所以这意味着和解应该*仍然可以。 If you're not the server then unload the old scene.如果您不是服务器,则卸载旧场景。 If you're the server keep all scenes additively loaded when there are still clients in that scene.如果您是服务器,则在该场景中仍有客户端时保持所有场景的附加加载。
The only issue with my above approach is that I can't disable/hide scenes on the server (or at least I don't know how to do that yet).我上述方法的唯一问题是我无法在服务器上禁用/隐藏场景(或者至少我还不知道该怎么做)。
My Request我的请求
Is this the best approach?这是最好的方法吗? Are there free code examples I could look at?有我可以查看的免费代码示例吗? Tutorials that might explain a better approach?可能解释更好方法的教程? Has anyone else done this with a better method?有没有其他人用更好的方法做到这一点? I would really appreciate any help I could get on this.我非常感谢我能得到的任何帮助。
Final Thoughts最后的想法
The last thing I thought about what dynamically starting a new server and connecting to the new server for every new unity scene to separate players that way.我想到的最后一件事是动态启动新服务器并为每个新的统一场景连接到新服务器,从而以这种方式分隔玩家。 The only problem with this approach is it breaks cross scene communication.这种方法的唯一问题是它破坏了跨场景通信。 Like if I wanted to display the scene the player was in and their current health to all players in a party across multiple scenes.就像我想在多个场景中向派对中的所有玩家展示玩家所在的场景以及他们当前的健康状况一样。
This is somewhat complicated.这有点复杂。 However, I was able to achieve it like the following:但是,我能够像下面这样实现它:
NetworkClient.Send(new ClientRequestLoadScene() { sceneName = sceneName, travelPoint = travelPoint });
conn.Send(new SceneMessage() { sceneName = msg.sceneName, sceneOperation = SceneOperation.LoadAdditive });
SceneManager.MoveGameObjectToScene(character, SceneManager.GetSceneByName(GetCleanedSceneName(msg.sceneName)));
NetworkSceneChecker
to have visibility only when you're in that particular scene包括NetworkSceneChecker
以仅在您处于该特定场景时才可见PhysicsSimulator
component if you have the scene loaded with 3d physics. (可选)如果您的场景加载了 3d 物理,则包括PhysicsSimulator
组件。Now this doesn't give every tiny little detail on how to do this but this is a good starting point to understand how you might be able to accomplish this.现在这并没有给出关于如何做到这一点的每一个微小的细节,但这是一个很好的起点,可以帮助您了解如何实现这一点。 The big take aways are the following:主要的收获如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.