溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

android?studio集成unity導出工程怎么實現(xiàn)

發(fā)布時間:2022-05-16 09:47:12 來源:億速云 閱讀:182 作者:iii 欄目:開發(fā)技術

這篇文章主要講解了“android studio集成unity導出工程怎么實現(xiàn)”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“android studio集成unity導出工程怎么實現(xiàn)”吧!

環(huán)境

1,android studio 2021.1.1.1
2, unity 2021.2.4

新建android 工程

1,

android?studio集成unity導出工程怎么實現(xiàn)

2,

android?studio集成unity導出工程怎么實現(xiàn)

導出 unity 工程

1,

android?studio集成unity導出工程怎么實現(xiàn)

2,導出結果 unityLibrary 就是我們想要的結果 launcher 暫時用不上

android?studio集成unity導出工程怎么實現(xiàn)

3, 在android 工程中

android?studio集成unity導出工程怎么實現(xiàn)

4,選擇unitylibarary 目錄

android?studio集成unity導出工程怎么實現(xiàn)

5,

android?studio集成unity導出工程怎么實現(xiàn)

6,更改 app gradle配置文件:

 implementation project(path:':unityLibrary')
 implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString()+('\\libs'), include: ['*.jar', '*.aar'])

     ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }

android?studio集成unity導出工程怎么實現(xiàn)


7,刪除manifest配置

android?studio集成unity導出工程怎么實現(xiàn)

8, 在 gradle.property 添加配置 不加這個會報錯

unityStreamingAssets=.unity3d, google-services-desktop.json, google-services.json, GoogleService-Info.plist

android?studio集成unity導出工程怎么實現(xiàn)

9,添加 value值 不加也會掛掉

android?studio集成unity導出工程怎么實現(xiàn)

<string name="game_view_content_description">Game view</string>

10,調(diào)用

android?studio集成unity導出工程怎么實現(xiàn)

Button myBtn=  findViewById(R.id.button);

myBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(MainActivity.this,UnityPlayerActivity.class);
        startActivity(intent);
    }
});

android c# 互相調(diào)用

android 調(diào)用 c#

package com.xingame.unitycallandroid;

import android.os.Bundle;
import android.widget.Toast;

import com.unity3d.player.UnityPlayer;

public class MainActivity extends UnityPlayerActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
    }

    //unity調(diào)用Android
    public void UnityCallAndroid () {

        Toast.makeText(this,"unity調(diào)用android成功", Toast.LENGTH_LONG).show();

        AndroidCallUnity();
    }
    
    //android調(diào)用unity
    public void AndroidCallUnity () {

        //第1個參數(shù)為Unity場景中用于接收android消息的對象名稱
        //第2個參數(shù)為對象上的腳本的一個成員方法名稱(腳本名稱不限制)
        //第3個參數(shù)為unity方法的參數(shù)
        UnityPlayer.UnitySendMessage("receiveObj", "UnityMethod", "This is args.");
    }

}

c# 調(diào)用 java

  private void OnBtnClickHandler()
    {
        using (jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
            using (jo = jc.GetStatic<AndroidJavaObject>("currentActivity")){
                jo.Call("UnityCallAndroid");
            }
        }
    }

感謝各位的閱讀,以上就是“android studio集成unity導出工程怎么實現(xiàn)”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對android studio集成unity導出工程怎么實現(xiàn)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI