diff --git a/Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs b/Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs index d4a836125..e4ac1cbe9 100644 --- a/Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs +++ b/Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs @@ -14,9 +14,13 @@ public void SetHostname(string hostname) public ChatWindow chatWindow; - public class CreatePlayerMessage : MessageBase + public class CreatePlayerMessage : IMessageBase { public string name; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } public override void OnStartServer() diff --git a/Assets/Mirror/Runtime/Messages.cs b/Assets/Mirror/Runtime/Messages.cs index 49f4705f9..32e4905a1 100644 --- a/Assets/Mirror/Runtime/Messages.cs +++ b/Assets/Mirror/Runtime/Messages.cs @@ -10,15 +10,6 @@ public interface IMessageBase void Serialize(NetworkWriter writer); } - public abstract class MessageBase : IMessageBase - { - // De-serialize the contents of the reader into this message - public virtual void Deserialize(NetworkReader reader) { } - - // Serialize the contents of this message into the writer - public virtual void Serialize(NetworkWriter writer) { } - } - #region Public System Messages public struct ErrorMessage : IMessageBase { diff --git a/Assets/Mirror/Tests/Editor/BasicAuthenticatorTest.cs b/Assets/Mirror/Tests/Editor/BasicAuthenticatorTest.cs deleted file mode 100644 index d31ceb21a..000000000 --- a/Assets/Mirror/Tests/Editor/BasicAuthenticatorTest.cs +++ /dev/null @@ -1,68 +0,0 @@ -using NUnit.Framework; - -namespace Mirror.Tests -{ - [TestFixture] - public class BasicAuthenticatorTest - { - public class AuthRequestMessage : MessageBase - { - public string authUsername; - public string authPassword; - } - - public class AuthResponseMessage : MessageBase - { - public byte code; - public string message; - } - - [Test] - public void AuthRequestMessageTest() - { - // try setting value with constructor - AuthRequestMessage message = new AuthRequestMessage - { - authUsername = "abc", - authPassword = "123" - }; - Assert.That(message.authUsername, Is.EqualTo("abc")); - Assert.That(message.authPassword, Is.EqualTo("123")); - - // serialize - NetworkWriter writer = new NetworkWriter(); - message.Serialize(writer); - byte[] writerData = writer.ToArray(); - - // try deserialize - AuthRequestMessage fresh = new AuthRequestMessage(); - fresh.Deserialize(new NetworkReader(writerData)); - Assert.That(fresh.authUsername, Is.EqualTo("abc")); - Assert.That(fresh.authPassword, Is.EqualTo("123")); - } - - [Test] - public void AuthResponseMessageTest() - { - // try setting value with constructor - AuthResponseMessage message = new AuthResponseMessage - { - code = 123, - message = "abc" - }; - Assert.That(message.code, Is.EqualTo(123)); - Assert.That(message.message, Is.EqualTo("abc")); - - // serialize - NetworkWriter writer = new NetworkWriter(); - message.Serialize(writer); - byte[] writerData = writer.ToArray(); - - // try deserialize - AuthResponseMessage fresh = new AuthResponseMessage(); - fresh.Deserialize(new NetworkReader(writerData)); - Assert.That(fresh.code, Is.EqualTo(123)); - Assert.That(fresh.message, Is.EqualTo("abc")); - } - } -} diff --git a/Assets/Mirror/Tests/Editor/BasicAuthenticatorTest.cs.meta b/Assets/Mirror/Tests/Editor/BasicAuthenticatorTest.cs.meta deleted file mode 100644 index 352bb836d..000000000 --- a/Assets/Mirror/Tests/Editor/BasicAuthenticatorTest.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 14742e780e150894b983a54d36a3cdb6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Mirror/Tests/Editor/CustomRWTest.cs b/Assets/Mirror/Tests/Editor/CustomRWTest.cs index 38a8cd256..ae3907d09 100644 --- a/Assets/Mirror/Tests/Editor/CustomRWTest.cs +++ b/Assets/Mirror/Tests/Editor/CustomRWTest.cs @@ -23,7 +23,7 @@ public static void WriteQuest(this NetworkWriter writer, MockQuest quest) { writer.WriteInt32(quest.Id); } - public static MockQuest WriteQuest(this NetworkReader reader) + public static MockQuest ReadQuest(this NetworkReader reader) { return new MockQuest(reader.ReadInt32()); } @@ -33,9 +33,13 @@ public static MockQuest WriteQuest(this NetworkReader reader) public class CustomRWTest { - class QuestMessage : MessageBase + struct QuestMessage : IMessageBase { public MockQuest quest; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] diff --git a/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs b/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs index de3308535..7bae16411 100644 --- a/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs +++ b/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs @@ -23,19 +23,40 @@ public static EnumReadWriteTests.MyCustomEnum ReadMyCustomEnum(this NetworkReade } public class EnumReadWriteTests { - public class ByteMessage : MessageBase { public MyByteEnum byteEnum; } + public struct ByteMessage : IMessageBase + { + public MyByteEnum byteEnum; + + // Weaver auto generates serialization + public void Deserialize(NetworkReader reader) {} + public void Serialize(NetworkWriter writer) {} + } public enum MyByteEnum : byte { A, B, C, D } - public class ShortMessage : MessageBase { public MyShortEnum shortEnum; } + public struct ShortMessage : IMessageBase + { + public MyShortEnum shortEnum; + + // Weaver auto generates serialization + public void Deserialize(NetworkReader reader) {} + public void Serialize(NetworkWriter writer) {} + } public enum MyShortEnum : short { E, F, G, H } - public class CustomMessage : MessageBase { public MyCustomEnum customEnum; } + public struct CustomMessage : IMessageBase + { + public MyCustomEnum customEnum; + + // Weaver auto generates serialization + public void Deserialize(NetworkReader reader) {} + public void Serialize(NetworkWriter writer) {} + } public enum MyCustomEnum { @@ -76,7 +97,7 @@ public void CustomWriterIsUsedForEnum() // custom writer should write N if it sees O Assert.That(clientMsg.customEnum, Is.EqualTo(MyCustomEnum.N)); } - T SerializeAndDeserializeMessage(T msg) where T : MessageBase, new() + T SerializeAndDeserializeMessage(T msg) where T : IMessageBase, new() { NetworkWriter writer = new NetworkWriter(); diff --git a/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs b/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs index 171e37775..14566578b 100644 --- a/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs +++ b/Assets/Mirror/Tests/Editor/Generated/CollectionWriterTests.gen.cs @@ -10,9 +10,13 @@ namespace Mirror.Tests.Generated.CollectionWriters public class Array_int_Test { - class Message : MessageBase + struct Message : IMessageBase { public int[] collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -74,9 +78,13 @@ public void SendsData() public class Array_string_Test { - class Message : MessageBase + struct Message : IMessageBase { public string[] collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -138,9 +146,13 @@ public void SendsData() public class Array_Vector3_Test { - class Message : MessageBase + struct Message : IMessageBase { public Vector3[] collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -202,9 +214,13 @@ public void SendsData() public class Array_FloatStringStruct_Test { - class Message : MessageBase + struct Message : IMessageBase { public FloatStringStruct[] collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -266,9 +282,13 @@ public void SendsData() public class Array_ClassWithNoConstructor_Test { - class Message : MessageBase + struct Message : IMessageBase { public ClassWithNoConstructor[] collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -330,9 +350,13 @@ public void SendsData() public class ArraySegment_int_Test { - class Message : MessageBase + struct Message : IMessageBase { public ArraySegment collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -408,9 +432,13 @@ public void SendsData() public class ArraySegment_string_Test { - class Message : MessageBase + struct Message : IMessageBase { public ArraySegment collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -486,9 +514,13 @@ public void SendsData() public class ArraySegment_Vector3_Test { - class Message : MessageBase + struct Message : IMessageBase { public ArraySegment collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -564,9 +596,13 @@ public void SendsData() public class ArraySegment_FloatStringStruct_Test { - class Message : MessageBase + struct Message : IMessageBase { public ArraySegment collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -642,9 +678,13 @@ public void SendsData() public class ArraySegment_ClassWithNoConstructor_Test { - class Message : MessageBase + struct Message : IMessageBase { public ArraySegment collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -720,9 +760,13 @@ public void SendsData() public class List_int_Test { - class Message : MessageBase + struct Message : IMessageBase { public List collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -784,9 +828,13 @@ public void SendsData() public class List_string_Test { - class Message : MessageBase + struct Message : IMessageBase { public List collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -848,9 +896,13 @@ public void SendsData() public class List_Vector3_Test { - class Message : MessageBase + struct Message : IMessageBase { public List collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -912,9 +964,13 @@ public void SendsData() public class List_FloatStringStruct_Test { - class Message : MessageBase + struct Message : IMessageBase { public List collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] @@ -976,9 +1032,13 @@ public void SendsData() public class List_ClassWithNoConstructor_Test { - class Message : MessageBase + struct Message : IMessageBase { public List collection; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } [Test] diff --git a/Assets/Mirror/Tests/Editor/MessageBaseTests.cs b/Assets/Mirror/Tests/Editor/MessageBaseTests.cs index 7cd1d7b4f..8b1378917 100644 --- a/Assets/Mirror/Tests/Editor/MessageBaseTests.cs +++ b/Assets/Mirror/Tests/Editor/MessageBaseTests.cs @@ -1,190 +1 @@ -using NUnit.Framework; -namespace Mirror.Tests.MessageTests -{ - struct TestMessage : IMessageBase - { - public int IntValue; - public string StringValue; - public double DoubleValue; - - public TestMessage(int i, string s, double d) - { - IntValue = i; - StringValue = s; - DoubleValue = d; - } - - public void Deserialize(NetworkReader reader) - { - IntValue = reader.ReadInt32(); - StringValue = reader.ReadString(); - DoubleValue = reader.ReadDouble(); - } - - public void Serialize(NetworkWriter writer) - { - writer.WriteInt32(IntValue); - writer.WriteString(StringValue); - writer.WriteDouble(DoubleValue); - } - } - - struct StructWithEmptyMethodMessage : IMessageBase - { - public int IntValue; - public string StringValue; - public double DoubleValue; - - // Mirror will fill out these empty methods - public void Deserialize(NetworkReader reader) { } - public void Serialize(NetworkWriter writer) { } - } - - class ClassWithoutBaseMessage : IMessageBase - { - public int[] array; - - // Mirror will fill out these empty methods - public void Deserialize(NetworkReader reader) { } - public void Serialize(NetworkWriter writer) { } - } - - abstract class AbstractMessage : IMessageBase - { - public abstract void Deserialize(NetworkReader reader); - public abstract void Serialize(NetworkWriter writer); - } - - class OverrideMessage : AbstractMessage - { - public int someValue; - - // Mirror will fill out these empty methods - public override void Serialize(NetworkWriter writer) { } - public override void Deserialize(NetworkReader reader) { } - } - - class Layer1Message : IMessageBase - { - public int value1; - - // Mirror will fill out these empty methods - public virtual void Serialize(NetworkWriter writer) { } - public virtual void Deserialize(NetworkReader reader) { } - } - - class Layer2Message : Layer1Message - { - public int value2; - } - class Layer3Message : Layer2Message - { - public int value3; - } - - class NullableObject - { - public int id = 3; - } - - class NullableObjectMessage : MessageBase - { - public string name; - public NullableObject nullObj; - } - - [TestFixture] - public class MessageBaseTests - { - [Test] - public void StructWithMethods() - { - byte[] arr = MessagePackerTest.PackToByteArray(new TestMessage(1, "2", 3.3)); - TestMessage t = MessagePacker.Unpack(arr); - - Assert.AreEqual(1, t.IntValue); - } - - [Test] - public void StructWithEmptyMethods() - { - byte[] arr = MessagePackerTest.PackToByteArray(new StructWithEmptyMethodMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 }); - StructWithEmptyMethodMessage t = MessagePacker.Unpack(arr); - - Assert.AreEqual(1, t.IntValue); - Assert.AreEqual("2", t.StringValue); - Assert.AreEqual(3.3, t.DoubleValue); - } - - [Test] - public void ClassWithEmptyMethods() - { - ClassWithoutBaseMessage intMessage = new ClassWithoutBaseMessage - { - array = new[] { 3, 4, 5 } - }; - - byte[] data = MessagePackerTest.PackToByteArray(intMessage); - - ClassWithoutBaseMessage unpacked = MessagePacker.Unpack(data); - - Assert.That(unpacked.array, Is.EquivalentTo(new int[] { 3, 4, 5 })); - } - - [Test] - public void AbstractBaseClassWorks() - { - const int value = 10; - OverrideMessage intMessage = new OverrideMessage - { - someValue = value - }; - - byte[] data = MessagePackerTest.PackToByteArray(intMessage); - - OverrideMessage unpacked = MessagePacker.Unpack(data); - - Assert.That(unpacked.someValue, Is.EqualTo(value)); - } - - [Test] - public void MessageInheirtanceWorksWithMultipleLayers() - { - const int value1 = 10; - const int value2 = 13; - const int value3 = 15; - Layer3Message intMessage = new Layer3Message - { - value1 = value1, - value2 = value2, - value3 = value3 - }; - - byte[] data = MessagePackerTest.PackToByteArray(intMessage); - - Layer3Message unpacked = MessagePacker.Unpack(data); - - Assert.That(unpacked.value1, Is.EqualTo(value1)); - Assert.That(unpacked.value2, Is.EqualTo(value2)); - Assert.That(unpacked.value3, Is.EqualTo(value3)); - } - - [Test] - public void NullObjectMessageTest() - { - NullableObjectMessage nullableObjectMessage = new NullableObjectMessage - { - name = "pepe", - nullObj = null - }; - - byte[] data = MessagePackerTest.PackToByteArray(nullableObjectMessage); - - NullableObjectMessage unpacked = MessagePacker.Unpack(data); - - Assert.That(unpacked.name, Is.EqualTo("pepe")); - Assert.That(unpacked.nullObj, Is.Null); - } - } -} diff --git a/Assets/Mirror/Tests/Editor/MessageBaseTests.cs.meta b/Assets/Mirror/Tests/Editor/MessageBaseTests.cs.meta deleted file mode 100644 index 14117769c..000000000 --- a/Assets/Mirror/Tests/Editor/MessageBaseTests.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ecf93fcf0386fee4e85f981d5ca9259d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs b/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs deleted file mode 100644 index 39c88fc45..000000000 --- a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs +++ /dev/null @@ -1,127 +0,0 @@ -using NUnit.Framework; - -namespace Mirror.Tests.MessageTests -{ - class ParentMessage : MessageBase - { - public int parentValue; - } - - class ChildMessage : ParentMessage - { - public int childValue; - } - - - public abstract class RequestMessageBase : MessageBase - { - public int responseId = 0; - } - public class ResponseMessage : RequestMessageBase - { - public int state; - public string message = ""; - public int errorCode = 0; // optional for error codes - } - - //reverseOrder to test this https://github.com/vis2k/Mirror/issues/1925 - public class ResponseMessageReverse : RequestMessageBaseReverse - { - public int state; - public string message = ""; - public int errorCode = 0; // optional for error codes - } - public abstract class RequestMessageBaseReverse : MessageBase - { - public int responseId = 0; - } - - [TestFixture] - public class MessageInheritanceTest - { - [Test] - public void SendsVauesInParentAndChildClass() - { - NetworkWriter writer = new NetworkWriter(); - - writer.WriteMessage(new ChildMessage - { - parentValue = 3, - childValue = 4 - }); - - byte[] arr = writer.ToArray(); - - NetworkReader reader = new NetworkReader(arr); - ChildMessage received = new ChildMessage(); - received.Deserialize(reader); - - Assert.AreEqual(3, received.parentValue); - Assert.AreEqual(4, received.childValue); - - int writeLength = writer.Length; - int readLength = reader.Position; - Assert.That(writeLength == readLength, $"OnSerializeAll and OnDeserializeAll calls write the same amount of data\n writeLength={writeLength}\n readLength={readLength}"); - } - - [Test] - public void SendsVauesWhenUsingAbstractClass() - { - NetworkWriter writer = new NetworkWriter(); - - const int state = 2; - const string message = "hello world"; - const int responseId = 5; - writer.WriteMessage(new ResponseMessage - { - state = state, - message = message, - responseId = responseId, - }); - - byte[] arr = writer.ToArray(); - - NetworkReader reader = new NetworkReader(arr); - ResponseMessage received = new ResponseMessage(); - received.Deserialize(reader); - - Assert.AreEqual(state, received.state); - Assert.AreEqual(message, received.message); - Assert.AreEqual(responseId, received.responseId); - - int writeLength = writer.Length; - int readLength = reader.Position; - Assert.That(writeLength == readLength, $"OnSerializeAll and OnDeserializeAll calls write the same amount of data\n writeLength={writeLength}\n readLength={readLength}"); - } - - [Test] - public void SendsVauesWhenUsingAbstractClassReverseDefineOrder() - { - NetworkWriter writer = new NetworkWriter(); - - const int state = 2; - const string message = "hello world"; - const int responseId = 5; - writer.WriteMessage(new ResponseMessageReverse - { - state = state, - message = message, - responseId = responseId, - }); - - byte[] arr = writer.ToArray(); - - NetworkReader reader = new NetworkReader(arr); - ResponseMessageReverse received = new ResponseMessageReverse(); - received.Deserialize(reader); - - Assert.AreEqual(state, received.state); - Assert.AreEqual(message, received.message); - Assert.AreEqual(responseId, received.responseId); - - int writeLength = writer.Length; - int readLength = reader.Position; - Assert.That(writeLength == readLength, $"OnSerializeAll and OnDeserializeAll calls write the same amount of data\n writeLength={writeLength}\n readLength={readLength}"); - } - } -} diff --git a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta b/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta deleted file mode 100644 index 4e78acae8..000000000 --- a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 808855b645f9843d2b3077ab1304b2b3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs b/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs index 1f3ff4e49..71f26c3d9 100644 --- a/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs +++ b/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs @@ -16,9 +16,13 @@ public class ScriptableObjectWriterTest // other types are generated by the weaver - class ScriptableObjectMessage : MessageBase + struct ScriptableObjectMessage : IMessageBase { public MyScriptableObject scriptableObject; + + // Weaver auto generates serialization + public void Deserialize(NetworkReader reader) {} + public void Serialize(NetworkWriter writer) {} } [Test] diff --git a/Assets/Mirror/Tests/Editor/StructMessagesTests.cs b/Assets/Mirror/Tests/Editor/StructMessagesTests.cs index 51f475a2e..25d5e7898 100644 --- a/Assets/Mirror/Tests/Editor/StructMessagesTests.cs +++ b/Assets/Mirror/Tests/Editor/StructMessagesTests.cs @@ -6,7 +6,7 @@ public struct SomeStructMessage : IMessageBase { public int someValue; - // Mirror will automatically implement message that are empty + // Weaver will generate serialization public void Serialize(NetworkWriter writer) { } public void Deserialize(NetworkReader reader) { } } diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests.cs index e340d383d..0fe9613fd 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests.cs @@ -10,19 +10,6 @@ public void MessageValid() IsSuccess(); } - [Test] - public void MessageWithBaseClass() - { - IsSuccess(); - } - - [Test] - public void MessageSelfReferencing() - { - HasError("MessageSelfReferencing has field selfReference that references itself", - "WeaverMessageTests.MessageSelfReferencing.MessageSelfReferencing WeaverMessageTests.MessageSelfReferencing.MessageSelfReferencing::selfReference"); - } - [Test] public void MessageMemberGeneric() { @@ -41,12 +28,6 @@ public void MessageMemberInterface() "WeaverMessageTests.MessageMemberInterface.SuperCoolInterface WeaverMessageTests.MessageMemberInterface.MessageMemberInterface::invalidField"); } - [Test] - public void MessageNestedInheritance() - { - IsSuccess(); - } - [Test] public void AbstractMessageMethods() { diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberGeneric.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberGeneric.cs index 578e42cbd..bb0101a65 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberGeneric.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberGeneric.cs @@ -6,7 +6,7 @@ namespace WeaverMessageTests.MessageMemberGeneric { class HasGeneric { } - class MessageMemberGeneric : MessageBase + struct MessageMemberGeneric : IMessageBase { public uint netId; public Guid assetId; @@ -14,5 +14,9 @@ class MessageMemberGeneric : MessageBase public Quaternion rotation; public HasGeneric invalidField; public byte[] payload; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } } diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberInterface.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberInterface.cs index dcdfcc762..87294c7db 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberInterface.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageMemberInterface.cs @@ -6,7 +6,7 @@ namespace WeaverMessageTests.MessageMemberInterface { interface SuperCoolInterface { } - class MessageMemberInterface : MessageBase + struct MessageMemberInterface : IMessageBase { public uint netId; public Guid assetId; @@ -14,5 +14,9 @@ class MessageMemberInterface : MessageBase public Quaternion rotation; public SuperCoolInterface invalidField; public byte[] payload; + + // Weaver will generate serialization + public void Serialize(NetworkWriter writer) {} + public void Deserialize(NetworkReader reader) {} } } diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageNestedInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageNestedInheritance.cs deleted file mode 100644 index b3a785009..000000000 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageNestedInheritance.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Mirror; - -namespace WeaverMessageTests.MessageNestedInheritance -{ - public class Message : MessageBase - { - public class Request : Message - { - - } - - public class Response : Message - { - public int errorCode; - } - } -} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageSelfReferencing.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageSelfReferencing.cs deleted file mode 100644 index a2e0ac1a3..000000000 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageSelfReferencing.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using Mirror; -using UnityEngine; - -namespace WeaverMessageTests.MessageSelfReferencing -{ - class MessageSelfReferencing : MessageBase - { - public uint netId; - public Guid assetId; - public Vector3 position; - public Quaternion rotation; - public MessageSelfReferencing selfReference = new MessageSelfReferencing(); - public byte[] payload; - } -} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageValid.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageValid.cs index 0a5fcf3be..9e58644a4 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageValid.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageValid.cs @@ -4,7 +4,7 @@ namespace WeaverMessageTests.MessageValid { - class MessageValid : MessageBase + struct MessageValid : IMessageBase { public uint netId; public Guid assetId; @@ -12,7 +12,7 @@ class MessageValid : MessageBase public Quaternion rotation; public byte[] payload; - public override void Deserialize(NetworkReader reader) + public void Deserialize(NetworkReader reader) { netId = reader.ReadPackedUInt32(); assetId = reader.ReadGuid(); @@ -21,7 +21,7 @@ public override void Deserialize(NetworkReader reader) payload = reader.ReadBytesAndSize(); } - public override void Serialize(NetworkWriter writer) + public void Serialize(NetworkWriter writer) { writer.WritePackedUInt32(netId); writer.WriteGuid(assetId); diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageWithBaseClass.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageWithBaseClass.cs deleted file mode 100644 index 1fc0289db..000000000 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverMessageTests~/MessageWithBaseClass.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Mirror; -using UnityEngine; - -namespace WeaverMessageTests.MessageWithBaseClass -{ - class MessageWithBaseClass : SomeBaseMessage - { - public uint netId; - public Guid assetId; - public Vector3 position; - public Quaternion rotation; - public byte[] payload; - } - - class SomeBaseMessage : MessageBase - { - public int myExtraType; - } -}