====== キーボードの入力で移動・拡縮・回転するVCI ====== [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportMe/index.html|ExportMe]]を利用した、キーボードの入力を受け取ってVCIを移動・回転・拡縮させるサンプルVCIです。 === サンプルデータ === https://virtualcast.jp/products/614fe676102b36cf353a1d47616efdaa450e202c519e5414b7b26ae3652f929c {{ :vci:sample:sample_advanced:inputsample.zip |}} ==== コンポーネント設定 ==== コンポーネントはSubItemが設定されていれば他に必要なコンポーネント等はありません。\\ 下記のサンプルは Target という名前のSubitemが必要です。 ===== VCIスクリプト ===== キーボードでXZ方向の移動、UIで上昇降下、12で回転、34で拡大縮小を行います。 local _Target = vci.assets.GetTransform("Target") function update() -- 軸入力を取得する。 local axis = vci.me.GetAxisInput() -- 入力ログ if axis.x ~= 0 then print(" X : "..tostring(axis.x)) end if axis.y ~= 0 then print(" Y : "..tostring(axis.y)) end if axis.z ~= 0 then print(" Z : "..tostring(axis.z)) end -- Targetの移動 local pos = 0.01 * axis + _Target.GetLocalPosition() _Target.SetLocalPosition(pos) -- 入力取得 if vci.me.GetButtonInput(1) then print(" Button1 が押されました。") -- 回転処理 local rot = _Target.GetLocalRotation() rot = rot * Quaternion.AngleAxis(-30, Vector3.forward) _Target.SetLocalRotation(rot) end -- 入力取得 if vci.me.GetButtonInput(2) then print(" Button2 が押されました。") -- 回転処理 local rot = _Target.GetLocalRotation() rot = rot * Quaternion.AngleAxis(30, Vector3.forward) _Target.SetLocalRotation(rot) end -- 入力取得 if vci.me.GetButtonInput(3) then print(" Button3 が押されました。") -- 拡縮処理 local scale = _Target.GetLocalScale() if scale.x < 0.2 then return end scale = scale + Vector3.__new(-0.1, -0.1, -0.1) _Target.SetLocalScale(scale) end -- 入力取得 if vci.me.GetButtonInput(4) then print(" Button4 が押されました。") -- 拡縮処理 local scale = _Target.GetLocalScale() scale = scale + Vector3.__new(0.2, 0.2, 0.2) _Target.SetLocalScale(scale) end end ==== VCIスクリプト(解説) ==== GetAxisには押された状態の値が常に入り続けます。\\ 移動の処理などを行う場合は値をそのまま使えばよいですが、コンソールなどの場合は0の時は表示しないようにするのがよいかと思われます。 -- 軸入力を取得する。 local axis = vci.me.GetAxisInput() -- 入力ログ if axis.x ~= 0 then print(" X : "..tostring(axis.x)) end