Exemple #1
0
        internal static void SpawnObject(GameObject obj)
        {
            if (!active)
            {
                Debug.LogError("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server.");
                return;
            }

            NetworkIdentity identity = obj.GetComponent <NetworkIdentity>();

            if (identity == null)
            {
                Debug.LogError("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj);
                return;
            }
            identity.Reset();

            identity.OnStartServer(false);

            if (LogFilter.Debug)
            {
                Debug.Log("SpawnObject instance ID " + identity.netId + " asset ID " + identity.assetId);
            }

            identity.RebuildObservers(true);
            //SendSpawnMessage(objNetworkIdentity, null);
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        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);
        }