Exemplo n.º 1
0
        public void OnStartServerTest()
        {
            // lets add a component to check OnStartserver
            UnityAction func1 = Substitute.For <UnityAction>();
            UnityAction func2 = Substitute.For <UnityAction>();

            identity.OnStartServer.AddListener(func1);
            identity.OnStartServer.AddListener(func2);

            identity.StartServer();

            func1.Received(1).Invoke();
            func2.Received(1).Invoke();
        }
Exemplo n.º 2
0
        internal void SpawnObject(GameObject obj, INetworkConnection ownerConnection)
        {
            if (!Server || !Server.Active)
            {
                throw new InvalidOperationException("SpawnObject for " + obj + ", NetworkServer is not active. Cannot spawn objects without an active server.");
            }

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

            if (identity is null)
            {
                throw new InvalidOperationException("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj);
            }

            identity.ConnectionToClient  = ownerConnection;
            identity.Server              = Server;
            identity.ServerObjectManager = this;
            identity.Client              = Server.LocalClient;

            // special case to make sure hasAuthority is set
            // on start server in host mode
            if (ownerConnection == Server.LocalConnection)
            {
                identity.HasAuthority = true;
            }

            if (identity.NetId == 0)
            {
                // the object has not been spawned yet
                identity.NetId = GetNextNetworkId();
                SpawnedObjects[identity.NetId] = identity;
                identity.StartServer();
                Spawned.Invoke(identity);
            }

            if (logger.LogEnabled())
            {
                logger.Log("SpawnObject instance ID " + identity.NetId + " asset ID " + identity.AssetId);
            }

            identity.RebuildObservers(true);
        }
Exemplo n.º 3
0
        internal void SpawnObject(GameObject obj, INetworkPlayer ownerPlayer)
        {
            if (!Server || !Server.Active)
            {
                throw new InvalidOperationException("NetworkServer is not active. Cannot spawn objects without an active server.");
            }

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

            if (identity is null)
            {
                throw new InvalidOperationException("SpawnObject " + obj + " has no NetworkIdentity. Please add a NetworkIdentity to " + obj);
            }

            identity.ConnectionToClient = ownerPlayer;

            identity.SetServerValues(Server, this);

            // special case to make sure hasAuthority is set
            // on start server in host mode
            if (ownerPlayer == Server.LocalPlayer)
            {
                identity.HasAuthority = true;
            }

            if (identity.NetId == 0)
            {
                // the object has not been spawned yet
                identity.NetId = GetNextNetworkId();
                identity.StartServer();
                Server.World.AddIdentity(identity.NetId, identity);
            }

            if (logger.LogEnabled())
            {
                logger.Log("SpawnObject instance ID " + identity.NetId + " asset ID " + identity.AssetId);
            }

            identity.RebuildObservers(true);
        }