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.
 
 
 
 
 
 

43 lines
1.1 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Networking
{
public static class ExtensionMethods
{
public static bool TryRead<T>(this NetworkMessage msg, out T outMsg, bool logError = true) where T : MessageBase, new()
{
try
{
outMsg = msg.ReadMessage<T>();
return true;
}
catch
{
outMsg = default(T);
if (logError)
Debug.LogError("Recieved unknown NetworkMessage. Expected typeof " + typeof(T).Name);
return false;
}
}
public static T TryRead<T>(this NetworkMessage msg, bool logError = true) where T : MessageBase, new()
{
T retval;
if (msg.TryRead(out retval,logError))
return retval;
return null;
}
public static int Hash(this NetworkConnection conn)
{
return (conn.address.GetHashCode() + conn.connectionId).GetHashCode();
}
}
}