Exemple #1
0
        Trait BuildTraitGenericPayload <T>(Payload <T> payload, PayloadBuilder builder) where T : struct
        {
            var trait = Trait.Create(payload.Build(builder));

            bool isValueType = trait.type.IsValueType;
            bool isBlittable = UnsafeUtility.IsBlittable(trait.type);

            if (!isValueType || !isBlittable)
            {
                throw new ArgumentException($"Trait {typeof(T).Name} generated a non-blittable instance of type {trait.type.Name}.");
            }

            if (!HasTraitAttribute <T>())
            {
                throw new ArgumentException($"Trait {trait.type.Name} must have the 'Trait' attribute.");
            }

            RegisterType(trait.type);

            return(trait);
        }