Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public enum ForgeAcceptableFieldTypes
QUATERNION = 15,
COLOR = 16,
//OBJECT_ARRAY = 17, //Unsupported
//BYTE_ARRAY = 18
//BYTE_ARRAY = 18,
FLOAT2 = 19,
FLOAT3 = 20,
FLOAT4 = 21,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public enum ForgeAcceptableRPCTypes
QUATERNION = 15,
COLOR = 16,
//OBJECT_ARRAY = 17,
BYTE_ARRAY = 18
BYTE_ARRAY = 18,
FLOAT2 = 19,
FLOAT3 = 20,
FLOAT4 = 21,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public static ForgeClassFieldRPCValue GetClassField(FieldInfo field, Type t, boo
type = ForgeAcceptableRPCTypes.VECTOR3;
else if (fieldType == typeof(Vector4))
type = ForgeAcceptableRPCTypes.VECTOR4;
else if (fieldType == typeof(Float2))
type = ForgeAcceptableRPCTypes.FLOAT2;
else if (fieldType == typeof(Float3))
type = ForgeAcceptableRPCTypes.FLOAT3;
else if (fieldType == typeof(Float4))
type = ForgeAcceptableRPCTypes.FLOAT4;
else if (fieldType == typeof(string))
type = ForgeAcceptableRPCTypes.STRING;
//else if (fieldType == typeof(object[]))
Expand Down Expand Up @@ -133,6 +139,12 @@ public static Type GetTypeFromAcceptable(ForgeAcceptableRPCTypes type)
return typeof(Vector3);
case ForgeAcceptableRPCTypes.VECTOR4:
return typeof(Vector4);
case ForgeAcceptableRPCTypes.FLOAT2:
return typeof(Float2);
case ForgeAcceptableRPCTypes.FLOAT3:
return typeof(Float3);
case ForgeAcceptableRPCTypes.FLOAT4:
return typeof(Float4);
case ForgeAcceptableRPCTypes.STRING:
return typeof(string);
//case ForgeAcceptableRPCTypes.OBJECT_ARRAY:
Expand Down Expand Up @@ -180,6 +192,12 @@ public static ForgeAcceptableRPCTypes GetTypeFromAcceptable(string val)
return ForgeAcceptableRPCTypes.VECTOR3;
case "vector4":
return ForgeAcceptableRPCTypes.VECTOR4;
case "float2":
return ForgeAcceptableRPCTypes.FLOAT2;
case "float3":
return ForgeAcceptableRPCTypes.FLOAT3;
case "float4":
return ForgeAcceptableRPCTypes.FLOAT4;
case "string":
return ForgeAcceptableRPCTypes.STRING;
//case "object[]":
Expand All @@ -196,4 +214,4 @@ public override string ToString()
return string.Format("[ Name: {0}, Value: {1}, Type: {2}, IsNetObj: {3}]", FieldRPCName, FieldRPCValue, FieldType, IsNetworkedObject);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public static ForgeClassFieldValue GetClassField(FieldInfo field, Type t, bool i
type = ForgeAcceptableFieldTypes.VECTOR3;
else if (fieldType == typeof(Vector4))
type = ForgeAcceptableFieldTypes.VECTOR4;
else if (fieldType == typeof(Float2))
type = ForgeAcceptableFieldTypes.FLOAT2;
else if (fieldType == typeof(Float3))
type = ForgeAcceptableFieldTypes.FLOAT3;
else if (fieldType == typeof(Float4))
type = ForgeAcceptableFieldTypes.FLOAT4;
//else if (fieldType == typeof(string))
// type = ForgeAcceptableFieldTypes.STRING; //Unsupported
//else if (fieldType == typeof(object[]))
Expand Down Expand Up @@ -126,6 +132,12 @@ public static Type GetTypeFromAcceptable(ForgeAcceptableFieldTypes type)
return typeof(Vector3);
case ForgeAcceptableFieldTypes.VECTOR4:
return typeof(Vector4);
case ForgeAcceptableFieldTypes.FLOAT2:
return typeof(Float2);
case ForgeAcceptableFieldTypes.FLOAT3:
return typeof(Float3);
case ForgeAcceptableFieldTypes.FLOAT4:
return typeof(Float4);
//case ForgeAcceptableFieldTypes.STRING: //Unsupported
// return typeof(string);
//case ForgeAcceptableFieldTypes.OBJECT_ARRAY: //Unsupported
Expand Down Expand Up @@ -220,6 +232,12 @@ public static ForgeAcceptableFieldTypes GetTypeFromAcceptable(string val)
return ForgeAcceptableFieldTypes.VECTOR3;
case "vector4":
return ForgeAcceptableFieldTypes.VECTOR4;
case "float2":
Copy link

@NoTuxNoBux NoTuxNoBux Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these fields also be marked in IsInterpolatable above as interpolatable, just like Unity's Vector types?

I'm not too familiar with the internals, but an implementation for these in BMSExtensions and BeardedMath may be required, e.g.:

public static bool Near(this Float4 target, Float4 other, float distance)
{
    return
        Near(target.x, other.x, distance) &&
        Near(target.y, other.y, distance) &&
        Near(target.z, other.z, distance) &&
        Near(target.w, other.w, distance);
}
public static Float4 Lerp(Float4 a0, Float4 a1, float t)
{
    return new Float4(
        Lerp(a0.x, a1.x, t),
        Lerp(a0.y, a1.y, t),
        Lerp(a0.z, a1.z, t),
        Lerp(a0.w, a1.w, t)
    );
}

Note also that there appears to be a bug (#384) currently that causes interpolation of these new types to break. In any case, I think we can support interpolation here, too. Forge appears to already do this for Vector3 and friends in e.g. InterpolateVector3.

Copy link

@NoTuxNoBux NoTuxNoBux Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed #384 in another pull request, this makes interpolation "work" as in "not break any updates entirely anymore", but not pretty, as there is no actual interpolation happening as is the case for e.g. Vector3. I took a quick stab at this and implementing interpolation seemed to be fairly straightforward.

@DrPotatoNet I can't update this pull request's branch, so could you implement this patch on top of the changes, if this is okay for the maintainers of Forge?

From 21a5f83ca3e275ea88d42e5e50c51edb04cc0d2b Mon Sep 17 00:00:00 2001
From: MrWatts-Anorak <73220431+MrWatts-Anorak@users.noreply.github.com>
Date: Mon, 30 Nov 2020 12:55:37 +0100
Subject: [PATCH] Fix interpolation not working for new Float types

There were multiple bugs here: interpolation was simply not implemented
for the new FloatX types, and falling back to a generic version. This
generic version also didn't work [1].

See also https://github.com/BeardedManStudios/ForgeNetworkingRemastered/pull/310#discussion_r532443679

[1] https://github.com/BeardedManStudios/ForgeNetworkingRemastered/issues/384
---
 .../Editor/ForgeClassFieldValue.cs            | 12 ++++++
 .../Scripts/Networking/BMSExtensions.cs       | 15 +++++++
 .../Scripts/StandAlone/Objects/Float2.cs      | 20 +++++++++-
 .../Scripts/StandAlone/Objects/Float3.cs      | 22 +++++++++-
 .../Scripts/StandAlone/Objects/Float4.cs      | 24 ++++++++++-
 .../StandAlone/Objects/InterpolateFloat2.cs   | 40 +++++++++++++++++++
 .../Objects/InterpolateFloat2.cs.meta         | 11 +++++
 .../StandAlone/Objects/InterpolateFloat3.cs   | 19 +++++++++
 .../Objects/InterpolateFloat3.cs.meta         | 11 +++++
 .../StandAlone/Objects/InterpolateFloat4.cs   | 19 +++++++++
 .../Objects/InterpolateFloat4.cs.meta         | 11 +++++
 11 files changed, 201 insertions(+), 3 deletions(-)
 create mode 100644 unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs
 create mode 100644 unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs.meta
 create mode 100644 unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs
 create mode 100644 unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs.meta
 create mode 100644 unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs
 create mode 100644 unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs.meta

diff --git a/unity-wade/Assets/BeardedManStudios/Editor/ForgeClassFieldValue.cs b/unity-wade/Assets/BeardedManStudios/Editor/ForgeClassFieldValue.cs
index b5230f0..7375ed8 100644
--- a/unity-wade/Assets/BeardedManStudios/Editor/ForgeClassFieldValue.cs
+++ b/unity-wade/Assets/BeardedManStudios/Editor/ForgeClassFieldValue.cs
@@ -170,6 +170,15 @@ namespace BeardedManStudios.Forge.Networking.UnityEditor
 				case ForgeAcceptableFieldTypes.QUATERNION:
 					returnValue = "InterpolateQuaternion";
 					break;
+				case ForgeAcceptableFieldTypes.FLOAT2:
+					returnValue = "InterpolateFloat2";
+					break;
+				case ForgeAcceptableFieldTypes.FLOAT3:
+					returnValue = "InterpolateFloat3";
+					break;
+				case ForgeAcceptableFieldTypes.FLOAT4:
+					returnValue = "InterpolateFloat4";
+					break;
 				default:
 					returnValue = "Interpolated<" + baseTypeString + ">";
 					break;
@@ -188,6 +197,9 @@ namespace BeardedManStudios.Forge.Networking.UnityEditor
 				case ForgeAcceptableFieldTypes.VECTOR2:
 				case ForgeAcceptableFieldTypes.VECTOR3:
 				case ForgeAcceptableFieldTypes.VECTOR4:
+				case ForgeAcceptableFieldTypes.FLOAT2:
+				case ForgeAcceptableFieldTypes.FLOAT3:
+				case ForgeAcceptableFieldTypes.FLOAT4:
 				case ForgeAcceptableFieldTypes.QUATERNION:
 					returnValue = true;
 					break;
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/Networking/BMSExtensions.cs b/unity-wade/Assets/BeardedManStudios/Scripts/Networking/BMSExtensions.cs
index efc7b74..560e818 100644
--- a/unity-wade/Assets/BeardedManStudios/Scripts/Networking/BMSExtensions.cs
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/Networking/BMSExtensions.cs
@@ -57,6 +57,21 @@
 			return target.Between(other - distance, other + distance);
 		}

+		public static bool Near(this Float2 target, Float2 other, float threshold = 0.0012f)
+		{
+			return Float2.Distance(target, other) <= threshold;
+		}
+
+		public static bool Near(this Float3 target, Float3 other, float threshold = 0.0012f)
+		{
+			return Float3.Distance(target, other) <= threshold;
+		}
+
+		public static bool Near(this Float4 target, Float4 other, float threshold = 0.0012f)
+		{
+			return Float4.Distance(target, other) <= threshold;
+		}
+
 		public static bool Near<T>(this T target, T other, float distance)
 		{
 			return target.Equals(other);
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float2.cs b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float2.cs
index 36ca8c2..bd04eeb 100644
--- a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float2.cs
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float2.cs
@@ -1,4 +1,6 @@
-namespace BeardedManStudios
+using System;
+
+namespace BeardedManStudios
 {
 	public partial struct Float2
 	{
@@ -33,5 +35,21 @@
 		{
 			return base.GetHashCode();
 		}
+
+		public static Float2 Lerp(Float2 a0, Float2 a1, float t)
+		{
+			return new Float2(
+				BeardedMath.Lerp(a0.x, a1.x, t),
+				BeardedMath.Lerp(a0.y, a1.y, t)
+			);
+		}
+
+		public static float Distance(Float2 a, Float2 b)
+		{
+			return (float)Math.Sqrt((double)(
+				Math.Pow(a.x - b.x, 2) +
+				Math.Pow(a.y - b.y, 2)
+			));
+		}
 	}
 }
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float3.cs b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float3.cs
index 315f7b6..1670ab2 100644
--- a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float3.cs
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float3.cs
@@ -1,4 +1,6 @@
-namespace BeardedManStudios
+using System;
+
+namespace BeardedManStudios
 {
 	public partial struct Float3
 	{
@@ -34,5 +36,23 @@
 		{
 			return base.GetHashCode();
 		}
+
+		public static Float3 Lerp(Float3 a0, Float3 a1, float t)
+		{
+			return new Float3(
+				BeardedMath.Lerp(a0.x, a1.x, t),
+				BeardedMath.Lerp(a0.y, a1.y, t),
+				BeardedMath.Lerp(a0.z, a1.z, t)
+			);
+		}
+
+		public static float Distance(Float3 a, Float3 b)
+		{
+			return (float)Math.Sqrt((double)(
+				Math.Pow(a.x - b.x, 2) +
+				Math.Pow(a.y - b.y, 2) +
+				Math.Pow(a.z - b.z, 2)
+			));
+		}
 	}
 }
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float4.cs b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float4.cs
index 2fe927e..d9bb279 100644
--- a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float4.cs
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/Float4.cs
@@ -1,4 +1,6 @@
-namespace BeardedManStudios
+using System;
+
+namespace BeardedManStudios
 {
 	public partial struct Float4
 	{
@@ -35,5 +37,25 @@
 		{
 			return base.GetHashCode();
 		}
+
+		public static Float4 Lerp(Float4 a0, Float4 a1, float t)
+		{
+			return new Float4(
+				BeardedMath.Lerp(a0.x, a1.x, t),
+				BeardedMath.Lerp(a0.y, a1.y, t),
+				BeardedMath.Lerp(a0.z, a1.z, t),
+				BeardedMath.Lerp(a0.w, a1.w, t)
+			);
+		}
+
+		public static float Distance(Float4 a, Float4 b)
+		{
+			return (float)Math.Sqrt((double)(
+				Math.Pow(a.x - b.x, 2) +
+				Math.Pow(a.y - b.y, 2) +
+				Math.Pow(a.z - b.z, 2) +
+				Math.Pow(a.w - b.w, 2)
+			));
+		}
 	}
 }
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs
new file mode 100644
index 0000000..5155500
--- /dev/null
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs
@@ -0,0 +1,40 @@
+/*-----------------------------+------------------------------\
+|                                                             |
+|                        !!!NOTICE!!!                         |
+|                                                             |
+|  These libraries are under heavy development so they are    |
+|  subject to make many changes as development continues.     |
+|  For this reason, the libraries may not be well commented.  |
+|  THANK YOU for supporting forge with all your feedback      |
+|  suggestions, bug reports and comments!                     |
+|                                                             |
+|                               - The Forge Team              |
+|                                 Bearded Man Studios, Inc.   |
+|                                                             |
+|  This source code, project files, and associated files are  |
+|  copyrighted by Bearded Man Studios, Inc. (2012-2015) and   |
+|  may not be redistributed without written permission.       |
+|                                                             |
+\------------------------------+-----------------------------*/
+
+using BeardedManStudios.Forge.Networking;
+
+namespace BeardedManStudios
+{
+	public struct InterpolateFloat2 : IInterpolator<Float2>
+	{
+		public Float2 current;
+		public Float2 target;
+		public float LerpT { get; set; }
+		public bool Enabled { get; set; }
+		public ulong Timestep { get; set; }
+
+		public Float2 Interpolate()
+		{
+			if (!Enabled) return target;
+
+			current = Float2.Lerp(current, target, LerpT);
+			return current;
+		}
+	}
+}
\ No newline at end of file
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs.meta b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs.meta
new file mode 100644
index 0000000..f17feab
--- /dev/null
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat2.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5d8f29f9be70c3a4e9c81a969eca280c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData:
+  assetBundleName:
+  assetBundleVariant:
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs
new file mode 100644
index 0000000..6599612
--- /dev/null
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs
@@ -0,0 +1,21 @@
+using BeardedManStudios.Forge.Networking;
+
+namespace BeardedManStudios
+{
+	public struct InterpolateFloat3 : IInterpolator<Float3>
+	{
+		public Float3 current;
+		public Float3 target;
+		public float LerpT { get; set; }
+		public bool Enabled { get; set; }
+		public ulong Timestep { get; set; }
+
+		public Float3 Interpolate()
+		{
+			if (!Enabled) return target;
+
+			current = Float3.Lerp(current, target, LerpT);
+			return current;
+		}
+	}
+}
\ No newline at end of file
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs.meta b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs.meta
new file mode 100644
index 0000000..0ad8ee4
--- /dev/null
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat3.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 57d00189c59006d48a08c6c9ed915b29
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData:
+  assetBundleName:
+  assetBundleVariant:
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs
new file mode 100644
index 0000000..28622e0
--- /dev/null
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs
@@ -0,0 +1,21 @@
+using BeardedManStudios.Forge.Networking;
+
+namespace BeardedManStudios
+{
+	public struct InterpolateFloat4 : IInterpolator<Float4>
+	{
+		public Float4 current;
+		public Float4 target;
+		public float LerpT { get; set; }
+		public bool Enabled { get; set; }
+		public ulong Timestep { get; set; }
+
+		public Float4 Interpolate()
+		{
+			if (!Enabled) return target;
+
+			current = Float4.Lerp(current, target, LerpT);
+			return current;
+		}
+	}
+}
\ No newline at end of file
diff --git a/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs.meta b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs.meta
new file mode 100644
index 0000000..d6b9aee
--- /dev/null
+++ b/unity-wade/Assets/BeardedManStudios/Scripts/StandAlone/Objects/InterpolateFloat4.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 77b17d7f89db5bb4bb8038dfaa3b6da9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData:
+  assetBundleName:
+  assetBundleVariant:
--
2.28.0.windows.1

return ForgeAcceptableFieldTypes.FLOAT2;
case "float3":
return ForgeAcceptableFieldTypes.FLOAT3;
case "float4":
return ForgeAcceptableFieldTypes.FLOAT4;
//case "string":
// return ForgeAcceptableFieldTypes.STRING; //Unsupported
//case "object[]":
Expand All @@ -237,4 +255,4 @@ public override string ToString()
return string.Format("[ Name: {0}, Value: {1}, Type: {2}, IsNetObj: {3}]", FieldName, FieldValue, FieldType, IsNetworkedObject);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public static ForgeAcceptableRPCTypes GetATypeFromPInfo(ParameterInfo pInfo)
type = ForgeAcceptableRPCTypes.VECTOR3;
else if (fieldType == typeof(Vector4))
type = ForgeAcceptableRPCTypes.VECTOR4;
else if (fieldType == typeof(Float2))
type = ForgeAcceptableRPCTypes.FLOAT2;
else if (fieldType == typeof(Float3))
type = ForgeAcceptableRPCTypes.FLOAT3;
else if (fieldType == typeof(Float4))
type = ForgeAcceptableRPCTypes.FLOAT4;
else if (fieldType == typeof(string))
type = ForgeAcceptableRPCTypes.STRING;
//else if (fieldType == typeof(object[]))
Expand All @@ -93,4 +99,4 @@ public static ForgeAcceptableRPCTypes GetATypeFromPInfo(ParameterInfo pInfo)
return type;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public static ForgeAcceptableRPCTypes GetATypeFromPInfo(ParameterInfo pInfo)
type = ForgeAcceptableRPCTypes.VECTOR3;
else if (fieldType == typeof(Vector4))
type = ForgeAcceptableRPCTypes.VECTOR4;
else if (fieldType == typeof(Float2))
type = ForgeAcceptableRPCTypes.FLOAT2;
else if (fieldType == typeof(Float3))
type = ForgeAcceptableRPCTypes.FLOAT3;
else if (fieldType == typeof(Float4))
type = ForgeAcceptableRPCTypes.FLOAT4;
else if (fieldType == typeof(string))
type = ForgeAcceptableRPCTypes.STRING;
//else if (fieldType == typeof(object[]))
Expand All @@ -79,4 +85,4 @@ public static ForgeAcceptableRPCTypes GetATypeFromPInfo(ParameterInfo pInfo)
return type;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ public void Initialize()
_referenceVariables.Add(typeof(Vector4).Name, "Vector4");
_referenceVariables.Add(typeof(Quaternion).Name, "Quaternion");
_referenceVariables.Add(typeof(Color).Name, "Color");
_referenceVariables.Add(typeof(Float2).Name, "Float2");
_referenceVariables.Add(typeof(Float3).Name, "Float3");
_referenceVariables.Add(typeof(Float4).Name, "Float4");
_referenceVariables.Add(typeof(object).Name, "object");
_referenceVariables.Add(typeof(object[]).Name, "object[]");
_referenceVariables.Add(typeof(byte[]).Name, "byte[]");
Expand Down Expand Up @@ -710,7 +713,14 @@ public void MakeForgeFactory()
/// <returns>The generated string to save to a file</returns>
public string SourceCodeNetworkObject(ForgeClassObject cObj, ForgeEditorButton btn, int identity)
{
TextAsset asset = Resources.Load<TextAsset>(EDITOR_RESOURCES_DIR + "/NetworkObjectTemplate");
string networkObjectPath = string.Empty;

if (btn.BaseType == ForgeBaseClassType.NetworkBehavior)
networkObjectPath = EDITOR_RESOURCES_DIR + "/StandAloneNetworkObjectTemplate";
else
networkObjectPath = EDITOR_RESOURCES_DIR + "/NetworkObjectTemplate";

TextAsset asset = Resources.Load<TextAsset>(networkObjectPath);
TemplateSystem template = new TemplateSystem(asset.text);

template.AddVariable("className", btn.StrippedSearchName + "NetworkObject");
Expand Down Expand Up @@ -892,6 +902,32 @@ public string SourceCodeFactory()
return template.Parse();
}

/// <summary>
/// Generates the code factory for all our custom network objects for standalone use
/// </summary>
/// <returns>The string for the save file</returns>
public string SourceCodeStandAloneFactory()
{
TextAsset asset = Resources.Load<TextAsset>(EDITOR_RESOURCES_DIR + "/StandAloneNetworkObjectFactoryTemplate");
TemplateSystem template = new TemplateSystem(asset.text);

List<object> networkObjects = new List<object>();
for (int i = 0; i < _editorButtons.Count; ++i)
{
if (!_editorButtons[i].IsNetworkObject)
continue;

string name = _editorButtons[i].StrippedSearchName + "NetworkObject";
if (networkObjects.Contains(name))
continue;

networkObjects.Add(name);
}

template.AddVariable("networkObjects", networkObjects.ToArray());
return template.Parse();
}

/// <summary>
/// Generates the network manager that will allow the instantiation of these new network objects
/// </summary>
Expand Down Expand Up @@ -1045,6 +1081,15 @@ public void Compile()
sw.Write(networkManagerData);
}

if(ActiveButton.BaseType == ForgeBaseClassType.NetworkBehavior)
{
string standAloneFactoryData = SourceCodeStandAloneFactory();
using (StreamWriter sw = File.CreateText(Path.Combine(_storingPath, "StandAloneNetworkObjectFactory.cs")))
{
sw.Write(standAloneFactoryData);
}
}

//IFormatter previousSavedState = new BinaryFormatter();
//using (Stream s = new FileStream(Path.Combine(Application.persistentDataPath, FN_WIZARD_DATA), FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
//{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BeardedManStudios.Forge.Networking;
using BeardedManStudios.Forge.Networking.Unity;
using UnityEngine;
using BeardedManStudios.Forge.Networking.StandAlone;

namespace BeardedManStudios.Forge.Networking.Generated
{
Expand Down
Loading