UnityEngine.Networking.NetworkIdentity.OnStartServer C# (CSharp) Method

OnStartServer() private method

private OnStartServer ( bool allowNonZeroNetId ) : void
allowNonZeroNetId bool
return void
        internal void OnStartServer(bool allowNonZeroNetId)
        {
            if (!this.m_IsServer)
            {
                this.m_IsServer = true;
                if (this.m_LocalPlayerAuthority)
                {
                    this.m_HasAuthority = false;
                }
                else
                {
                    this.m_HasAuthority = true;
                }
                this.m_Observers = new List<NetworkConnection>();
                this.m_ObserverConnections = new HashSet<int>();
                this.CacheBehaviours();
                if (this.netId.IsEmpty())
                {
                    this.m_NetId = GetNextNetworkId();
                }
                else if (!allowNonZeroNetId)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError(string.Concat(new object[] { "Object has non-zero netId ", this.netId, " for ", base.gameObject }));
                    }
                    return;
                }
                if (LogFilter.logDev)
                {
                    Debug.Log(string.Concat(new object[] { "OnStartServer ", base.gameObject, " GUID:", this.netId }));
                }
                NetworkServer.instance.SetLocalObjectOnServer(this.netId, base.gameObject);
                for (int i = 0; i < this.m_NetworkBehaviours.Length; i++)
                {
                    NetworkBehaviour behaviour = this.m_NetworkBehaviours[i];
                    try
                    {
                        behaviour.OnStartServer();
                    }
                    catch (Exception exception)
                    {
                        Debug.LogError("Exception in OnStartServer:" + exception.Message + " " + exception.StackTrace);
                    }
                }
                if (NetworkClient.active && NetworkServer.localClientActive)
                {
                    ClientScene.SetLocalObject(this.netId, base.gameObject);
                    this.OnStartClient();
                }
                if (this.m_HasAuthority)
                {
                    this.OnStartAuthority();
                }
            }
        }

Usage Example

コード例 #1
0
 private bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity uv, PlayerController newPlayerController)
 {
     if (LogFilter.logDev)
     Debug.Log((object) ("NetworkServer SetupLocalPlayerForConnection netID:" + (object) uv.netId));
       ULocalConnectionToClient connectionToClient = conn as ULocalConnectionToClient;
       if (connectionToClient == null)
     return false;
       if (LogFilter.logDev)
     Debug.Log((object) "NetworkServer AddPlayer handling ULocalConnectionToClient");
       if (uv.netId.IsEmpty())
     uv.OnStartServer();
       uv.RebuildObservers(true);
       this.SendSpawnMessage(uv, (NetworkConnection) null);
       connectionToClient.localClient.AddLocalPlayer(newPlayerController);
       uv.SetLocalPlayer(newPlayerController.playerControllerId);
       return true;
 }