mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: weaver support array of custom types (#1470)
* WIP * Proposed Rearrange * Rearrange Code * Unit test for PR * unit test * unit test * Update TestingScriptableObjectArraySerialization.cs Improving code * Update TestingScriptableObjectArraySerialization.cs * Remove blank lines * remove blank space * Remove leftover log Co-authored-by: MrGadget <chris@clevertech.net> Co-authored-by: Uchiha I_A_H_I <jkaran.sharma101@gmail.com>
This commit is contained in:
parent
1736bb0c42
commit
d0b0bc92bc
@ -27,6 +27,19 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
|
|||||||
return foundFunc;
|
return foundFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MethodDefinition newReaderFunc;
|
||||||
|
|
||||||
|
// Arrays are special, if we resolve them, we get teh element type,
|
||||||
|
// so the following ifs might choke on it for scriptable objects
|
||||||
|
// or other objects that require a custom serializer
|
||||||
|
// thus check if it is an array and skip all the checks.
|
||||||
|
if (variable.IsArray)
|
||||||
|
{
|
||||||
|
newReaderFunc = GenerateArrayReadFunc(variable, recursionCount);
|
||||||
|
RegisterReadFunc(variable.FullName, newReaderFunc);
|
||||||
|
return newReaderFunc;
|
||||||
|
}
|
||||||
|
|
||||||
TypeDefinition td = variable.Resolve();
|
TypeDefinition td = variable.Resolve();
|
||||||
if (td == null)
|
if (td == null)
|
||||||
{
|
{
|
||||||
@ -60,13 +73,7 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDefinition newReaderFunc;
|
if (td.IsEnum)
|
||||||
|
|
||||||
if (variable.IsArray)
|
|
||||||
{
|
|
||||||
newReaderFunc = GenerateArrayReadFunc(variable, recursionCount);
|
|
||||||
}
|
|
||||||
else if (td.IsEnum)
|
|
||||||
{
|
{
|
||||||
return GetReadFunc(td.GetEnumUnderlyingType(), recursionCount);
|
return GetReadFunc(td.GetEnumUnderlyingType(), recursionCount);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,19 @@ public static MethodReference GetWriteFunc(TypeReference variable, int recursion
|
|||||||
return foundFunc;
|
return foundFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MethodDefinition newWriterFunc;
|
||||||
|
|
||||||
|
// Arrays are special, if we resolve them, we get the element type,
|
||||||
|
// so the following ifs might choke on it for scriptable objects
|
||||||
|
// or other objects that require a custom serializer
|
||||||
|
// thus check if it is an array and skip all the checks.
|
||||||
|
if (variable.IsArray)
|
||||||
|
{
|
||||||
|
newWriterFunc = GenerateArrayWriteFunc(variable, recursionCount);
|
||||||
|
RegisterWriteFunc(variable.FullName, newWriterFunc);
|
||||||
|
return newWriterFunc;
|
||||||
|
}
|
||||||
|
|
||||||
if (variable.IsByReference)
|
if (variable.IsByReference)
|
||||||
{
|
{
|
||||||
// error??
|
// error??
|
||||||
@ -61,13 +74,7 @@ public static MethodReference GetWriteFunc(TypeReference variable, int recursion
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDefinition newWriterFunc;
|
if (variable.Resolve().IsEnum)
|
||||||
|
|
||||||
if (variable.IsArray)
|
|
||||||
{
|
|
||||||
newWriterFunc = GenerateArrayWriteFunc(variable, recursionCount);
|
|
||||||
}
|
|
||||||
else if (variable.Resolve().IsEnum)
|
|
||||||
{
|
{
|
||||||
return GetWriteFunc(variable.Resolve().GetEnumUnderlyingType(), recursionCount);
|
return GetWriteFunc(variable.Resolve().GetEnumUnderlyingType(), recursionCount);
|
||||||
}
|
}
|
||||||
|
@ -728,5 +728,12 @@ public void MessageMemberInterface()
|
|||||||
Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Cannot generate writer for interface MirrorTest.SuperCoolInterface. Use a concrete type or provide a custom writer"));
|
Assert.That(weaverErrors, Contains.Item("Mirror.Weaver error: Cannot generate writer for interface MirrorTest.SuperCoolInterface. Use a concrete type or provide a custom writer"));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestingScriptableObjectArraySerialization()
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log(string.Join("\n",weaverErrors));
|
||||||
|
Assert.That(CompilationFinishedHook.WeaveFailed, Is.False);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
using Mirror;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MirrorTest
|
||||||
|
{
|
||||||
|
public static class CustomSerializer
|
||||||
|
{
|
||||||
|
public static void Writedata(this NetworkWriter writer, Data arg)
|
||||||
|
{
|
||||||
|
writer.WriteInt32(arg.Var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Data Readdata(this NetworkReader reader)
|
||||||
|
{
|
||||||
|
return new Data
|
||||||
|
{
|
||||||
|
Var1 = reader.ReadInt32()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Data : ScriptableObject
|
||||||
|
{
|
||||||
|
public int Var1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PlayerScript : NetworkBehaviour
|
||||||
|
{
|
||||||
|
[Command]
|
||||||
|
public void
|
||||||
|
CmdwriteArraydata(
|
||||||
|
Data[] arg) //This gonna give error saying-- Mirror.Weaver error: Cannot generate writer for scriptable object Data[]. Use a supported type or provide a custom writer
|
||||||
|
{
|
||||||
|
|
||||||
|
//some code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user