Used Expression Body Members to make code smaller and nicer in NetworkIdentity. (#486)

This commit is contained in:
rodolphito 2019-02-28 01:20:57 -08:00 committed by vis2k
parent 2d37a9e87c
commit c13f4bd13b

View File

@ -52,14 +52,7 @@ public sealed class NetworkIdentity : MonoBehaviour
// all spawned NetworkIdentities by netId. needed on server and client. // all spawned NetworkIdentities by netId. needed on server and client.
public static Dictionary<uint, NetworkIdentity> spawned = new Dictionary<uint, NetworkIdentity>(); public static Dictionary<uint, NetworkIdentity> spawned = new Dictionary<uint, NetworkIdentity>();
public NetworkBehaviour[] NetworkBehaviours public NetworkBehaviour[] NetworkBehaviours => m_NetworkBehaviours = m_NetworkBehaviours ?? GetComponents<NetworkBehaviour>();
{
get
{
m_NetworkBehaviours = m_NetworkBehaviours ?? GetComponents<NetworkBehaviour>();
return m_NetworkBehaviours;
}
}
// the AssetId trick: // the AssetId trick:
// - ideally we would have a serialized 'Guid m_AssetId' but Unity can't // - ideally we would have a serialized 'Guid m_AssetId' but Unity can't
@ -111,10 +104,7 @@ internal void SetClientOwner(NetworkConnection conn)
} }
// used during dispose after disconnect // used during dispose after disconnect
internal void ClearClientOwner() internal void ClearClientOwner() => clientAuthorityOwner = null;
{
clientAuthorityOwner = null;
}
internal void ForceAuthority(bool authority) internal void ForceAuthority(bool authority)
{ {
@ -135,10 +125,7 @@ internal void ForceAuthority(bool authority)
} }
static uint s_NextNetworkId = 1; static uint s_NextNetworkId = 1;
internal static uint GetNextNetworkId() internal static uint GetNextNetworkId() => s_NextNetworkId++;
{
return s_NextNetworkId++;
}
public delegate void ClientAuthorityCallback(NetworkConnection conn, NetworkIdentity identity, bool authorityState); public delegate void ClientAuthorityCallback(NetworkConnection conn, NetworkIdentity identity, bool authorityState);
public static ClientAuthorityCallback clientAuthorityCallback; public static ClientAuthorityCallback clientAuthorityCallback;
@ -154,20 +141,9 @@ internal void SetNetworkInstanceId(uint newNetId)
} }
// only used when fixing duplicate scene IDs during post-processing // only used when fixing duplicate scene IDs during post-processing
public void ForceSceneId(uint newSceneId) public void ForceSceneId(uint newSceneId) => m_SceneId = newSceneId;
{ internal void EnableIsClient() => isClient = true;
m_SceneId = newSceneId; internal void EnableIsServer() => m_IsServer = true;
}
internal void EnableIsClient()
{
isClient = true;
}
internal void EnableIsServer()
{
m_IsServer = true;
}
// used when the player object for a connection changes // used when the player object for a connection changes
internal void SetNotLocalPlayer() internal void SetNotLocalPlayer()
@ -200,21 +176,9 @@ void OnValidate()
SetupIDs(); SetupIDs();
} }
void AssignAssetID(GameObject prefab) void AssignAssetID(GameObject prefab) => AssignAssetID(AssetDatabase.GetAssetPath(prefab));
{ void AssignAssetID(string path) => m_AssetId = AssetDatabase.AssetPathToGUID(path);
string path = AssetDatabase.GetAssetPath(prefab); bool ThisIsAPrefab() => PrefabUtility.IsPartOfPrefabAsset(gameObject);
AssignAssetID(path);
}
void AssignAssetID(string path)
{
m_AssetId = AssetDatabase.AssetPathToGUID(path);
}
bool ThisIsAPrefab()
{
return PrefabUtility.IsPartOfPrefabAsset(gameObject);
}
bool ThisIsASceneObjectWithPrefabParent(out GameObject prefab) bool ThisIsASceneObjectWithPrefabParent(out GameObject prefab)
{ {
@ -873,10 +837,7 @@ public bool AssignClientAuthority(NetworkConnection conn)
// 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.
internal void MarkForReset() internal void MarkForReset() => m_Reset = true;
{
m_Reset = true;
}
// if we have marked an identity for reset we do the actual reset. // if we have marked an identity for reset we do the actual reset.
internal void Reset() internal void Reset()