mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
breaking: Remove localPlayerAuthority (#1192)
* breaking: Remove localPlayerAuthority (#1188) * breaking: Remove localPlayerAuthority This flag does not do anything useful in anything but NetworkAnimator so NetworkAnimator can keep it's own flag. * Add tooltip with explanation * Editor should no longer access localPlayerAuthority property
This commit is contained in:
parent
7df3ce37d1
commit
40f50ac908
@ -34,17 +34,19 @@ public class NetworkAnimator : NetworkBehaviour
|
|||||||
int[] transitionHash;
|
int[] transitionHash;
|
||||||
float sendTimer;
|
float sendTimer;
|
||||||
|
|
||||||
|
[Tooltip("Set to true if animations come from owner client, set to false if animations always come from server")]
|
||||||
|
public bool clientAuthority;
|
||||||
|
|
||||||
bool sendMessagesAllowed
|
bool sendMessagesAllowed
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (isServer)
|
if (isServer)
|
||||||
{
|
{
|
||||||
if (!localPlayerAuthority)
|
if (!clientAuthority)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// This is a special case where we have localPlayerAuthority set
|
// This is a special case where we have client authority but we have not assigned the client who has
|
||||||
// on a NetworkIdentity but we have not assigned the client who has
|
|
||||||
// authority over it, no animator data will be sent over the network by the server.
|
// authority over it, no animator data will be sent over the network by the server.
|
||||||
//
|
//
|
||||||
// So we check here for a clientAuthorityOwner and if it is null we will
|
// So we check here for a clientAuthorityOwner and if it is null we will
|
||||||
@ -360,7 +362,7 @@ public void SetTrigger(string triggerName)
|
|||||||
/// <param name="hash">Hash id of trigger (from the Animator).</param>
|
/// <param name="hash">Hash id of trigger (from the Animator).</param>
|
||||||
public void SetTrigger(int hash)
|
public void SetTrigger(int hash)
|
||||||
{
|
{
|
||||||
if (hasAuthority && localPlayerAuthority)
|
if (hasAuthority && clientAuthority)
|
||||||
{
|
{
|
||||||
if (ClientScene.readyConnection != null)
|
if (ClientScene.readyConnection != null)
|
||||||
{
|
{
|
||||||
@ -369,7 +371,7 @@ public void SetTrigger(int hash)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isServer && !localPlayerAuthority)
|
if (isServer && !clientAuthority)
|
||||||
{
|
{
|
||||||
RpcOnAnimationTriggerClientMessage(hash);
|
RpcOnAnimationTriggerClientMessage(hash);
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,8 @@ namespace Mirror
|
|||||||
public class NetworkIdentityEditor : Editor
|
public class NetworkIdentityEditor : Editor
|
||||||
{
|
{
|
||||||
SerializedProperty serverOnlyProperty;
|
SerializedProperty serverOnlyProperty;
|
||||||
SerializedProperty localPlayerAuthorityProperty;
|
|
||||||
|
|
||||||
readonly GUIContent serverOnlyLabel = new GUIContent("Server Only", "True if the object should only exist on the server.");
|
readonly GUIContent serverOnlyLabel = new GUIContent("Server Only", "True if the object should only exist on the server.");
|
||||||
readonly GUIContent localPlayerAuthorityLabel = new GUIContent("Local Player Authority", "True if this object will be controlled by a player on a client.");
|
|
||||||
readonly GUIContent spawnLabel = new GUIContent("Spawn Object", "This causes an unspawned server object to be spawned on clients");
|
readonly GUIContent spawnLabel = new GUIContent("Spawn Object", "This causes an unspawned server object to be spawned on clients");
|
||||||
|
|
||||||
NetworkIdentity networkIdentity;
|
NetworkIdentity networkIdentity;
|
||||||
@ -25,7 +23,6 @@ void Init()
|
|||||||
networkIdentity = target as NetworkIdentity;
|
networkIdentity = target as NetworkIdentity;
|
||||||
|
|
||||||
serverOnlyProperty = serializedObject.FindProperty("serverOnly");
|
serverOnlyProperty = serializedObject.FindProperty("serverOnly");
|
||||||
localPlayerAuthorityProperty = serializedObject.FindProperty("localPlayerAuthority");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,21 +32,7 @@ public override void OnInspectorGUI()
|
|||||||
|
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
if (serverOnlyProperty.boolValue)
|
EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel);
|
||||||
{
|
|
||||||
EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel);
|
|
||||||
EditorGUILayout.LabelField("Local Player Authority cannot be set for server-only objects");
|
|
||||||
}
|
|
||||||
else if (localPlayerAuthorityProperty.boolValue)
|
|
||||||
{
|
|
||||||
EditorGUILayout.LabelField("Server Only cannot be set for Local Player Authority objects");
|
|
||||||
EditorGUILayout.PropertyField(localPlayerAuthorityProperty, localPlayerAuthorityLabel);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel);
|
|
||||||
EditorGUILayout.PropertyField(localPlayerAuthorityProperty, localPlayerAuthorityLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
|
@ -719,7 +719,7 @@ internal static void OnClientAuthority(NetworkConnection _, ClientAuthorityMessa
|
|||||||
|
|
||||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
|
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
|
||||||
{
|
{
|
||||||
identity.HandleClientAuthority(msg.authority);
|
identity.ForceAuthority(msg.authority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +36,6 @@ public class NetworkBehaviour : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[HideInInspector] public float syncInterval = 0.1f;
|
[HideInInspector] public float syncInterval = 0.1f;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This value is set on the NetworkIdentity and is accessible here for convenient access for scripts.
|
|
||||||
/// </summary>
|
|
||||||
public bool localPlayerAuthority => netIdentity.localPlayerAuthority;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if this object is active on an active server.
|
/// Returns true if this object is active on an active server.
|
||||||
/// <para>This is only true if the object has been spawned. This is different from NetworkServer.active, which is true if the server itself is active rather than this object being active.</para>
|
/// <para>This is only true if the object has been spawned. This is different from NetworkServer.active, which is true if the server itself is active rather than this object being active.</para>
|
||||||
|
@ -108,13 +108,6 @@ public bool isServer
|
|||||||
[FormerlySerializedAs("m_ServerOnly")]
|
[FormerlySerializedAs("m_ServerOnly")]
|
||||||
public bool serverOnly;
|
public bool serverOnly;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// localPlayerAuthority means that the client of the "owning" player has authority over their own player object.
|
|
||||||
/// <para>Authority for this object will be on the player's client. So hasAuthority will be true on that client - and false on the server and on other clients.</para>
|
|
||||||
/// </summary>
|
|
||||||
[FormerlySerializedAs("m_LocalPlayerAuthority")]
|
|
||||||
public bool localPlayerAuthority;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The client that has authority for this object. This will be null if no client has authority.
|
/// The client that has authority for this object. This will be null if no client has authority.
|
||||||
/// <para>This is set for player objects with localPlayerAuthority, and for objects set with AssignClientAuthority, and spawned with SpawnWithClientAuthority.</para>
|
/// <para>This is set for player objects with localPlayerAuthority, and for objects set with AssignClientAuthority, and spawned with SpawnWithClientAuthority.</para>
|
||||||
@ -294,12 +287,6 @@ void Awake()
|
|||||||
void OnValidate()
|
void OnValidate()
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (serverOnly && localPlayerAuthority)
|
|
||||||
{
|
|
||||||
Debug.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only.");
|
|
||||||
localPlayerAuthority = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetupIDs();
|
SetupIDs();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -562,7 +549,7 @@ internal void OnStartClient()
|
|||||||
{
|
{
|
||||||
isClient = true;
|
isClient = true;
|
||||||
|
|
||||||
if (LogFilter.Debug) Debug.Log("OnStartClient " + gameObject + " netId:" + netId + " localPlayerAuthority:" + localPlayerAuthority);
|
if (LogFilter.Debug) Debug.Log("OnStartClient " + gameObject + " netId:" + netId);
|
||||||
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
foreach (NetworkBehaviour comp in NetworkBehaviours)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -836,18 +823,6 @@ internal void OnDeserializeAllSafely(NetworkReader reader, bool initialState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// happens on client
|
|
||||||
internal void HandleClientAuthority(bool authority)
|
|
||||||
{
|
|
||||||
if (!localPlayerAuthority)
|
|
||||||
{
|
|
||||||
Debug.LogError("HandleClientAuthority " + gameObject + " does not have localPlayerAuthority");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ForceAuthority(authority);
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper function to handle SyncEvent/Command/Rpc
|
// helper function to handle SyncEvent/Command/Rpc
|
||||||
void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvokeType invokeType, NetworkReader reader)
|
void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvokeType invokeType, NetworkReader reader)
|
||||||
{
|
{
|
||||||
@ -904,16 +879,13 @@ internal void SetLocalPlayer()
|
|||||||
// or it will be called twice for this object, but that state is lost by the time OnStartAuthority
|
// or it will be called twice for this object, but that state is lost by the time OnStartAuthority
|
||||||
// is called below, so the original value is cached here to be checked below.
|
// is called below, so the original value is cached here to be checked below.
|
||||||
bool originAuthority = hasAuthority;
|
bool originAuthority = hasAuthority;
|
||||||
if (localPlayerAuthority)
|
hasAuthority = true;
|
||||||
{
|
|
||||||
hasAuthority = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (NetworkBehaviour comp in networkBehavioursCache)
|
foreach (NetworkBehaviour comp in networkBehavioursCache)
|
||||||
{
|
{
|
||||||
comp.OnStartLocalPlayer();
|
comp.OnStartLocalPlayer();
|
||||||
|
|
||||||
if (localPlayerAuthority && !originAuthority)
|
if (!originAuthority)
|
||||||
{
|
{
|
||||||
comp.OnStartAuthority();
|
comp.OnStartAuthority();
|
||||||
}
|
}
|
||||||
@ -1135,11 +1107,6 @@ public bool AssignClientAuthority(NetworkConnection conn)
|
|||||||
Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
|
Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!localPlayerAuthority)
|
|
||||||
{
|
|
||||||
Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity components with LocalPlayerAuthority set.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientAuthorityOwner != null && conn != clientAuthorityOwner)
|
if (clientAuthorityOwner != null && conn != clientAuthorityOwner)
|
||||||
{
|
{
|
||||||
|
@ -821,10 +821,7 @@ public static bool AddPlayerForConnection(NetworkConnection conn, GameObject pla
|
|||||||
if (LogFilter.Debug) Debug.Log("Adding new playerGameObject object netId: " + identity.netId + " asset ID " + identity.assetId);
|
if (LogFilter.Debug) Debug.Log("Adding new playerGameObject object netId: " + identity.netId + " asset ID " + identity.assetId);
|
||||||
|
|
||||||
FinishPlayerForConnection(identity, player);
|
FinishPlayerForConnection(identity, player);
|
||||||
if (identity.localPlayerAuthority)
|
identity.SetClientOwner(conn);
|
||||||
{
|
|
||||||
identity.SetClientOwner(conn);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -910,10 +907,7 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn,
|
|||||||
if (LogFilter.Debug) Debug.Log("Replacing playerGameObject object netId: " + player.GetComponent<NetworkIdentity>().netId + " asset ID " + player.GetComponent<NetworkIdentity>().assetId);
|
if (LogFilter.Debug) Debug.Log("Replacing playerGameObject object netId: " + player.GetComponent<NetworkIdentity>().netId + " asset ID " + player.GetComponent<NetworkIdentity>().assetId);
|
||||||
|
|
||||||
FinishPlayerForConnection(identity, player);
|
FinishPlayerForConnection(identity, player);
|
||||||
if (identity.localPlayerAuthority)
|
identity.SetClientOwner(conn);
|
||||||
{
|
|
||||||
identity.SetClientOwner(conn);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user