最も要望の多かった機能の一つがついに登場しました:カスタムTypeScriptおよびJavaScriptコンポーネント用のレコードと配列プロパティタイプ。

これを活用して生まれる素晴らしい体験を見るのが楽しみです!

レコード 

プロパティはrecordプロパティを使用してJavaScriptクラスにまとめることができます:

import {Component, Property} from '@wonderlandengine/api';

class PlayerSettings {
    static Properties = {
        speed: Property.float(10.0),
        name: Property.string('Hero')
    };
}

export class PlayerManager extends Component {
    static TypeName = 'player-manager';

    static Properties = {
        settings: Property.record(PlayerSettings)
    };

    start() {
        console.log(this.settings); // Player(10.0, 'Hero')と表示
        console.log(this.settings instanceof PlayerSettings); // true
    }
}
Wonderland EditorでのPlayerManagerコンポーネント

PlayerSettingsクラスを定義する際のスタイルに注目してください。プロパティはレコードとコンポーネントの両方で同じ方法で宣言されます。

配列 

arrayプロパティを使用することで、プロパティのリストを作成することも可能になりました:

import {Component, Property} from '@wonderlandengine/api';

export class Downloader extends Component {
    static TypeName = 'downloader';

    static Properties = {
        urls: Property.array(Property.string())
    };

    start() {
        for(const url of this.urls) {
            // `url`が指すファイルをダウンロード。
        }
    }
}

Property.string()は配列要素の型を表します。配列は一度に単一の型の要素しか保持できません。

recordプロパティと組み合わせて、複雑な型を実現することができます:

import {Component, Property} from '@wonderlandengine/api';

class Zombie {
    static Properties = {
        name: Property.string(),
        maxHealth: Property.float(100.0),
        mesh: Property.mesh(),
    };
}

export class ZombieSpawner extends Component {
    static TypeName = 'zombie-spawner';

    static Properties = {
        enemies: Property.array(Property.record(Zombie))
    };

    start() {
        for(const zombie of this.enemies) {
            const name = zombie.name;
            const health = zombie.maxHealth;
            // 凶悪なゾンビをスポーン!
        }
    }
}
Wonderland EditorでのZombieSpawnerコンポーネント

このAPIはネストされた配列プロパティ(配列の配列)もサポートしています:

import {Component, Property} from '@wonderlandengine/api';

export class LevelGenerator extends Component {
    static TypeName = 'level-generator';

    static Properties = {
        mapPiecesPerLevel: Property.array(Property.array(Property.string())),
    };

    start() {
        // 次のように表示されます:
        // [
        //    ['level_1_forest.map', 'level_1_mountains.map'],
        //    ['level_2_beach.map', 'level_2_ocean.map', 'level_2_desert.map'],
        //    ['level_3_underwater.map'],
        // ]
        console.log(this.mapPiecesPerLevel);
    }
}

TypeScript 

TypeScriptユーザー向けに、新しいrecordarrayのプロパティデコレータにより、複雑なコンポーネントプロパティをコンパクトかつ直感的に宣言できます:

import {Component, property, Property} from '@wonderlandengine/api';

class Zombie {
    @property.string()
    name!: string;

    @property.float(100)
    maxHealth!: number;

    @property.float(10)
    damage!: number;
}

export class ZombieManager extends Component {
    static TypeName = 'zombie-manager';

    @property.array(Property.record(Zombie))
    zombies!: Zombie[];
}
Last Update: May 12, 2025

最新情報をお届けします。