public bool AssignClientAuthority(NetworkConnection conn)
{
if (!isServer)
{
if (LogFilter.logError)
{
Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
}
return(false);
}
if (!localPlayerAuthority)
{
if (LogFilter.logError)
{
Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
}
return(false);
}
if (m_ClientAuthorityOwner != null && conn != m_ClientAuthorityOwner)
{
if (LogFilter.logError)
{
Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
}
return(false);
}
if (conn == null)
{
if (LogFilter.logError)
{
Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
}
return(false);
}
m_ClientAuthorityOwner = conn;
m_ClientAuthorityOwner.AddOwnedObject(this);
// server no longer has authority (this is called on server). Note that local client could re-acquire authority below
ForceAuthority(false);
// send msg to that client
var msg = new ClientAuthorityMessage();
msg.netId = netId;
msg.authority = true;
conn.Send((short)MsgType.LocalClientAuthority, msg);
if (clientAuthorityCallback != null)
{
clientAuthorityCallback(conn, this, true);
}
return(true);
}