>创建场景后,我正在尝试从我的页面填充我的场景,但我收到上述错误。
这适用于安卓,它适用于 iOS(线程安全性存在一些问题)
01-05 18:45:19.139 E/Urho3D (32719): Sending events is only supported from the main thread
01-05 18:45:19.139 E/Urho3D (32719): Sending events is only supported from the main thread
01-05 18:45:19.139 E/Urho3D (32719): Sending events is only supported from the main thread
01-05 18:45:19.139 E/Urho3D (32719): Attempted to get resource Models/Box.mdl from outside the main thread
01-05 18:45:19.149 E/Urho3D (32719): Attempted to get resource Materials/Stone.xml from outside the main thread
知道如何在创建场景后将项目添加到我的场景中吗?
urhoApp?.addItem(urhoval);
在我的 urho 应用程序中:
public void addItem(string p)
{
modelNode2 = scene.CreateChild(p);
modelNode2.Position = new Vector3(5.0f, 1.0f, 5.0f);
modelNode2.SetScale(10.0f);
var obj2 = modelNode2.CreateComponent<StaticModel>();
obj2.Model = ResourceCache.GetModel("Models/Box.mdl");
obj2.SetMaterial(urhoAssets.GetMaterial("Materials/Stone.xml"));
}
您可以尝试在主线程上调用它:
InvokeOnMain(() =>{
//Your code here
}
android Activity 的每个事件总是在单个线程上调用 - "主线程"。
此线程由一个队列提供支持,所有活动事件都将发布到该队列中。它们按插入顺序执行。
如果要调用 Finish(),则线程将从当前任务中释放出来。
启动 Urho 线程的 Android 线程在 Urho 启动时仍处于活动状态,并且被视为 Main。因此,它无法处理您的资源缓存。
你应该完成()启动Urho线程的Android线程。
startBtn.Click += (sender, e) =>
{
Intent intent = new Intent(this, typeof(Urho3DActivity));
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop);
StartActivity(intent);
Finish();
};
iOS 则不同。没有主线程,Apple OS 以固有的稳定性处理事件。
startButton.TouchUpInside += delegate
{
Urho.Application Urho3DApp = Urho.Application.CreateInstance(typeof(Urho3DApp), new ApplicationOptions("Data"));
Urho3DApp.Run();
};