【发布时间】:2019-02-06 16:12:57
【问题描述】:
这是非常基本的,但我没有从 Unity 官方文档和 YouTube 视频教程中成功实施它,所以我问了。
我想从已经制作的 aar 插件中访问方法。默认情况下,它被选中为 android 插件。插件代码如下:
package alarm.company.com.unity;
public class myPlugin {
public String myTest(int i){
return "Hello your string number is: "+i;
}
}
编译好的aar插件复制到Unity文件夹中。 这是访问该方法的 c# 代码:
const string PluginName = "alarm.company.com.unity.myPlugin";
static AndroidJavaClass _pluginClass;
static AndroidJavaClass _pluginInstance;
public Text text;
// Start is called before the first frame update
void Start()
{
AndroidJavaClass plugin = new AndroidJavaClass(PluginName);
string s = plugin.CallStatic<string>("myTest", 9);
print(s);
text.text = s;
}
text 被分配并且这个脚本被放在主摄像机上。但是在模拟器中运行时,我没有收到任何文本或文本对象没有更改。怎么解决?
【问题讨论】: