I wouldn't use RFC(0), but instead would suggest just using the function's name instead. Also note that collider.GetComponent implies that TNObject is on the collider. Generally it's on the rigidbody instead, so it would be collider.GetComponentInChildren<TNObject>() instead.
Wellll, if we're going to nitpick, I'd say using the function's name is less efficient than a byte identifier. For one, using the ID reduces packet size (doesn't have to write the string). Secondly, when the packet arrives and execution occurs, it's less expensive to look up the ID than the name:
if (ent.id == funcID)
generates the following IL:
ldloca.s CachedFunc
ldfld System.Byte CachedFunc::id
ldarg.1
bne.un -> 49
Compared to looking up the name:
if (ent.func.Name == funcName)
generates the following IL:
ldloca.s CachedFunc
ldfld System.Reflection.MethodInfo TNet.CachedFunc::func
callvirt System.String System.Reflection.MemberInfo::get_Name()
ldarg.1
call System.Boolean System.String::op_Equality(System.String, System.String)
brfalse -> 52
String comparisons are always going to be more expensive than simple integer comparisons.
Granted, using a string adds a lot to convenience and readability, but you can do something like so to achieve similar results:
public class NetworkManager
{
public const byte NETID_COLLISION_OTHER = 1;
}
tno.Send(NetworkManager.NETID_COLLISION_OTHER, Target.All, otherTNO.ownerID);
[RFC(NetworkManager.NETID_COLLISION_OTHER)]
public void RFCCollisionOther(int id)
{
if (id == tno.ownerID)
{
// do stuff
}
}
Additionally, why stop at checking just children? Use the following extension method instead:
public static T GetComponentAll<T>(this GameObject go) where T : Component
{
T component = go.GetComponent<T>();
if (component == null)
{
component = go.GetComponentInParent<T>();
if (component == null)
{
component = go.GetComponentInChildren<T>();
if (component == null)
return null;
}
}
return component;
}
Though, TNObject does call FindParent in its Start() function, so you only really need to check downwards. Also, you were probably more suggesting to not use 0 in tno.Send as SendRFC checks if byte ID is 0, but that's more of a design flaw in my opinion. Shouldn't it check if id is -1 instead?