Lookups.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. using Mirror;
  2. using System.Runtime.CompilerServices;
  3. namespace FirstGearGames.Utilities.Networks
  4. {
  5. public static class Lookups
  6. {
  7. /// <summary>
  8. /// Returns the NetworkBehaviour for the specified NetworkIdentity and component index.
  9. /// </summary>
  10. /// <param name="componentIndex"></param>
  11. /// <returns></returns>
  12. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  13. public static NetworkBehaviour ReturnNetworkBehaviour(NetworkIdentity netIdentity, byte componentIndex)
  14. {
  15. if (netIdentity == null)
  16. return null;
  17. /* Networkbehaviours within the collection are the same order as compenent indexes.
  18. * I can save several iterations by simply grabbing the index from the networkbehaviours collection rather than iterating
  19. * it. */
  20. //A network behaviour was removed or added at runtime, component counts don't match up.
  21. if (componentIndex >= netIdentity.NetworkBehaviours.Length)
  22. return null;
  23. return netIdentity.NetworkBehaviours[componentIndex];
  24. }
  25. }
  26. }