Luaコンポーネントから他のコンポーネントを参照したい
仕事のほうが忙しく、久々の記事なのですが…
うまくいっておらず、途中経過のみ掲載。
Luaで作ったEntityComponentから、他のComponentを参照するため
以下のようなコードを書いたんだけれど、numがずっと0
(Test2Behaviourを付けたEntityは配置済み)
local query_cache = {}
-- Called once each frame. Optional.
function TestBehavior.update(world, dt)
local script_component = stingray.EntityManager.script_component(world)--SimpleProject.script_component
if script_component == nil then
return
end
local world_entity_data = world_data[world]
for entity, entity_data in pairs(world_entity_data) do
local com, num = script_component:instances_with_script(entity, "Test2Behaviour", query_cache)
if num ~= 0 then
print("AA"..num)
end
local ents = script_component:entities_with_script("Test2Behaviour")
for script_component_instance, script_component_data in pairs(entity_data) do
-- TODO: Do your component's update logic here.
end
end
end
script_component:instances_with_script
一応SimpleProjectのscript_componentを引いて使ってみたりもしたけど結果は変わらず。
Component間通信ができないと色々辛いのでなんとかしたい。
ちなみにUnity3dのMonoBehaviourと違って、全てstatic classやsingletonで書くようなイメージ。
このスクリプトを記述する上での留意点は、すべてのゲーム ワールドでモジュールが関連付けられている「すべての」エンティティを処理する必要があることです。このスクリプトで各エンティティに対して定義するコンポーネント オブジェクトの個別のコピーはなく、ゲーム内にはこの Lua オブジェクトのインスタンスは 1 つ だけあります
引用元:http://help.autodesk.com/view/Stingray/JPN/?guid=__stingray_help_using_entities_script_behavior_html
参考:ScriptComponentのドキュメント
http://help.autodesk.com/view/Stingray/ENU/?guid=__lua_ref_obj_stingray_ScriptComponent_html