mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkIdentity: AssignClientAuthority moved above RemoveClientAuthority
This commit is contained in:
parent
508e253bb1
commit
65645dd266
@ -1096,6 +1096,44 @@ public void RebuildObservers(bool initialize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Assign control of an object to a client via the client's <see cref="NetworkConnection">NetworkConnection.</see>
|
||||||
|
/// <para>This causes hasAuthority to be set on the client that owns the object, and NetworkBehaviour.OnStartAuthority will be called on that client. This object then will be in the NetworkConnection.clientOwnedObjects list for the connection.</para>
|
||||||
|
/// <para>Authority can be removed with RemoveClientAuthority. Only one client can own an object at any time. This does not need to be called for player objects, as their authority is setup automatically.</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="conn"> The connection of the client to assign authority to.</param>
|
||||||
|
/// <returns>True if authority was assigned.</returns>
|
||||||
|
public bool AssignClientAuthority(NetworkConnection conn)
|
||||||
|
{
|
||||||
|
if (!isServer)
|
||||||
|
{
|
||||||
|
Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connectionToClient != null && conn != connectionToClient)
|
||||||
|
{
|
||||||
|
Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conn == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetClientOwner(conn);
|
||||||
|
|
||||||
|
// The client will match to the existing object
|
||||||
|
// update all variables and assign authority
|
||||||
|
NetworkServer.SendSpawnMessage(this, conn);
|
||||||
|
|
||||||
|
clientAuthorityCallback?.Invoke(conn, this, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Deprecated 09/25/2019
|
// Deprecated 09/25/2019
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Obsolete: Use <see cref="RemoveClientAuthority()"/> instead
|
/// Obsolete: Use <see cref="RemoveClientAuthority()"/> instead
|
||||||
@ -1146,44 +1184,6 @@ public void RemoveClientAuthority()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Assign control of an object to a client via the client's <see cref="NetworkConnection">NetworkConnection.</see>
|
|
||||||
/// <para>This causes hasAuthority to be set on the client that owns the object, and NetworkBehaviour.OnStartAuthority will be called on that client. This object then will be in the NetworkConnection.clientOwnedObjects list for the connection.</para>
|
|
||||||
/// <para>Authority can be removed with RemoveClientAuthority. Only one client can own an object at any time. This does not need to be called for player objects, as their authority is setup automatically.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conn"> The connection of the client to assign authority to.</param>
|
|
||||||
/// <returns>True if authority was assigned.</returns>
|
|
||||||
public bool AssignClientAuthority(NetworkConnection conn)
|
|
||||||
{
|
|
||||||
if (!isServer)
|
|
||||||
{
|
|
||||||
Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connectionToClient != null && conn != connectionToClient)
|
|
||||||
{
|
|
||||||
Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conn == null)
|
|
||||||
{
|
|
||||||
Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetClientOwner(conn);
|
|
||||||
|
|
||||||
// The client will match to the existing object
|
|
||||||
// update all variables and assign authority
|
|
||||||
NetworkServer.SendSpawnMessage(this, conn);
|
|
||||||
|
|
||||||
clientAuthorityCallback?.Invoke(conn, this, true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// marks the identity for future reset, this is because we cant reset the identity during destroy
|
// marks the identity for future reset, this is because we cant reset the identity during destroy
|
||||||
// as people might want to be able to read the members inside OnDestroy(), and we have no way
|
// as people might want to be able to read the members inside OnDestroy(), and we have no way
|
||||||
// of invoking reset after OnDestroy is called.
|
// of invoking reset after OnDestroy is called.
|
||||||
|
Loading…
Reference in New Issue
Block a user