Class GenerateSerializationForGenericParameterAttribute
Marks a generic parameter in this class as a type that should be serialized through
NetworkVariableSerialization<T>. This enables the use of the following methods to support
serialization within a Network Variable type:
NetworkVariableSerialization<T>.Read(FastBufferReader, ref T)
NetworkVariableSerialization<T>.Write(FastBufferWriter, ref T)
NetworkVariableSerialization<T>.AreEqual
NetworkVariableSerialization<T>.Duplicate(in T, ref T)
The parameter is indicated by index (and is 0-indexed); for example:
[SerializesGenericParameter(1)]
public class MyClass<TTypeOne, TTypeTwo>
{
}
This tells the code generation for NetworkVariableSerialization<T> to generate serialized code for TTypeTwo (generic parameter 1).
Note that this is primarily intended to support subtypes of NetworkVariableBase, and as such, the type resolution is done by examining fields of NetworkBehaviour subclasses. If your type is not used in a NetworkBehaviour, the codegen will not find the types, even with this attribute.
This attribute is properly inherited by subclasses. For example:
[SerializesGenericParameter(0)]
public class MyClass<T>
{
}
public class MySubclass1 : MyClass<Foo>
{
}
public class MySubclass2<T> : MyClass<T>
{
}
[SerializesGenericParameter(1)]
public class MySubclass3<TTypeOne, TTypeTwo> : MyClass<TTypeOne>
{
}
public class MyBehaviour : NetworkBehaviour
{
public MySubclass1 TheValue;
public MySubclass2<Bar> TheValue;
public MySubclass3<Baz, Qux> TheValue;
}
The above code will trigger generation of serialization code for Foo (passed directly to the base class), Bar (passed indirectly to the base class), Baz (passed indirectly to the base class), and Qux (marked as serializable in the subclass).
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple = true)]
public class GenerateSerializationForGenericParameterAttribute : Attribute, _Attribute
Constructors
GenerateSerializationForGenericParameterAttribute(int)
Declaration
public GenerateSerializationForGenericParameterAttribute(int parameterIndex)
Parameters
Type | Name | Description |
---|---|---|
int | parameterIndex |