1,常见报错
报错并提示:Add library 'unity.classes' to classpath
报错:
e: file:///D:/IDEA-items/quanji_xitong/app/src/main/java/com/example/quanji_xitong/start_test/UnityPlayerActivity.kt:5:27 Unresolved reference: UnityPlayer
e: file:///D:/IDEA-items/quanji_xitong/app/src/main/java/com/example/quanji_xitong/start_test/UnityPlayerActivity.kt:9:33 Unresolved reference: UnityPlayer
e: file:///D:/IDEA-items/quanji_xitong/app/src/main/java/com/example/quanji_xitong/start_test/UnityPlayerActivity.kt:14:13 Unresolved reference: UnityPlayer提示:
Add library 'unity.classes' to classpath
解决方法:添加依赖(这里的unity-classes.jar包为自己的路径)
//noinspection GradlePathimplementation(files("D:/IDEA-items/quanji_xitong/unityLibrary/libs/unity-classes.jar"))
2,继承unity,使场景在布局文件显示的同时进行通信,UnitySendMethod.callUnityMethod(this, "head", "head", "10.0,20.0,30.0")安卓端发送给unity,代码如下:
package com.example.quanji_xitong.start_testimport android.os.Bundle
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.example.quanji_xitong.R
import com.unity3d.player.UnityPlayerActivityclass StartTestActivity : UnityPlayerActivity() {private lateinit var unityView: ConstraintLayoutoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.function_start_test_main)/*** 为变量绑定控件*/unityView = findViewById(R.id.UnityView)// 获取 Unity 渲染视图并添加到 ConstraintLayoutunityView.addView(mUnityPlayer.frameLayout)// 主功能模块-设备管理findViewById<View>(R.id.send).setOnClickListener {UnitySendMethod.callUnityMethod(this, "head", "head", "10.0,20.0,30.0")}}}
目前还在写,完成之后再更新