internal void SetLocalPlayer(short localPlayerControllerId) { m_IsLocalPlayer = true; m_PlayerId = localPlayerControllerId; // 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(); } } }
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); } } }