I haven’t seen any posts on this, so my apologies if this is a duplicate. If anyone has found themselves in a position where they would like to have several scripts making use of the OnSerializeNetworkView call, you can use this script to bridge the gap. Simply add all scripts that need OnSerializeNetworkView to the ‘components’ property, and set the NetworkView’s observed property to this script.
This is only recommended for “Unreliable” transmissions, unless someone can help shed some light on how the delta compressed mode knows what data has changed. Does it inspect the scripts? Or does it just work off of the differences between the contents of the BinaryStream each time.
using UnityEngine;
using System.Collections;
using System.Reflection;
public class NetworkSerializeMultiplexer : MonoBehaviour {
public Component[] components;
void OnSerializeNetworkView( BitStream stream, NetworkMessageInfo info )
{
foreach( Component c in components )
{
try
{
System.Type myType = c.GetType();
myType.InvokeMember( "OnSerializeNetworkView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, c, new System.Object[]{ stream, info } );
} catch( System.MissingMethodException e )
{
}
}
}
}