====== VirtualCast 1.5.1a VCI更新 ======
===== アイテムの状態を変数として同期する機能 =====
アイテム変数をネットワークを介して同期する **vci.state** と、
それを使うのに必要な **updateAll**, **vci.assets.IsMine**, **ExportTransform(SubItem).IsMine** を追加します
==== updateAll と vci.state の使用例 ====
function updateAll() -- 所有権に関係なく全ユーザーに来る
if vci.state.Get("TOGGLE") then
vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 0, 0, 1))
else
vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 1, 1, 1))
end
end
function onUse() -- 使用時
local toggle = vci.state.Get("TOGGLE")
vci.state.Set("TOGGLE", not toggle)
end
=== 変更前 ===
だいたい同じことをする例です。
TOGGLE="ITEM_UNIQUE_TOGGLE" -- 同じアイテムが複数持ち込まれたときにスタジオ内でユニークにならない弱点
vci.studio.shared.Bind(TOGGLE, function(value) -- Bind関数が難しい
if value then
vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 0, 0, 1))
else
vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 1, 1, 1))
end
end)
function onUse() -- 使用時
local value = vci.studio.shared.Get(TOGGLE)
vci.studio.shared.Set(TOGGLE, not value)
end
==== vci.assets.IsMine ====
function updateAll() -- 所有権に関係なく全ユーザーに来る
if vci.assets.IsMine then
-- 処理
end
end
-- 上と同じ意味になります
function update() -- VCIの所有者(VCIを呼び出したユーザー)に来る
-- 処理
end
==== ExportTransform(SubItem).IsMine ====
subitem = vci.assets.GetTransform('item_name')
function updateAll() -- 所有権に関係なく全ユーザーに来る
if subitem.IsMine then -- SubItemの所有者だけで処理したい
subitem.SetPosition = Vector3.__new(1, 2, 3)
end
end