• Unity与Android间的交互


    1.打开Android Studio,命名并自动生成包名

    2.点击Next,设置最小支持的SDK  

    3.点击Next,选择Empty Activity

     4.点击Next,默认就行不用管

    5.Finish

    6.在Unity安装路径下找到Class.jar

    找到libs文件夹

     右键点击Show In Explorer,将class.jar放进去

     

    右键点击Class.jar,点击Add As Library

    出现对话框,点OK

    7.打开Android Mainifest

    加上这句话:

     <meta-data android:name="unityplayer.UnityActivity" android:value="true" />

    8.打开build.gradle

    修改一下:  applicaition改成library;applicationId那一句删掉

    点击右上角sync Now

     9编写MainActivity代码,修改如下

    10.点击Build APK

    11.在项目的这个目录下找到app-debug.arr

    右键选择用压缩工具打开

    删掉里面的res文件夹和libs下的Class.jar

    12.把app-debug.arr和AndroidManifest扔进Unity的这个文件夹下

    把AndroidManifest改一下:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.a.z">

    <application
    android:theme="@android:style/Theme.NoTitleBar"
    android:icon="@drawable/app_icon"
    android:label="@string/app_name">
    <activity android:name=".MainActivity">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    </application>

    </manifest>

    13.Unity里建一个脚本

    3个参数分别对应Android Studio那边的“函数名”,"参数1","参数2"

    14.发布出来apk到手机上测试一下吧。在电脑上没法测

  • 相关阅读:
    每天一道LeetCode--141.Linked List Cycle(链表环问题)
    每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)
    每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
    CF1277D Let's Play the Words?
    CF1281B Azamon Web Services
    CF1197D Yet Another Subarray Problem
    CF1237D Balanced Playlist
    CF1239A Ivan the Fool and the Probability Theory
    CF1223D Sequence Sorting
    CF1228D Complete Tripartite
  • 原文地址:https://www.cnblogs.com/Feiyuzhu/p/6400589.html
Copyright © 2020-2023  润新知