バーチャルキャスト公式Wiki
メニュー
配信
その他
リリース情報
安定版
ベータ版
Quest版
- wiki編集者用ページ
-
安定版
ベータ版
Quest版
以前のリビジョンの文書です
VCIの各種情報・機能にアクセスできます。
[EmbeddedScriptWorkspace]フォルダ内の[types.lua]を開くと一覧を確認できます。
---vci module ---@class ExportVci ---@field StartCoroutine fun(coroutine: usertype) ---@field studio ExportStudio ---@field me ExportMe ---@field assets ExportAssets ---@field state ExportState ---@field message ExportMessage ---@field ResetRootTransform fun() ---@field _ALL_ResetRootTransform fun()
メソッド | 説明 | VCバージョン |
---|---|---|
StartCoroutine fun(coroutine: usertype) | コルーチンを開始します | 1.9.2a以降 |
studio | ||
me | ||
assets | ||
state | ||
message | ||
ResetRootTransform fun() | VCIのTransformをリセットします | 1.9.2a以降 |
_ALL_ResetRootTransform fun() | VCIのTransformをリセットします | 1.9.2a以降 |
VCバージョン: 1.9.2a以降
luaのコルーチン機能を用いて、Unityのコルーチンのような記述ができます。
サンプル
vci.StartCoroutine( coroutine.create( function() print("コルーチン開始") local i = 0 while i < 10 do -- カウントする print(i) i = i + 1 -- 0.5秒スリープする sleep(0.5) end print("コルーチン終了") end ) ) function sleep(sec) local t0 = os.time() + sec while os.time() < t0 do -- コルーチンの実行を中断する coroutine.yield() end end
コルーチンは複数実行できますが、過剰に追加すると動作が不安定になるのでご注意ください。
また、無限ループにもご注意ください。coroutine.yieldがループ内に入っている場合は問題ありませんが、 coroutine.yieldをループ内に入れなかった場合、Too Many Instructionsというエラーが表示され、スクリプトが停止します。
複数のコルーチンを用いてアニメーションするサンプルです。
local cube = vci.assets.GetSubItem("Cube") vci.StartCoroutine( coroutine.create( function() print("Coroutine1: start") while true do local r = math.random() local g = math.random() local b = math.random() vci.assets.SetMaterialColorFromIndex(0, Color.__new(r,g,b)) sleep(2) end end ) ) vci.StartCoroutine( coroutine.create( function() print("Coroutine2: start") local ry = 0 while true do cube.SetLocalRotation(Quaternion.Euler(0, ry, 0)) ry = ry + 1 coroutine.yield() end end ) ) vci.StartCoroutine( coroutine.create( function() print("Coroutine3: start") local cnt = 0 while true do local x = 2 * math.cos(cnt / 100) local z = 2 * math.sin(cnt / 100) cube.SetLocalPosition(Vector3.__new(x, 4, z)) cnt = cnt + 1 coroutine.yield() end end ) ) function sleep(sec) local t0 = os.time() + sec while os.time() < t0 do coroutine.yield() end end
VCバージョン: 1.9.2a以降
通常の場合、小物VCIは、アバターの目の前の座標に生成されます。 生成後にResetRootTransformを呼ぶと、VCIの大元のTransformがリセットされます。座標が原点にセットされ、角度もリセットされます。
サンプル
vci.ResetRootTransform()