You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
783 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace Networking
  6. {
  7. public static class ExtensionMethods
  8. {
  9. public static bool TryRead<T>(this NetworkMessage msg, out T outMsg) where T : MessageBase, new()
  10. {
  11. try
  12. {
  13. outMsg = msg.ReadMessage<T>();
  14. return true;
  15. }
  16. catch
  17. {
  18. outMsg = default(T);
  19. return false;
  20. }
  21. }
  22. public static T TryRead<T>(this NetworkMessage msg) where T : MessageBase, new()
  23. {
  24. T retval;
  25. if (msg.TryRead(out retval))
  26. return retval;
  27. return null;
  28. }
  29. }
  30. }