Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supports scriptable objects (#1471)
* feat: supports scriptable objects Now you can pass scriptable objects in commands, rpcs and syncvars For example: ```cs class Weapon: ScriptableObject { public string name; public string description; public int damage; ... } class Player : NetworkBehaviour { [SyncVar] Weapon equipped; ... } ``` Scriptable objects will be created in the client using ScriptableObject.CreateInstance. If users want something else they can provide a custom serializer (that has not changed) * fix: remove scriptableobject error Tests The test that checks that scrscriptableobjects give error is no longer valid
- Loading branch information
Showing
8 changed files
with
85 additions
and
49 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
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,44 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace Mirror.Tests | ||
{ | ||
internal class MyScriptableObject : ScriptableObject | ||
{ | ||
public int someData; | ||
} | ||
|
||
[TestFixture] | ||
public class ScriptableObjectWriterTest | ||
{ | ||
|
||
// ArraySegment<byte> is a special case, optimized for no copy and no allocation | ||
// other types are generated by the weaver | ||
|
||
|
||
class ScriptableObjectMessage : MessageBase | ||
{ | ||
public MyScriptableObject scriptableObject; | ||
} | ||
|
||
[Test] | ||
public void TestWriteScriptableObject() | ||
{ | ||
ScriptableObjectMessage message = new ScriptableObjectMessage | ||
{ | ||
scriptableObject = ScriptableObject.CreateInstance<MyScriptableObject>() | ||
}; | ||
|
||
message.scriptableObject.someData = 10; | ||
|
||
byte[] data = MessagePacker.Pack(message); | ||
|
||
ScriptableObjectMessage unpacked = MessagePacker.Unpack<ScriptableObjectMessage>(data); | ||
|
||
Assert.That(unpacked.scriptableObject, Is.Not.Null); | ||
Assert.That(unpacked.scriptableObject.someData, Is.EqualTo(10)); | ||
} | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
31 changes: 0 additions & 31 deletions
31
Assets/Mirror/Tests/Editor/WeaverTests~/SyncVarsDerivedScriptableObject.cs
This file was deleted.
Oops, something went wrong.