static bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity identity) { if (LogFilter.Debug) Debug.Log("NetworkServer SetupLocalPlayerForConnection netID:" + identity.netId); if (conn is ULocalConnectionToClient localConnection) { if (LogFilter.Debug) Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient"); // Spawn this player for other players, instead of SpawnObject: if (identity.netId == 0) { // it is allowed to provide an already spawned object as the new player object. // so dont spawn it again. identity.OnStartServer(true); } identity.RebuildObservers(true); SendSpawnMessage(identity, null); // Set up local player instance on the client instance and update local object map localConnection.localClient.AddLocalPlayer(identity); identity.SetClientOwner(conn); // Trigger OnAuthority identity.ForceAuthority(true); // Trigger OnStartLocalPlayer identity.SetLocalPlayer(); return true; } return false; }
static bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity uv) { if (LogFilter.Debug) { Debug.Log("NetworkServer SetupLocalPlayerForConnection netID:" + uv.netId); } var localConnection = conn as ULocalConnectionToClient; if (localConnection != null) { if (LogFilter.Debug) { Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient"); } // Spawn this player for other players, instead of SpawnObject: if (uv.netId == 0) { // it is allowed to provide an already spawned object as the new player object. // so dont spawn it again. uv.OnStartServer(true); } uv.RebuildObservers(true); SendSpawnMessage(uv, null); // Set up local player instance on the client instance and update local object map localConnection.localClient.AddLocalPlayer(uv); uv.SetClientOwner(conn); // Trigger OnAuthority uv.ForceAuthority(true); // Trigger OnStartLocalPlayer uv.SetLocalPlayer(); return(true); } return(false); }
public static bool SpawnObjects() { if (!active) { return(true); } NetworkIdentity[] identities = Resources.FindObjectsOfTypeAll <NetworkIdentity>(); for (int i = 0; i < identities.Length; i++) { NetworkIdentity identity = identities[i]; if (!ValidateSceneObject(identity)) { continue; } if (LogFilter.Debug) { Debug.Log("SpawnObjects sceneId:" + identity.sceneId + " name:" + identity.gameObject.name); } identity.Reset(); identity.gameObject.SetActive(true); } for (int i = 0; i < identities.Length; i++) { NetworkIdentity identity = identities[i]; if (!ValidateSceneObject(identity)) { continue; } Spawn(identity.gameObject); // these objects are server authority - even if "localPlayerAuthority" is set on them identity.ForceAuthority(true); } return(true); }