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.

35 lines
746 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace Multiplayer
  6. {
  7. public static class Utility
  8. {
  9. public static bool ReadMessage<T>(NetworkMessage msg, out T outMsg, bool logError = true) where T : MessageBase, new()
  10. {
  11. outMsg = new T();
  12. bool isValid = true;
  13. try
  14. {
  15. outMsg = msg.ReadMessage<T>();
  16. isValid = true;
  17. }
  18. catch (UnityException e)
  19. {
  20. isValid = false;
  21. msg.reader.SeekZero();
  22. #if UNITY_EDITOR
  23. Debug.LogError(e);
  24. #endif
  25. }
  26. return isValid;
  27. }
  28. }
  29. }