スキーマ
コンポーネント・スキーマは、コンポーネントが含むデータを定義します。 スキーマを 定義するとき、キーと値のペアを含むオブジェクトを提供します。キーはプロパティの名前で、値はそのプロパティが保持するデータの種類を指定するECSタイプです。
Currently, storing dynamically sized objects or lists isn’t supported. We’re actively exploring this feature and would love to hear about your specific use cases.
The following data types are useful for creating Schema properties on a Custom Component or references to a specific type.
Type | Description |
---|---|
ecs.eid | Entity Reference |
ecs.f32 | 32-bit floating-point number |
ecs.f64 | 64-bit floating-point number |
ecs.i32 | 32-bit integer |
ecs.ui8 | 8-bit unsigned integer |
ecs.ui32 | 32-bit unsigned integer |
ecs.string | String |
ecs.boolean | Boolean |
例
次の例は、カスタム・コンポーネントのスキーマを示しています。
schema: {
target: ecs.eid, // Unique entity reference for the NPC (Entity ID)
speed: ecs.f32, // Movement speed of the NPC (32-bit float)
strength: ecs.f64, // Strength level for the NPC (64-bit float)
level: ecs.i32, // Character level of the NPC (32-bit integer)
armor: ecs.ui8, // Armor rating of the NPC (0-255, 8-bit unsigned integer)
experience: ecs.ui32, // Experience points of the NPC (32-bit unsigned integer)
guildName: ecs.string, // Name of the Guild NPC belongs to. (String)
isHostile: ecs.boolean // Boolean indicating if the NPC is hostile to the player (Boolean)
}
デフォルトを指定することもできるが、必須ではない。 デフォルトが指定されていない場合、数値のデフォ ルトは 0
、論理値のデフォルトは false
、文字列のデフォルトは ''
、実体参照のデフォルトは unset となります。 コンポーネント・レベルでエンティティ参照のデフォルトを設定する方法はありません。
schemaDefaults: {
speed: 3.14,
strength: 5.8,
level: 10,
armor: 255,
experience: 12,
guildName: 'Niantic Crew'
isHostile: false
}
カスタムエディターフィールド
エンティティエディタでのコンポーネントの表示と機能は、さまざまな方法でカスタマイズできます。 これはすべてスキーマ内のコメントを使って行われ、フィールドには//@
というマークが付けられる。
ラベル
エディター上のラベルは、コード上の名前よりも説明的でなければならないことがある。
schema: {
// @label Foo
bar: ecs.eid,
},
資産の参照
プロジェクト内のアセットを参照する必要がある場合。
schema: {
// @asset
yetiModel: ecs.string,
}
最小&最大
インターフェイスで値を変更したときに、その値が一定量を超えないようにクランプする必要がある場合。 *実行時の変数の変更には影響しない。
schema: {
// @min 0
// @max 128
goldCoins: ecs.i32,
}
条件
プロパティは、他のプロパティの値によってのみ表示されるように設定することができます。
schema: {
// 'from' will only show if autoFrom set false:
autoFrom: ecs.boolean,
// @condition autoFrom=false
from: ecs.f32,
// 'easingFunction' will show if either easeIn or easeOut set:
easeIn: ecs.boolean,
easeOut: ecs.boolean,
// @condition easeIn=true|easeOut=true
easingFunction: ecs.string,
// 'targetX' only shows if no target set:
target: ecs.eid,
// @condition target=null
targetX: ecs.f32,
}
列挙
文字列プロパティは、セットリストに制限することができます:
schema: {
// @enum Quadratic, Cubic, Quartic, Quintic, Sinusoidal, Exponential
easingFunction: ecs.string,
}
グループ
特定のプロパティのグループをエディタで特別に扱うように指示することができる。 グループは以下のように設定される:
- グループの開始と終了は // @group start …でマークされる。 および // @group end
- 条件は // @group 条件でグループ全体に適用できる。
- 現在サポートされているグループは2種類:vector3とcolor
ラベル
カスタムラベルは、個々のフィールドに使用することができます:
schema: {
// @group start orient:vector3
// @label Pitch
orientPitch: ecs.f32,
// @label Yaw
orientYaw: ecs.f32,
// @label Roll
orientRoll: ecs.f32,
// @group end
}
Vector3
3次元ベクトルを表すプロパティのグループは、以下のように示すことができる:
schema: {
autoFrom: ecs.boolean,
// @group start from:vector3
// @group condition autoFrom=false
fromX: ecs.f32,
fromY: ecs.f32,
fromZ: ecs.f32,
// @group end
}
カラー
色は次の例のように示すことができる:
schema: {
// @group start background:color
bgRed: ecs.f32,
bgGreen: ecs.f32,
bgBlue: ecs.f32,
// @group end
}
データ
データはスキーマと似ているが、顕著な違いが2つある。
- データは、それが定義されているコンポーネントの外部で読み書きすることは**できない。
- データには**デフォルト値はありませんが、同様の機能を持つライフサイクルメソッド'add'で設定することができます。