本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
參數和引數
預覽版的新Sumerian 引擎 API
參數可讓您建立指令碼,透過將欄位新增到編輯器中的指令碼屬性來自定指令碼。例如,下列指令碼定義名為 Velocity
的參數,取用 3 個號碼 (vec3 參數)。安裝函數會取得參數的值從args
物件。
var setup = function(args, ctx){
console.log(args.velocity);
};
var parameters = [
{
name : "Velocity",
key : "velocity",
type : "vec3",
default : [1,0,0]
}
];
在設定階段,指令碼會從 args
物件讀取參數值,並將參數值列印到主控台。
當您新增上述指令碼的執行個體到實體時,編輯器將顯示一個 Velocity (速度) 欄位,接受三個值並反映預設值。

參數格式
參數為含有下列必填與選填欄位的物件。
必要欄位
-
金鑰[string] — 一個獨特金鑰,用於存放與擷取參數值在
args
物件。 -
type[string] —參數類型。
-
default— 預設值或參數值。
選填欄位
-
name
[string] — 顯示於指令碼執行個體上的參數欄位的標籤。如果您不指定名稱,將使用key
來產生標籤。 -
control
[string enum] — 控制類型。-
slider
— 滑桿控制。 -
color
— 顏色轉輪。 -
select
— 下拉式清單,列出options
欄位。 -
jointSelector
— 下拉式清單,列出指令碼父實體上動畫元件的連接點。
-
-
description
[string] — 當您以滑鼠滑過參數時顯示的描述。 -
options
[array]-一系列的可能值select
控制。 -
min
和max
[number]-最小與最大值int
或float
參數。 -
decimal
[number]-有效位數數數數數字float
參數。 -
step
[number] — 累加值float
值會鎖點至。 -
precision
[number] — 有效位數數數數字float
值。 -
exponential
[布林值] — 設定為true
來將值分布在slider
以對數方式控制。
參數類型
類型屬性須設定為其中一個預先定義的字串,每個字串對應至一個參數類型。
-
int
— 整數數字變數 (例如1
。 -
float
— 數字變數 (例如3.14
。 -
string
— 字串 (例如“HelloGoo”
。 -
boolean
— 布林值 (true
或false
。 -
vec2
、vec3
、vec4
— 一系列的 2、3、或 4 個號碼。 -
texture
、sound
、entity
、camera
、animstate
、json
— 指定type。
下列範例參數宣告顯示所有可用類型。
var parameters = [
{type: 'int', key: 'int', 'default': 1, description: 'Integer input'},
{type: 'float', key: 'float', 'default': 0.1, description: 'Float input'},
{type: 'string', key: 'string', 'default': 'Hello!', description: 'String input'},
{type: 'boolean', key: 'boolean', 'default': true, description: 'Checkbox'},
{type: 'vec2', key: 'vec2', 'default': [0, 0], description: 'Vector2 input'},
{type: 'vec3', key: 'vec3', 'default': [0, 0, 0], description: 'Vector3 input'},
{type: 'vec4', key: 'vec4', 'default': [0, 0, 0, 0], description: 'Vector4 input'},
{type: 'texture', key: 'texture', description: 'Texture asset drop area'},
{type: 'sound', key: 'sound', description: 'Sound asset drop area'},
{type: 'entity', key: 'entity', description: 'Entity drop area'},
{type: 'camera', key: 'camera', description: 'Camera drop down'},
{type: 'animstate', key: 'animation', description: 'Animation state from the animation component on a parent entity'},
{type: 'json', key: 'json', description: 'JSON asset drop area'},
{type: 'float', control: 'slider', key: 'floatSlider', 'default': 10.1, min: 5, max: 15, exponential: false, decimal: 1, description: 'Float slider input'},
{type: 'int', control: 'slider', key: 'intSlider', 'default': 10, min: 5, max: 15, exponential: false, description: 'Integer slider input'},
{type: 'vec3', control: 'color', key: 'vec3Color', 'default': [1, 0, 0], description: 'RGB color input'},
{type: 'vec4', control: 'color', key: 'vec4Color', 'default': [1, 0, 0, 1], description: 'RGBA color input'},
{type: 'string', control: 'select', key: 'select', 'default': 'a', options: ['a', 'b', 'c'], description: 'Dropdown/select'},
{type: 'int', control: 'jointSelector', key: 'jointSelector', description: 'Joint select from the animation component on a parent entity'}
];
