VCIを出した際に、message(”NATransformPosPlz”)にて、VCIの個別IDが共有されるので、それを使って、message(”NATransformSend”)にてTransformの情報を送ると、「猫山庵」を個別に移動させることができます。また、エフェクト再生を指示したり、暖簾を非アクティブにすることにより、「猫山庵」を固定して設置することも可能です。
--猫山庵のTransform用メッセージ
--message[1]:VCIの個別ID、固定できないIDのため、読み込み時のみIDを共有
--message[2]:Transform用Tbl
--message[3]:エフェクトのON/OFF
--message[4]:コントローラーのON/OFF、OFF(非アクティブ)で疑似的な固定
-- アクティブの場合、コントローラーも移動
function nekoyamaAnTransform(sender, name, message)
if message[1] == vci.assets.GetInstanceId() then
local tempPos = Vector3.zero
tempPos.x = message[2]["Pos"]["x"]
tempPos.y = message[2]["Pos"]["y"]
tempPos.z = message[2]["Pos"]["z"]
local tempRot = Quaternion.identity
tempRot.x = message[2]["Rot"]["x"]
tempRot.y = message[2]["Rot"]["y"]
tempRot.z = message[2]["Rot"]["z"]
tempRot.w = message[2]["Rot"]["w"]
local tempScl = Vector3.one
tempScl.x = message[2]["Scl"]["x"]
tempScl.y = message[2]["Scl"]["y"]
tempScl.z = message[2]["Scl"]["z"]
vci.assets.GetTransform("NekoyamaAn").SetPosition(tempPos)
vci.assets.GetTransform("NekoyamaAn").SetRotation(tempRot)
vci.assets.GetTransform("NekoyamaAn").SetLocalScale(tempScl)
resetTime = os.time(sec)
doorReset = false
if message[3] ~= nil then
if message[3] then
--エフェクト再生用のフラグ
effectFlag = true
end
end
if message[4] ~= nil then
if noren.IsMine then
if message[4] then
noren._ALL_SetActive(false)
vci.state.Set("FixState", true)
else
noren._ALL_SetActive(true)
vci.state.Set("FixState", false)
end
end
end
end
end
vci.message.On("NATransformSend", nekoyamaAnTransform)
--初回ロード時に、messageにてVCIの個別IDを共有
function update()
if vci.state.Get("InitialSetMes") == nil then
vci.message.Emit("NATransformPosPlz", vci.assets.GetInstanceId())
vci.state.Set("InitialSetMes", "Done")
end
end
移動させるためのスクリプトの一例は以下の通りです。
function nekoyamaAnTransformMessage(sender, name, message)
local tempTbl = {}
tempTbl["Pos"] = {
x = vci.assets.GetTransform("NekoyamaAnPos").GetPosition().x,
y = vci.assets.GetTransform("NekoyamaAnPos").GetPosition().y,
z = vci.assets.GetTransform("NekoyamaAnPos").GetPosition().z
}
tempTbl["Rot"] = {
x = vci.assets.GetTransform("NekoyamaAnPos").GetRotation().x,
y = vci.assets.GetTransform("NekoyamaAnPos").GetRotation().y,
z = vci.assets.GetTransform("NekoyamaAnPos").GetRotation().z,
w = vci.assets.GetTransform("NekoyamaAnPos").GetRotation().w
}
tempTbl["Scl"] = {
x = vci.assets.GetTransform("NekoyamaAnPos").GetLocalScale().x,
y = vci.assets.GetTransform("NekoyamaAnPos").GetLocalScale().y,
z = vci.assets.GetTransform("NekoyamaAnPos").GetLocalScale().z
}
vci.message.Emit("NATransformSend", {message, tempTbl, false, true})
end
vci.message.On("NATransformPosPlz", nekoyamaAnTransformMessage)