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:
Paul Pacheco 2019-10-30 10:13:25 -07:00 committed by vis2k
parent 7df3ce37d1
commit 40f50ac908
6 changed files with 14 additions and 73 deletions

View File

@ -34,17 +34,19 @@ public class NetworkAnimator : NetworkBehaviour
int[] transitionHash;
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
{
get
{
if (isServer)
{
if (!localPlayerAuthority)
if (!clientAuthority)
return true;
// This is a special case where we have localPlayerAuthority set
// on a NetworkIdentity but we have not assigned the client who has
// This is a special case where we have client authority but we have not assigned the client who has
// 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
@ -360,7 +362,7 @@ public void SetTrigger(string triggerName)
/// <param name="hash">Hash id of trigger (from the Animator).</param>
public void SetTrigger(int hash)
{
if (hasAuthority && localPlayerAuthority)
if (hasAuthority && clientAuthority)
{
if (ClientScene.readyConnection != null)
{
@ -369,7 +371,7 @@ public void SetTrigger(int hash)
return;
}
if (isServer && !localPlayerAuthority)
if (isServer && !clientAuthority)
{
RpcOnAnimationTriggerClientMessage(hash);
}

View File

@ -9,10 +9,8 @@ namespace Mirror
public class NetworkIdentityEditor : Editor
{
SerializedProperty serverOnlyProperty;
SerializedProperty localPlayerAuthorityProperty;
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");
NetworkIdentity networkIdentity;
@ -25,7 +23,6 @@ void Init()
networkIdentity = target as NetworkIdentity;
serverOnlyProperty = serializedObject.FindProperty("serverOnly");
localPlayerAuthorityProperty = serializedObject.FindProperty("localPlayerAuthority");
}
}
@ -35,21 +32,7 @@ public override void OnInspectorGUI()
serializedObject.Update();
if (serverOnlyProperty.boolValue)
{
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);
}
EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel);
serializedObject.ApplyModifiedProperties();

View File

@ -719,7 +719,7 @@ internal static void OnClientAuthority(NetworkConnection _, ClientAuthorityMessa
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
{
identity.HandleClientAuthority(msg.authority);
identity.ForceAuthority(msg.authority);
}
}

View File

@ -36,11 +36,6 @@ public class NetworkBehaviour : MonoBehaviour
/// </summary>
[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>
/// 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>

View File

@ -108,13 +108,6 @@ public bool isServer
[FormerlySerializedAs("m_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>
/// 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>
@ -294,12 +287,6 @@ void Awake()
void OnValidate()
{
#if UNITY_EDITOR
if (serverOnly && localPlayerAuthority)
{
Debug.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only.");
localPlayerAuthority = false;
}
SetupIDs();
#endif
}
@ -562,7 +549,7 @@ internal void OnStartClient()
{
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)
{
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
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
// is called below, so the original value is cached here to be checked below.
bool originAuthority = hasAuthority;
if (localPlayerAuthority)
{
hasAuthority = true;
}
hasAuthority = true;
foreach (NetworkBehaviour comp in networkBehavioursCache)
{
comp.OnStartLocalPlayer();
if (localPlayerAuthority && !originAuthority)
if (!originAuthority)
{
comp.OnStartAuthority();
}
@ -1135,11 +1107,6 @@ public bool AssignClientAuthority(NetworkConnection conn)
Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects.");
return false;
}
if (!localPlayerAuthority)
{
Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity components with LocalPlayerAuthority set.");
return false;
}
if (clientAuthorityOwner != null && conn != clientAuthorityOwner)
{

View File

@ -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);
FinishPlayerForConnection(identity, player);
if (identity.localPlayerAuthority)
{
identity.SetClientOwner(conn);
}
identity.SetClientOwner(conn);
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);
FinishPlayerForConnection(identity, player);
if (identity.localPlayerAuthority)
{
identity.SetClientOwner(conn);
}
identity.SetClientOwner(conn);
return true;
}