Skip to content

Commit 225dfb3

Browse files
author
FirstGearGames
committed
2.2.5
- Added StatisticsManager, can be placed on your NetworkManager for a variety of game statistics. - Improved DefaultPrefabObjects are now automatically refreshed before builds. - Fixed typo in TimeManager when setting lastMultipleTicks value. - Fixed Odin Inspector causing SceneId to serialize every frame when object is selected. - Improved SceneManager for mobile devices. - Fixed generic collection type fields from other assemblies sometimes creating codegen errors. - Added NetworkObject.IsGlobal, which allows NetworkObejcts to be visible for all players and making them DontDestroyOnLoad. - Fixed properties with generic return types causing codegen errors.
1 parent d9805a4 commit 225dfb3

26 files changed

Lines changed: 487 additions & 114 deletions

Assets/FishNet/CodeGenerating/Helpers/Extension/ModuleDefinitionExtensions.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ namespace FishNet.CodeGenerating.Helping.Extension
99

1010
public static class ModuleDefinitionExtensions
1111
{
12-
13-
/// <summary>
14-
/// Returns a TypeReference after being imported into moduleDef.
15-
/// </summary>
16-
public static TypeReference ImportIfDifferent(this ModuleDefinition moduleDef, TypeReference tr)
17-
{
18-
if (tr.Module != moduleDef)
19-
return moduleDef.ImportReference(tr.CachedResolve());
20-
else
21-
return tr;
22-
}
23-
2412
/// <summary>
2513
/// Gets a class within CodegenSession.Module.
2614
/// </summary>

Assets/FishNet/CodeGenerating/Helpers/Extension/TypeDefinitionExtensions.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ public static IEnumerable<FieldDefinition> FindAllPublicFields(this TypeDefiniti
3636
if (IsExcluded(typeDef, excludedBaseTypes, excludedAssemblyPrefixes))
3737
break;
3838

39-
foreach (FieldDefinition field in typeDef.Fields)
39+
foreach (FieldDefinition fd in typeDef.Fields)
4040
{
41-
if (ignoreStatic && field.IsStatic)
41+
if (ignoreStatic && fd.IsStatic)
4242
continue;
43-
if (field.IsPrivate)
43+
if (fd.IsPrivate)
4444
continue;
45-
if (ignoreNonSerialized && field.IsNotSerialized)
45+
if (ignoreNonSerialized && fd.IsNotSerialized)
46+
continue;
47+
if (CodegenSession.GeneralHelper.CodegenExclude(fd))
4648
continue;
4749

48-
yield return field;
50+
yield return fd;
4951
}
5052

5153
try { typeDef = typeDef.BaseType?.CachedResolve(); }
@@ -58,23 +60,27 @@ public static IEnumerable<FieldDefinition> FindAllPublicFields(this TypeDefiniti
5860
/// </summary>
5961
/// <param name="typeDef"></param>
6062
/// <returns></returns>
61-
public static IEnumerable<PropertyDefinition> FindAllPublicProperties(this TypeDefinition typeDef, System.Type[] excludedBaseTypes = null, string[] excludedAssemblyPrefixes = null)
63+
public static IEnumerable<PropertyDefinition> FindAllPublicProperties(this TypeDefinition typeDef, bool excludeGenerics = true, System.Type[] excludedBaseTypes = null, string[] excludedAssemblyPrefixes = null)
6264
{
6365
while (typeDef != null)
6466
{
6567
if (IsExcluded(typeDef, excludedBaseTypes, excludedAssemblyPrefixes))
6668
break;
6769

68-
foreach (PropertyDefinition prop in typeDef.Properties)
70+
foreach (PropertyDefinition pd in typeDef.Properties)
6971
{
7072
//Missing get or set method.
71-
if (prop.GetMethod == null || prop.SetMethod == null)
73+
if (pd.GetMethod == null || pd.SetMethod == null)
7274
continue;
7375
//Get or set is private.
74-
if (prop.GetMethod.IsPrivate || prop.SetMethod.IsPrivate)
76+
if (pd.GetMethod.IsPrivate || pd.SetMethod.IsPrivate)
77+
continue;
78+
if (excludeGenerics && pd.GetMethod.ReturnType.IsGenericParameter)
79+
continue;
80+
if (CodegenSession.GeneralHelper.CodegenExclude(pd))
7581
continue;
7682

77-
yield return prop;
83+
yield return pd;
7884
}
7985

8086
try { typeDef = typeDef.BaseType?.CachedResolve(); }
@@ -107,6 +113,7 @@ private static bool IsExcluded(TypeDefinition typeDef, System.Type[] excludedBas
107113
return true;
108114
}
109115
}
116+
110117
//Fall through, not excluded.
111118
return false;
112119
}

Assets/FishNet/CodeGenerating/Helpers/Extension/TypeReferenceExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ internal static bool IsClassOrStruct(this TypeReference typeRef)
3232
/// </summary>
3333
/// <param name="typeRef"></param>
3434
/// <returns></returns>
35-
public static IEnumerable<PropertyDefinition> FindAllPublicProperties(this TypeReference typeRef, System.Type[] excludedBaseTypes = null, string[] excludedAssemblyPrefixes = null)
35+
public static IEnumerable<PropertyDefinition> FindAllPublicProperties(this TypeReference typeRef, bool excludeGenerics = true, System.Type[] excludedBaseTypes = null, string[] excludedAssemblyPrefixes = null)
3636
{
37-
return typeRef.CachedResolve().FindAllPublicProperties(excludedBaseTypes, excludedAssemblyPrefixes);
37+
return typeRef.CachedResolve().FindAllPublicProperties(excludeGenerics, excludedBaseTypes, excludedAssemblyPrefixes);
3838
}
3939

4040

Assets/FishNet/CodeGenerating/Helpers/ReaderGenerator.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,18 @@ private bool ReadFieldsAndProperties(MethodDefinition readerMd, ParameterDefinit
436436
objectTr = CodegenSession.ImportReference(objectTr.CachedResolve());
437437

438438
//Fields.
439-
foreach (FieldDefinition fieldDef in objectTr.FindAllPublicFields(true, true,
439+
foreach (FieldDefinition fieldDef in objectTr.FindAllPublicFields(true, true,
440440
ReaderHelper.EXCLUDED_AUTO_SERIALIZER_TYPES, ReaderHelper.EXCLUDED_ASSEMBLY_PREFIXES))
441441
{
442-
if (CodegenSession.GeneralHelper.CodegenExclude(fieldDef))
443-
continue;
444442
FieldReference importedFr = CodegenSession.ImportReference(fieldDef);
445443
if (GetReadMethod(fieldDef.FieldType, out MethodReference readMr))
446444
CodegenSession.ReaderHelper.CreateReadIntoClassOrStruct(readerMd, readerPd, readMr, objectVd, importedFr);
447445
}
448446

449447
//Properties.
450448
foreach (PropertyDefinition propertyDef in objectTr.FindAllPublicProperties(
451-
ReaderHelper.EXCLUDED_AUTO_SERIALIZER_TYPES, ReaderHelper.EXCLUDED_ASSEMBLY_PREFIXES))
449+
true, ReaderHelper.EXCLUDED_AUTO_SERIALIZER_TYPES, ReaderHelper.EXCLUDED_ASSEMBLY_PREFIXES))
452450
{
453-
if (CodegenSession.GeneralHelper.CodegenExclude(propertyDef))
454-
continue;
455451
if (GetReadMethod(propertyDef.PropertyType, out MethodReference readMr))
456452
{
457453
MethodReference setMr = CodegenSession.Module.ImportReference(propertyDef.SetMethod);
@@ -462,8 +458,8 @@ private bool ReadFieldsAndProperties(MethodDefinition readerMd, ParameterDefinit
462458
//Gets or creates writer method and outputs it. Returns true if method is found or created.
463459
bool GetReadMethod(TypeReference tr, out MethodReference readMr)
464460
{
465-
TypeReference typeRef = CodegenSession.Module.ImportIfDifferent(tr);
466-
readMr = CodegenSession.ReaderHelper.GetOrCreateFavoredReadMethodReference(typeRef, true);
461+
tr = CodegenSession.ImportReference(tr);
462+
readMr = CodegenSession.ReaderHelper.GetOrCreateFavoredReadMethodReference(tr, true);
467463
return (readMr != null);
468464
}
469465

Assets/FishNet/CodeGenerating/Helpers/WriterGenerator.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,14 @@ private bool WriteFieldsAndProperties(MethodDefinition writerMd, ParameterDefini
237237
//Fields
238238
foreach (FieldDefinition fieldDef in objectTr.FindAllPublicFields(true, true))//, WriterHelper.EXCLUDED_AUTO_SERIALIZER_TYPES))
239239
{
240-
if (CodegenSession.GeneralHelper.CodegenExclude(fieldDef))
241-
continue;
242240
if (GetWriteMethod(fieldDef.FieldType, out MethodReference writeMr))
243241
CodegenSession.WriterHelper.CreateWrite(writerMd, valuePd, fieldDef, writeMr);
244242
}
245243

246244
//Properties.
247245
foreach (PropertyDefinition propertyDef in objectTr.FindAllPublicProperties(
248-
WriterHelper.EXCLUDED_AUTO_SERIALIZER_TYPES, WriterHelper.EXCLUDED_ASSEMBLY_PREFIXES))
246+
true, WriterHelper.EXCLUDED_AUTO_SERIALIZER_TYPES, WriterHelper.EXCLUDED_ASSEMBLY_PREFIXES))
249247
{
250-
if (CodegenSession.GeneralHelper.CodegenExclude(propertyDef))
251-
continue;
252248
if (GetWriteMethod(propertyDef.PropertyType, out MethodReference writerMr))
253249
{
254250
MethodReference getMr = CodegenSession.Module.ImportReference(propertyDef.GetMethod);
@@ -259,8 +255,8 @@ private bool WriteFieldsAndProperties(MethodDefinition writerMd, ParameterDefini
259255
//Gets or creates writer method and outputs it. Returns true if method is found or created.
260256
bool GetWriteMethod(TypeReference tr, out MethodReference writeMr)
261257
{
262-
TypeReference typeRef = CodegenSession.Module.ImportIfDifferent(tr);
263-
writeMr = CodegenSession.WriterHelper.GetOrCreateFavoredWriteMethodReference(typeRef, true);
258+
tr = CodegenSession.ImportReference(tr);
259+
writeMr = CodegenSession.WriterHelper.GetOrCreateFavoredWriteMethodReference(tr, true);
264260
return (writeMr != null);
265261
}
266262

Assets/FishNet/Example/All/SceneManager/Scenes/Additive/AdditiveMain.unity

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,8 @@ GameObject:
11471147
m_Component:
11481148
- component: {fileID: 7443408887680269496}
11491149
- component: {fileID: 7443408887680269499}
1150-
- component: {fileID: 7443408887680269500}
1151-
- component: {fileID: 7443408887680269501}
1152-
- component: {fileID: 7443408887680269502}
11531150
- component: {fileID: 7443408887680269503}
1151+
- component: {fileID: 7443408887680269500}
11541152
m_Layer: 0
11551153
m_Name: 'NetworkManager '
11561154
m_TagString: Untagged
@@ -1185,56 +1183,12 @@ MonoBehaviour:
11851183
m_GameObject: {fileID: 7443408887680269498}
11861184
m_Enabled: 1
11871185
m_EditorHideFlags: 0
1188-
m_Script: {fileID: 11500000, guid: 3fdaae44044276a49a52229c1597e33b, type: 3}
1189-
m_Name:
1190-
m_EditorClassIdentifier:
1191-
_tickRate: 30
1192-
_pingInterval: 1
1193-
_timingInterval: 2
1194-
_physicsMode: 0
1195-
_maximumBufferedInputs: 15
1196-
--- !u!114 &7443408887680269501
1197-
MonoBehaviour:
1198-
m_ObjectHideFlags: 0
1199-
m_CorrespondingSourceObject: {fileID: 0}
1200-
m_PrefabInstance: {fileID: 0}
1201-
m_PrefabAsset: {fileID: 0}
1202-
m_GameObject: {fileID: 7443408887680269498}
1203-
m_Enabled: 1
1204-
m_EditorHideFlags: 0
1205-
m_Script: {fileID: 11500000, guid: 6f48f002b825cbd45a19bd96d90f9edb, type: 3}
1206-
m_Name:
1207-
m_EditorClassIdentifier:
1208-
_unreliableMTU: 1023
1209-
_attackResponseType: 1
1210-
_ipv4BindAddress:
1211-
_ipv6BindAddress:
1212-
_port: 7770
1213-
_maximumClients: 4095
1214-
_clientAddress: localhost
1215-
_timeout: 15
1216-
--- !u!114 &7443408887680269502
1217-
MonoBehaviour:
1218-
m_ObjectHideFlags: 0
1219-
m_CorrespondingSourceObject: {fileID: 0}
1220-
m_PrefabInstance: {fileID: 0}
1221-
m_PrefabAsset: {fileID: 0}
1222-
m_GameObject: {fileID: 7443408887680269498}
1223-
m_Enabled: 1
1224-
m_EditorHideFlags: 0
1225-
m_Script: {fileID: 11500000, guid: 68828c85278210948b9d50a8db3aab74, type: 3}
1186+
m_Script: {fileID: 11500000, guid: 7d331f979d46e8e4a9fc90070c596d44, type: 3}
12261187
m_Name:
12271188
m_EditorClassIdentifier:
1228-
_authenticator: {fileID: 0}
1229-
SpawnPacking:
1230-
Position: 0
1231-
Rotation: 2
1232-
Scale: 2
1233-
_changeFrameRate: 1
1234-
_frameRate: 9999
1235-
_shareIds: 1
1236-
_startOnHeadless: 1
1237-
_limitClientMTU: 1
1189+
_setHostVisibility: 1
1190+
_defaultConditions:
1191+
- {fileID: 11400000, guid: 2033f54fd2794464bae08fa5a55c8996, type: 2}
12381192
--- !u!114 &7443408887680269503
12391193
MonoBehaviour:
12401194
m_ObjectHideFlags: 0

Assets/FishNet/Runtime/Editor/CodeStripping.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Xml.Serialization;
66

77
#if UNITY_EDITOR
8+
using FishNet.Editing.PrefabCollectionGenerator;
89
using UnityEditor.Compilation;
910
using UnityEditor.Build.Reporting;
1011
using UnityEditor;
@@ -16,7 +17,7 @@ namespace FishNet.Configuring
1617

1718

1819
public class CodeStripping
19-
20+
2021
{
2122

2223
/// <summary>
@@ -35,7 +36,7 @@ public static bool RemoveServerLogic
3536
{
3637
get
3738
{
38-
39+
3940

4041
/* This is to protect non pro users from enabling this
4142
* without the extra logic code. */
@@ -51,7 +52,7 @@ public static bool StripBuild
5152
{
5253
get
5354
{
54-
55+
5556

5657
/* This is to protect non pro users from enabling this
5758
* without the extra logic code. */
@@ -61,7 +62,52 @@ public static bool StripBuild
6162
}
6263
}
6364

64-
65+
private static object _compilationContext;
66+
public int callbackOrder => 0;
67+
#if UNITY_EDITOR
68+
69+
public void OnPreprocessBuild(BuildReport report)
70+
{
71+
Generator.IgnorePostProcess = true;
72+
Generator.GenerateFull();
73+
CompilationPipeline.compilationStarted += CompilationPipelineOnCompilationStarted;
74+
CompilationPipeline.compilationFinished += CompilationPipelineOnCompilationFinished;
75+
76+
77+
}
78+
/* Solution for builds ending with errors and not triggering OnPostprocessBuild.
79+
* Link: https://gamedev.stackexchange.com/questions/181611/custom-build-failure-callback
80+
*/
81+
private void CompilationPipelineOnCompilationStarted(object compilationContext)
82+
{
83+
_compilationContext = compilationContext;
84+
}
85+
86+
private void CompilationPipelineOnCompilationFinished(object compilationContext)
87+
{
88+
if (compilationContext != _compilationContext)
89+
return;
90+
91+
_compilationContext = null;
92+
93+
CompilationPipeline.compilationStarted -= CompilationPipelineOnCompilationStarted;
94+
CompilationPipeline.compilationFinished -= CompilationPipelineOnCompilationFinished;
95+
96+
BuildingEnded();
97+
}
98+
99+
private void BuildingEnded()
100+
{
101+
102+
103+
Generator.IgnorePostProcess = false;
104+
}
105+
106+
public void OnPostprocessBuild(BuildReport report)
107+
{
108+
BuildingEnded();
109+
}
110+
#endif
65111
}
66112

67113
}

Assets/FishNet/Runtime/InstanceFinder.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FishNet.Managing.Logging;
55
using FishNet.Managing.Scened;
66
using FishNet.Managing.Server;
7+
using FishNet.Managing.Statistic;
78
using FishNet.Managing.Timing;
89
using FishNet.Managing.Transporting;
910
using FishNet.Utility;
@@ -125,7 +126,17 @@ public static RollbackManager RollbackManager
125126
return (nm == null) ? null : nm.RollbackManager;
126127
}
127128
}
128-
129+
/// <summary>
130+
/// Returns the first instance of StatisticsManager.
131+
/// </summary>
132+
public static StatisticsManager StatisticsManager
133+
{
134+
get
135+
{
136+
NetworkManager nm = NetworkManager;
137+
return (nm == null) ? null : nm.StatisticsManager;
138+
}
139+
}
129140
/// <summary>
130141
/// True if the server is active.
131142
/// </summary>

Assets/FishNet/Runtime/Managing/Client/ClientManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ private void ParseReceived(ClientReceivedDataArgs args)
256256
#endif
257257

258258
ArraySegment<byte> segment = args.Data;
259+
NetworkManager.StatisticsManager.NetworkTraffic.LocalClientReceivedData((ulong)segment.Count);
259260
if (segment.Count <= TransportManager.TICK_BYTES)
260261
return;
261262

0 commit comments

Comments
 (0)