From dc6afc13313ee43e33988953b8481c9d88572afd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albin=20Cor=C3=A9n?= <2108U9@gmail.com>
Date: Wed, 7 Mar 2018 20:56:24 +0100
Subject: [PATCH 1/5] Added Reflection based SyncVar system
---
MLAPI/Attributes/FieldType.cs | 19 ++
MLAPI/Attributes/SyncedVar.cs | 10 +
MLAPI/MLAPI.csproj | 5 +-
.../MonoBehaviours/Core/NetworkedBehaviour.cs | 296 ++++++++++++++++++
MLAPI/MonoBehaviours/Core/NetworkedObject.cs | 28 ++
.../MonoBehaviours/Core/NetworkingManager.cs | 72 ++++-
.../SyncedVarManager.cs | 35 +++
7 files changed, 463 insertions(+), 2 deletions(-)
create mode 100644 MLAPI/Attributes/FieldType.cs
create mode 100644 MLAPI/Attributes/SyncedVar.cs
create mode 100644 MLAPI/NetworkingManagerComponents/SyncedVarManager.cs
diff --git a/MLAPI/Attributes/FieldType.cs b/MLAPI/Attributes/FieldType.cs
new file mode 100644
index 0000000..916c77f
--- /dev/null
+++ b/MLAPI/Attributes/FieldType.cs
@@ -0,0 +1,19 @@
+namespace MLAPI.Attributes
+{
+ internal enum FieldType
+ {
+ Bool,
+ Byte,
+ Char,
+ Double,
+ Single,
+ Int,
+ Long,
+ SByte,
+ Short,
+ UInt,
+ ULong,
+ UShort,
+ String
+ }
+}
diff --git a/MLAPI/Attributes/SyncedVar.cs b/MLAPI/Attributes/SyncedVar.cs
new file mode 100644
index 0000000..f01705c
--- /dev/null
+++ b/MLAPI/Attributes/SyncedVar.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace MLAPI.Attributes
+{
+ [AttributeUsage(AttributeTargets.Field)]
+ public class SyncedVar : Attribute
+ {
+
+ }
+}
diff --git a/MLAPI/MLAPI.csproj b/MLAPI/MLAPI.csproj
index 63b2af0..948bd46 100644
--- a/MLAPI/MLAPI.csproj
+++ b/MLAPI/MLAPI.csproj
@@ -41,7 +41,7 @@
AnyCPU
prompt
MinimumRecommendedRules.ruleset
- Off
+ Auto
@@ -56,6 +56,8 @@
+
+
@@ -71,6 +73,7 @@
+
diff --git a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs
index 8c1f608..64f342e 100644
--- a/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs
+++ b/MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs
@@ -2,11 +2,16 @@
using System.Collections.Generic;
using UnityEngine;
using MLAPI.NetworkingManagerComponents;
+using System.Reflection;
+using MLAPI.Attributes;
+using System.Linq;
+using System.IO;
namespace MLAPI
{
public abstract class NetworkedBehaviour : MonoBehaviour
{
+ public float SyncVarSyncDelay = 0.1f;
public bool isLocalPlayer
{
get
@@ -79,6 +84,7 @@ namespace MLAPI
{
_networkedObject = GetComponentInParent();
}
+ NetworkedObject.networkedBehaviours.Add(this);
}
internal bool networkedStartInvoked = false;
@@ -109,6 +115,11 @@ namespace MLAPI
MessageManager.RemoveIncomingMessageHandler(name, counter, networkId);
}
+ private void OnDisable()
+ {
+ NetworkedObject.networkedBehaviours.Remove(this);
+ }
+
private void OnDestroy()
{
foreach (KeyValuePair pair in registeredMessageHandlers)
@@ -117,6 +128,291 @@ namespace MLAPI
}
}
+ #region SYNC_VAR
+ private List syncedFields = new List();
+ internal List syncedFieldTypes = new List();
+ private List