-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adding error for generated read writer for abstract class (#2191)
* fix adding error for gernated read writer for abstract class weaver can not initialize class abstract class so cant not create a reader this gives a helpful error telling the server to make a custom reader * adding tests for error message * fixing typo * renaming * fixing expected error messages
- Loading branch information
1 parent
c9a9f92
commit a9d21ea
Showing
7 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../Editor/Weaver/WeaverGeneratedReaderWriterTests~/CanUseCustomReadWriteForAbstractClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Mirror; | ||
|
||
namespace GeneratedReaderWriter.CanUseCustomReadWriteForAbstractClass | ||
{ | ||
public class CanUseCustomReadWriteForAbstractClass : NetworkBehaviour | ||
{ | ||
[ClientRpc] | ||
public void RpcDoSomething(DataBase data) | ||
{ | ||
// empty | ||
} | ||
} | ||
|
||
public abstract class DataBase | ||
{ | ||
public int someField; | ||
public abstract int id { get; } | ||
} | ||
|
||
public class SomeData : DataBase | ||
{ | ||
public float anotherField; | ||
public override int id => 1; | ||
} | ||
|
||
public static class DataReadWrite | ||
{ | ||
public static void WriteData(this NetworkWriter writer, DataBase data) | ||
{ | ||
writer.WriteInt32(data.id); | ||
// write extra stuff depending on id here | ||
writer.WriteInt32(data.someField); | ||
|
||
if (data.id == 1) | ||
{ | ||
SomeData someData = (SomeData)data; | ||
writer.WriteSingle(someData.anotherField); | ||
} | ||
} | ||
|
||
public static DataBase ReadData(this NetworkReader reader) | ||
{ | ||
int id = reader.ReadInt32(); | ||
|
||
int someField = reader.ReadInt32(); | ||
DataBase data = null; | ||
if (data.id == 1) | ||
{ | ||
SomeData someData = new SomeData() | ||
{ | ||
someField = someField | ||
}; | ||
// read extra stuff depending on id here | ||
|
||
someData.anotherField = reader.ReadSingle(); | ||
|
||
data = someData; | ||
} | ||
return data; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...Tests/Editor/Weaver/WeaverGeneratedReaderWriterTests~/GivesErrorWhenUsingAbstractClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Mirror; | ||
|
||
namespace GeneratedReaderWriter.GivesErrorWhenUsingAbstractClass | ||
{ | ||
public class GivesErrorWhenUsingAbstractClass : NetworkBehaviour | ||
{ | ||
[ClientRpc] | ||
public void RpcDoSomething(DataBase data) | ||
{ | ||
// empty | ||
} | ||
} | ||
|
||
public abstract class DataBase | ||
{ | ||
public int someField; | ||
public abstract int id { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters