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

RemoveClientAuthority() public method

Removes ownership for an object for a client by its conneciton.

public RemoveClientAuthority ( NetworkConnection conn ) : bool
conn NetworkConnection The connection of the client to remove authority for.
return bool
        public bool RemoveClientAuthority(NetworkConnection conn)
        {
            if (!this.isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects.");
                }
                return false;
            }
            if (this.connectionToClient != null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority cannot remove authority for a player object");
                }
                return false;
            }
            if (this.m_ClientAuthorityOwner == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has no clientAuthority owner.");
                }
                return false;
            }
            if (this.m_ClientAuthorityOwner != conn)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has different owner.");
                }
                return false;
            }
            this.m_ClientAuthorityOwner.RemoveOwnedObject(this);
            this.m_ClientAuthorityOwner = null;
            this.ForceAuthority(true);
            ClientAuthorityMessage msg = new ClientAuthorityMessage {
                netId = this.netId,
                authority = false
            };
            conn.Send(15, msg);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, false);
            }
            return true;
        }

Usage Example

コード例 #1
0
 void CmdChangeColor(GameObject go, Color c)
 {
     objNetId = go.GetComponent<NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcUpdateTower(go, c);
     objNetId.RemoveClientAuthority(connectionToClient);
 }