AddOwnedObject() private method

private AddOwnedObject ( NetworkIdentity obj ) : void
obj NetworkIdentity
return void
コード例 #1
0
        public bool AssignClientAuthority(NetworkConnection conn)
        {
            if (!isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
                }
                return(false);
            }
            if (!localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
                }
                return(false);
            }

            if (m_ClientAuthorityOwner != null && conn != m_ClientAuthorityOwner)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
                }
                return(false);
            }

            if (conn == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
                }
                return(false);
            }

            m_ClientAuthorityOwner = conn;
            m_ClientAuthorityOwner.AddOwnedObject(this);

            // server no longer has authority (this is called on server). Note that local client could re-acquire authority below
            ForceAuthority(false);

            // send msg to that client
            var msg = new ClientAuthorityMessage();

            msg.netId     = netId;
            msg.authority = true;
            conn.Send((short)MsgType.LocalClientAuthority, msg);

            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, true);
            }
            return(true);
        }
コード例 #2
0
 // used when adding players
 internal void SetClientOwner(NetworkConnection conn)
 {
     if (m_ClientAuthorityOwner != null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("SetClientOwner m_ClientAuthorityOwner already set!");
         }
     }
     m_ClientAuthorityOwner = conn;
     m_ClientAuthorityOwner.AddOwnedObject(this);
 }
コード例 #3
0
ファイル: NetworkIdentity.cs プロジェクト: Hengle/JellyTerain
        public bool AssignClientAuthority(NetworkConnection conn)
        {
            if (!isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
                }
                return(false);
            }
            if (!localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
                }
                return(false);
            }
            if (m_ClientAuthorityOwner != null && conn != m_ClientAuthorityOwner)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " already has an owner. Use RemoveClientAuthority() first.");
                }
                return(false);
            }
            if (conn == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
                }
                return(false);
            }
            m_ClientAuthorityOwner = conn;
            m_ClientAuthorityOwner.AddOwnedObject(this);
            ForceAuthority(authority: false);
            ClientAuthorityMessage clientAuthorityMessage = new ClientAuthorityMessage();

            clientAuthorityMessage.netId     = netId;
            clientAuthorityMessage.authority = true;
            conn.Send(15, clientAuthorityMessage);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, authorityState: true);
            }
            return(true);
        }