docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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).
    Inheritance
    object
    Attribute
    GenerateSerializationForGenericParameterAttribute
    Inherited Members
    Attribute.Equals(object)
    Attribute.GetCustomAttribute(Assembly, Type)
    Attribute.GetCustomAttribute(Assembly, Type, bool)
    Attribute.GetCustomAttribute(MemberInfo, Type)
    Attribute.GetCustomAttribute(MemberInfo, Type, bool)
    Attribute.GetCustomAttribute(Module, Type)
    Attribute.GetCustomAttribute(Module, Type, bool)
    Attribute.GetCustomAttribute(ParameterInfo, Type)
    Attribute.GetCustomAttribute(ParameterInfo, Type, bool)
    Attribute.GetCustomAttributes(Assembly)
    Attribute.GetCustomAttributes(Assembly, bool)
    Attribute.GetCustomAttributes(Assembly, Type)
    Attribute.GetCustomAttributes(Assembly, Type, bool)
    Attribute.GetCustomAttributes(MemberInfo)
    Attribute.GetCustomAttributes(MemberInfo, bool)
    Attribute.GetCustomAttributes(MemberInfo, Type)
    Attribute.GetCustomAttributes(MemberInfo, Type, bool)
    Attribute.GetCustomAttributes(Module)
    Attribute.GetCustomAttributes(Module, bool)
    Attribute.GetCustomAttributes(Module, Type)
    Attribute.GetCustomAttributes(Module, Type, bool)
    Attribute.GetCustomAttributes(ParameterInfo)
    Attribute.GetCustomAttributes(ParameterInfo, bool)
    Attribute.GetCustomAttributes(ParameterInfo, Type)
    Attribute.GetCustomAttributes(ParameterInfo, Type, bool)
    Attribute.GetHashCode()
    Attribute.IsDefaultAttribute()
    Attribute.IsDefined(Assembly, Type)
    Attribute.IsDefined(Assembly, Type, bool)
    Attribute.IsDefined(MemberInfo, Type)
    Attribute.IsDefined(MemberInfo, Type, bool)
    Attribute.IsDefined(Module, Type)
    Attribute.IsDefined(Module, Type, bool)
    Attribute.IsDefined(ParameterInfo, Type)
    Attribute.IsDefined(ParameterInfo, Type, bool)
    Attribute.Match(object)
    Attribute.TypeId
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Netcode
    Assembly: Unity.Netcode.Runtime.dll
    Syntax
    [AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple = true)]
    public class GenerateSerializationForGenericParameterAttribute : Attribute

    Constructors

    GenerateSerializationForGenericParameterAttribute(int)

    Declaration
    public GenerateSerializationForGenericParameterAttribute(int parameterIndex)
    Parameters
    Type Name Description
    int parameterIndex
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)