我正在尝试根据播放器平台生成不同的预制件。因此,我将覆盖 NetworkLobbyManager 以按照我想要的方式生成对象。因此,我创建了一个将 connectionId 与预制件的索引相关联的字典,然后根据该索引实例化一个预制件。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class LobbyManager : NetworkLobbyManager
{
private Dictionary<int, int> m_currentPlayers;
void Start()
{
m_currentPlayers = new Dictionary<int, int>();
}
void AddPlayer(NetworkConnection conn)
{
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
{
m_currentPlayers.Add(conn.connectionId, 0);
}
else if (Application.platform == RuntimePlatform.Android)
{
m_currentPlayers.Add(conn.connectionId, 1);
}
}
public override GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId)
{
AddPlayer(conn);
return base.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
}
public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
{
GameObject go = Instantiate(spawnPrefabs[m_currentPlayers[conn.connectionId]]);
NetworkServer.AddPlayerForConnection(conn, go, playerControllerId);
return go;
}
}
但是使用此代码,客户端上的生成播放器始终与主机相同,我不知道为什么,因为我似乎覆盖了正确的功能,我在这里看到了http://abrgame.blogspot.fr/2016 /01/using-unet-to-spawn-different-player.html一个使用相同技术并且对他有用的人......