VCIを出した際に、message(”ToriiTransformPosPlz”)にて、VCIの個別IDが共有されるので、それを使って、message(”ToriiTransformSend”)にてTransformの情報を送ると、「鳥居」を個別に移動させることができます。ただし、messageでの送信量の関係から、10本毎での移動の指示となります。分割用ID:1が1~10番目の鳥居、ID:2が11~20番目、ID:3が21~30番目の鳥居の移動の指示となっています。また、大幣を非アクティブにすることにより、「鳥居」を固定して設置することも可能です。
--他VCIからのTransform操作用Message
--message[1]:VCI固有ID、固定ではないため、初期ロード時のみIDを発行する
--message[2]:Transform関係のTbl
--message[3]:データ量が多いと送れないため、分割用ID(1~3)
--message[4]:エフェクトのON/OFF
--message[5]:コントローラー(大幣)のON/OFF
function toriiTransform(sender, name, message)
if message[1] == vci.assets.GetInstanceId() then
for i = 1, 10 do
if tostring(message[2][i]["Act"]) ~= "nil" then
transTbl[i+10*(message[3]-1)]["Act"] = message[2][i]["Act"]
if message[2][i]["Act"] then
local tempPos = Vector3.zero
if message[2][i]["Act"] then
tempPos.x = message[2][i]["Pos"]["x"]
tempPos.y = message[2][i]["Pos"]["y"]
tempPos.z = message[2][i]["Pos"]["z"]
transTbl[i+10*(message[3]-1)]["Pos"] = {x = tempPos.x, y = tempPos.y, z = tempPos.z}
end
local tempRot = Quaternion.identity
if message[2][i]["Act"] then
tempRot.x = message[2][i]["Rot"]["x"]
tempRot.y = message[2][i]["Rot"]["y"]
tempRot.z = message[2][i]["Rot"]["z"]
tempRot.w = message[2][i]["Rot"]["w"]
transTbl[i+10*(message[3]-1)]["Rot"] = {x = tempRot.x, y = tempRot.y, z = tempRot.z, w = tempRot.w}
end
local tempScl = Vector3.one
if message[2][i]["Act"] then
tempScl.x = message[2][i]["Scl"]["x"]
tempScl.y = message[2][i]["Scl"]["y"]
tempScl.z = message[2][i]["Scl"]["z"]
transTbl[i+10*(message[3]-1)]["Scl"] = {x = tempScl.x, y = tempScl.y, z = tempScl.z}
end
vci.assets.GetTransform("SandoTorii-"..i+10*(message[3]-1)).SetPosition(tempPos)
vci.assets.GetTransform("SandoTorii-"..i+10*(message[3]-1)).SetRotation(tempRot)
vci.assets.GetTransform("SandoTorii-"..i+10*(message[3]-1)).SetLocalScale(tempScl)
end
vci.assets.GetTransform("SandoTorii-"..i+10*(message[3]-1)).SetActive(message[2][i]["Act"])
if message[4] then
vci.assets.GetEffekseerEmitter("SandoTorii-"..i+10*(message[3]-1)).PlayOneShot()
end
end
end
vci.state.Set("ToriiTrans", transTbl)
if ogusa.IsMine then
if message[5] ~= nil then
if message[5] then
ogusa._ALL_SetActive(false)
vci.state.Set("FixState", true)
else
ogusa._ALL_SetActive(true)
vci.state.Set("FixState", false)
end
end
end
end
end
vci.message.On("ToriiTransformSend", toriiTransform)
--初回ロード時に、messageにてVCIの個別IDを共有
function updateAll()
if not(initialFlag) then
if vci.state.Get("ToriiTrans") == nil then
if vci.assets.IsMine then
vci.state.Set("ToriiTrans", transTbl)
vci.message.Emit("ToriiTransformPosPlz", vci.assets.GetInstanceId())
end
end
end
end
移動させるためのスクリプトの一例は以下の通りです。
function toriiTransformMessage(sender, name, message)
for j = 1, 3 do
local tempTbl = {}
for i = 1, 10 do
tempTbl[i] = {}
tempTbl[i]["Act"] = true
tempTbl[i]["Pos"] = {
x = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetPosition().x,
y = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetPosition().y,
z = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetPosition().z
}
tempTbl[i]["Rot"] = {
x = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetRotation().x,
y = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetRotation().y,
z = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetRotation().z,
w = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetRotation().w
}
tempTbl[i]["Scl"] = {
x = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetLocalScale().x/100,
y = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetLocalScale().y/100,
z = vci.assets.GetTransform("SandoToriiSPos"..i+10*(j-1)).GetLocalScale().z/100
}
end
vci.message.Emit("ToriiTransformSend", {message, tempTbl, j, false, true})
end
end
vci.message.On("ToriiTransformPosPlz", toriiTransformMessage)