Added BinaryIgnore attribute to ignore fields on BinarySerialization

This commit is contained in:
Albin Corén 2018-04-01 10:03:14 +02:00
parent 901f87dfd5
commit 27eff96223
3 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1,13 @@
using System;
namespace MLAPI.Attributes
{
/// <summary>
/// The attribute to use for variables that should be automatically. replicated from Server to Client.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class BinaryIgnore : Attribute
{
}
}

View File

@ -66,6 +66,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes\BinaryIgnore.cs" />
<Compile Include="Data\FieldType.cs" />
<Compile Include="Attributes\SyncedVar.cs" />
<Compile Include="Data\NetworkPool.cs" />

View File

@ -1,10 +1,9 @@
using System;
using MLAPI.Attributes;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;
namespace MLAPI.NetworkingManagerComponents
{
@ -37,7 +36,7 @@ namespace MLAPI.NetworkingManagerComponents
sortedFields = cachedFields[instance.GetType().FullName];
else
{
sortedFields = instance.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).ToArray();
sortedFields = instance.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).Where(x => !x.IsDefined(typeof(BinaryIgnore), true)).ToArray();
cachedFields.Add(instance.GetType().FullName, sortedFields);
}
@ -142,7 +141,7 @@ namespace MLAPI.NetworkingManagerComponents
sortedFields = cachedFields[instance.GetType().FullName];
else
{
sortedFields = instance.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).ToArray();
sortedFields = instance.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(x => x.Name).Where(x => !x.IsDefined(typeof(BinaryIgnore), true)).ToArray();
cachedFields.Add(instance.GetType().FullName, sortedFields);
}