• Decorator to mark properties of a Serializable for automatic serialization and editor configuration.

    Editor Configuration: Specify a type (constructor) for an attribute within a class's metadata. This allows the intended type of an attribute to be known by the editor (at runtime), making it:

    • A valid drop target (e.g., for objects like Node, Texture, Mesh).
    • Display the appropriate input element, even if the attribute has not been set (undefined).

    Serialization: The automatic serialization occurs after an instance's Serializable.serialize / Serializable.deserialize method was called.

    • Primitives will be serialized as is.
    • Serializables will be serialized nested.
    • SerializableResources will be serialized via their resource id and fetched with it from the project when deserialized.
    • Nodes will be serialized as a path connecting them through the hierarchy, if found. During deserialization, the path will be unwound to find the instance in the current hierarchy. They will be available after EVENT.GRAPH_DESERIALIZED / EVENT.GRAPH_INSTANTIATED was broadcast through the hierarchy. Node references can only be serialized from a Component.

    Example:

    import ƒ = FudgeCore;

    @ƒ.serialize
    export class MyScript extends ƒ.ComponentScript {
    #size: number = 1;

    @ƒ.serialize(String) // display a string in the editor
    public info: string;

    @ƒ.serialize(ƒ.Vector3) // display a vector in the editor
    public position: ƒ.Vector3 = new ƒ.Vector3(1, 2, 3);

    @ƒ.serialize(ƒ.Material) // drop a material inside the editor to reference it
    public resource: ƒ.Material;

    @ƒ.serialize(ƒ.Node) // drop a node inside the editor to reference it
    public reference: ƒ.Node

    @ƒ.serialize(Number) // display a number in the editor
    public get size(): number {
    return this.#size;
    }

    // define a setter to allow writing to size, or omit it to leave the property read-only
    public set size(_size: number) {
    this.#size = _size;
    }
    }

    Side effects:

    Type Parameters

    Parameters

    • _constructor: (new (...args) => T)
        • new (...args): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    Returns ((_value, _context) => void)

  • Type Parameters

    Parameters

    • _value: T
    • _context: ClassDecoratorContext<(new (...args) => any)>

    Returns void