ユーザ用ツール

サイト用ツール


この翻訳は元のページよりも更新日が古く、内容が古い可能性があります。 変更点を参照して下さい。
Language:

サイドバー

en:vci:sample:message:no2

Exchange variables between multiple VCIs


Sample data: Transmitter: Transmit message

Sample data: Receiver: Receive message

UnityPackage:tutorial_message_send.zip

From VCI v0.17, vci.message is implemented which allows transmission and reception of messages in VCI.
This allows for the exchange of variables between multiple VCIs.


In this example, we will create two VCIs, transmitter and receiver, to demonstrate the communication of messages.

onUsing the transmitter VCI will send a message, which triggers a process in the receiving side if the set condition is met.
In this example, the receiving cylinder VCI will jump with upward velocity when it receives a message.


For the detailed information on vci.message, refer to:
https://virtualcast.jp/wiki/doku.php?id=%E3%83%A2%E3%83%87%E3%83%AB%E4%BD%9C%E6%88%90:vci%E4%BD%9C%E6%88%90:%E3%83%90%E3%83%BC%E3%83%81%E3%83%A3%E3%83%AB%E3%82%AD%E3%83%A3%E3%82%B9%E3%83%881.5.4a%E3%81%AEvci%E6%9B%B4%E6%96%B0


send.lua
function onUse(self)
    -- Message name: MSG_NAME
    -- Content of the message: 1
    vci.message.Emit("send_box_state","addforce_on")
end
 
function onUnuse(use)
    -- Message name: MSG_NAME
    -- Content of the message: 1
    vci.message.Emit("send_box_state","addforce_off")
end




get.lua
local sub = vci.assets.GetSubItem("get")
 
function onMessage(sender, name, message)
    -- The sender is in a table structure The information of the VCI that executed the vci.message.Emit function
    -- {
    --   type: "vci"
    --   name: "name of the vci"
    -- }
    -- In the future, the sender will have new messages implemented
    for k, v in pairs(sender) do
        print(k .. ":" .. v)
    end
 
    print(name)
    print(message)
 
    if name=="send_box_state" and message=="addforce_on" then
        print("forceon")
        sub.AddForce (1000*sub.GetUp())
    end
end
 
-- When ''vci.message.Emit'' is executed in studio, the onMessage function is called
vci.message.On("send_box_state", onMessage)
en/vci/sample/message/no2.txt · 最終更新: 2019/07/23 14:23 by h-eguchi

ページ用ツール