我从Unity导出了多个Unity场景,这些场景已作为库导入到Android Studio中。我的目标是在Android Studio中设置一些按钮,单击这些按钮将从Unity项目中加载特定场景。我正在关注this教程,并且已将C清晰代码添加到我的每个统一场景中,但无法使UnityPlayer.UnitySendMessage部分起作用。
这是我的MainActivty.java,其中包含UnityPlayer.UnitySendMessage。
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.unity3d.player.UnityPlayer;
public class MainActivity extends AppCompatActivity {
boolean isUnityLoaded = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void btnLoadUnity(View v) {
UnityPlayer.UnitySendMessage("SceneLoader", "LoadScene", "One");
isUnityLoaded = true;
Intent intent = new Intent(this, MainUnityActivity.class);
startActivityForResult(intent, 1);
}
public void btnLoadUnity2(View v) {
isUnityLoaded = true;
Intent intent = new Intent(this, MainUnityActivity.class);
startActivityForResult(intent, 1);
UnityPlayer.UnitySendMessage("SceneLoader", "LoadScene", "Two");
}
}
意图调用了第二个活动,该活动启动了统一活动:
import android.content.Intent;
import android.util.Log;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
public class MainUnityActivity extends UnityPlayerActivity {
//@Override
protected void showMainActivity(String setToColor) {
Intent intent = new Intent(this, UnityPlayerActivity.class);
startActivity(intent);
我在日志猫中收到未加载本机库-删除SceneLoader.LoadScene的消息错误。
嘿,我遇到了同样的问题。您设法解决了吗?