protected override void Reflect()
{
if (NetworkingManager.IsOnline)
{
rigidbodyRef = GetComponent<Rigidbody>();
colliderRef = GetComponent<Collider>();
if (colliderRef != null && colliderRef.enabled)
{
colliderRef.enabled = false;
turnedOffCollider = true;
}
}
base.Reflect();
#if NETFX_CORE
// Get all of the fields for this class
List<FieldInfo> fields = this.GetType().GetRuntimeFields().OrderBy(x => x.Name).ToList();
// Get all of the properties for this class
List<PropertyInfo> properties = this.GetType().GetRuntimeProperties().OrderBy(x => x.Name).ToList();
#else
// Get all of the fields for this class
FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).ToArray();
// Get all of the properties for this class
PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).ToArray();
#endif
// Go throug all of the found fields and find any that are to be synced across the network
#if NETFX_CORE
for (int i = 0; i < fields.Count; i++)
#else
for (int i = 0; i < fields.Length; i++)
#endif
{
// If this field has a [NetSync] attribute then add it to the variables to be synced
NetSync[] netSyncs = fields[i].GetCustomAttributes(typeof(NetSync), true) as NetSync[];
if (netSyncs.Length != 0)
{
// Create a temporary reference to this particular object to be used
FieldInfo field = fields[i];
#if NETFX_CORE
AddNetworkVariable(() => field.GetValue(this), x => field.SetValue(this, x), netSyncs[0]);
#else
GetValueDelegate get = (GetValueDelegate)Delegate.CreateDelegate(typeof(GetValueDelegate), field, "GetValue");
SetValueDelegate set = (SetValueDelegate)Delegate.CreateDelegate(typeof(SetValueDelegate), field, typeof(FieldInfo).GetMethod("SetValue", new Type[] { typeof(object), typeof(object) }));
AddNetworkVariable(() => get(this), x => set(this, x), netSyncs[0], netSyncs[0] is ManualNetSync, netSyncs[0] is NetSyncToServer);
#endif
}
}
// Go throug all of the found propperties and find any that are to be synced across the network
#if NETFX_CORE
for (int i = 0; i < properties.Count; i++)
#else
for (int i = 0; i < properties.Length; i++)
#endif
{
// If this property has a [NetSync] attribute then add it to the variables to be synced
#if NETFX_CORE
if (properties[i].GetCustomAttribute<NetSync>() != null)
#else
if (properties[i].GetCustomAttributes(typeof(NetSync), true).Length != 0)
#endif
{
// Make sure that the property is read and writeable otherwise there is no reason for it to sync
if (!properties[i].CanWrite || !properties[i].CanRead)
throw new NetworkException("Properties marked with the [NetSync] attribute must be readable and writeable");
// TODO: Getter and setter should be bound to delegate as fields are
// Create a temporary reference to this particular object to be used
PropertyInfo property = properties[i];
AddNetworkVariable(() => property.GetValue(this, null), x => property.SetValue(this, x, null));
}
}
SetupPreviousTransform();
}