Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
        public bool AssignClientAuthority(NetworkConnection conn)
        {
            if (!isServer)
            {
                Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
                return(false);
            }
            if (!localPlayerAuthority)
            {
                Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
                return(false);
            }

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

            if (conn == null)
            {
                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);
        }