OnStartAuthority() public method

This is invoked on behaviours that have authority, based on context and NetworkIdentity.hasAuthority.

This is called after OnStartServer and before OnStartClient.

When AssignClientAuthority is called on the server, this will be called on the client that owns the object. When an object is spawned with NetworkServer.Spawn with a NetworkConnection parameter included, this will be called on the client that owns the object.

public OnStartAuthority ( ) : void
return void
示例#1
0
        internal void SetLocalPlayer()
        {
            m_IsLocalPlayer = true;

            // there is an ordering issue here that originAuthority solves. OnStartAuthority should only be called if m_HasAuthority was false when this function began,
            // or it will be called twice for this object. But that state is lost by the time OnStartAuthority is called below, so the original value is cached
            // here to be checked below.
            bool originAuthority = m_HasAuthority;

            if (localPlayerAuthority)
            {
                m_HasAuthority = true;
            }

            for (int i = 0; i < m_NetworkBehaviours.Length; i++)
            {
                NetworkBehaviour comp = m_NetworkBehaviours[i];
                comp.OnStartLocalPlayer();

                if (localPlayerAuthority && !originAuthority)
                {
                    comp.OnStartAuthority();
                }
            }
        }
示例#2
0
 internal void OnStartAuthority()
 {
     for (int i = 0; i < m_NetworkBehaviours.Length; i++)
     {
         NetworkBehaviour comp = m_NetworkBehaviours[i];
         try
         {
             comp.OnStartAuthority();
         }
         catch (Exception e)
         {
             Debug.LogError("Exception in OnStartAuthority:" + e.Message + " " + e.StackTrace);
         }
     }
 }
示例#3
0
        internal void OnStartAuthority()
        {
            if (m_NetworkBehaviours == null && LogFilter.logError)
            {
                Debug.LogError("Network object " + name + " not initialized properly. Do you have more than one NetworkIdentity in the same object? Did you forget to spawn this object with NetworkServer?", this);
                return;
            }

            for (int i = 0; i < m_NetworkBehaviours.Length; i++)
            {
                NetworkBehaviour comp = m_NetworkBehaviours[i];
                try
                {
                    comp.OnStartAuthority();
                }
                catch (Exception e)
                {
                    Debug.LogError("Exception in OnStartAuthority:" + e.Message + " " + e.StackTrace);
                }
            }
        }