Pun2 未在 WebGL 中连接
Pun2 not connecting in WebGL
我在 Unity 2021.1.5f 中使用 PUN2 连接多人游戏。它适用于 Android、iOS 和 Windows。
当我为 WebGL 构建并尝试连接服务器时,出现下一个错误:
Connect() failed to create a IPhotonSocket instance for WebSocketSecure.SocketImplementationConfig:
{Udp=ExitGames.Client.Photon.SocketUdp, Tcp=ExitGames.Client.Photon.SocketTcp,
WebSocket=ExitGames.Client.Photon.SocketWebTcp,
WebSocketSecure=ExitGames.Client.Photon.SocketWebTcp}
Exception: System.MissingMethodException: Constructor on type
'ExitGames.Client.Photon.SocketWebTcp' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr,
System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture,
System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark)
[0x00000] in <00000000000000000000000000000000>:0
我刚接触 PUN2,不知道会发生什么。我使用网络套接字安全协议配置了我的 PhotonSettings。
我找到了答案:
Unity 中有一个选项可以削减代码以优化 Managed Stripping Level。我为 Low 更改了它并为我工作。
也把这个放在link.xml:
<assembly fullname="PhotonWebSocket">
<type fullname="ExitGames.Client.Photon.SocketWebTcp" preserve="all"/>
</assembly>
<assembly fullname="PhotonWebSocket">
<type fullname="ExitGames.Client.Photon.SocketWebSecure" preserve="all"/>
</assembly>
我在 Unity 2021.1.5f 中使用 PUN2 连接多人游戏。它适用于 Android、iOS 和 Windows。
当我为 WebGL 构建并尝试连接服务器时,出现下一个错误:
Connect() failed to create a IPhotonSocket instance for WebSocketSecure.SocketImplementationConfig:
{Udp=ExitGames.Client.Photon.SocketUdp, Tcp=ExitGames.Client.Photon.SocketTcp,
WebSocket=ExitGames.Client.Photon.SocketWebTcp,
WebSocketSecure=ExitGames.Client.Photon.SocketWebTcp}
Exception: System.MissingMethodException: Constructor on type
'ExitGames.Client.Photon.SocketWebTcp' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr,
System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture,
System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark)
[0x00000] in <00000000000000000000000000000000>:0
我刚接触 PUN2,不知道会发生什么。我使用网络套接字安全协议配置了我的 PhotonSettings。
我找到了答案:
Unity 中有一个选项可以削减代码以优化 Managed Stripping Level。我为 Low 更改了它并为我工作。
也把这个放在link.xml:
<assembly fullname="PhotonWebSocket">
<type fullname="ExitGames.Client.Photon.SocketWebTcp" preserve="all"/>
</assembly>
<assembly fullname="PhotonWebSocket">
<type fullname="ExitGames.Client.Photon.SocketWebSecure" preserve="all"/>
</assembly>