• 大小: 13.57MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-01
  • 语言: Java
  • 标签: Android  Unity  交互  

资源简介

Android与Unity交互示例 文章地址:http://blog.csdn.net/crazy1235/article/details/46733221 unity源码:https://yunpan.cn/cR369kvVbK2Ef (f9e9)

资源截图

代码片段和文件信息

package com.chen.interaction;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

public class UnityPlayerNativeActivity extends UnityPlayerActivity {
private LinearLayout u3dLayout;
private Button zoomInBtn zoomOutBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
u3dLayout = (LinearLayout) findViewById(R.id.u3d_layout);
u3dLayout.addView(mUnityPlayer);
mUnityPlayer.requestFocus();
zoomInBtn = (Button) findViewById(R.id.zoom_in_btn);
zoomOutBtn = (Button) findViewById(R.id.zoom_out_btn);
zoomInBtn.setonclickListener(new onclickListener() {
@Override
public void onclick(View v) {
Log.e(“info““in“);
UnityPlayer.UnitySendMessage(“Manager“ “ZoomIn“ ““);
}
});
zoomOutBtn.setonclickListener(new onclickListener() {
@Override
public void onclick(View v) {
Log.e(“info““out“);
UnityPlayer.UnitySendMessage(“Manager“ “ZoomOut“ ““);
}
});
}

public String getName(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(UnityPlayerNativeActivity.this str 1000).show();
}
});
return “for the lich king“;
}

/**
 * 3D调用此方法,用于退出3D
 */
public void makePauseUnity() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mUnityPlayer != null) {
try {
mUnityPlayer.quit();
} catch (Exception e) {
e.printStackTrace();
}
}
UnityPlayerNativeActivity.this.finish();
}
});
}

/**
 * 按键点击事件
 */
@Override
public boolean onkeydown(int keyCode KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onDestroy();
}
return true;
}

@Override
protected void onDestroy() {
super.onDestroy();
// UnityPlayer.UnitySendMessage(“Manager“ “Unload“ ““);
mUnityPlayer.quit();
}

// Pause Unity
@Override
protected void onPause() {
super.onPause();
mUnityPlayer.pause();
}

// Resume Unity
@Override
protected void onResume() {
super.onResume();
mUnityPlayer.resume();
}

@Override
public void onBackPressed() {
super.onBackPressed();
// mUnityPlayer.quit();
// this.finish();
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    I.A....       475  2016-06-13 16:00  Interaction\.classpath

    I.A....       861  2016-06-13 15:59  Interaction\.project

    I.A....      2162  2016-06-13 17:14  Interaction\AndroidManifest.xml

    I.A....     29460  2016-06-13 18:26  Interaction\assets\bin\Data\mainData

    I.A....      5120  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\Assembly-CSharp.dll

    I.A....     12288  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\Assembly-Unityscript.dll

    I.A....    126976  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\Boo.Lang.dll

    I.A....    292864  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\Mono.Security.dll

    I.A....   2496512  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\mscorlib.dll

    I.A....    268288  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\System.Core.dll

    I.A....   1069568  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\System.dll

    I.A....    699904  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\UnityEngine.dll

    I.A....    136192  2016-06-13 18:26  Interaction\assets\bin\Data\Managed\UnityEngine.UI.dll

    I.A....   1036040  2016-06-13 18:26  Interaction\assets\bin\Data\Resources\unity_builtin_extra

    I.A....       227  2016-06-13 18:26  Interaction\assets\bin\Data\settings.xml

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split0

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split1

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split10

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split11

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split12

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split13

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split14

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split15

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split16

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split17

    I.A....    317448  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split18

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split2

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split3

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split4

    I.A....   1048576  2016-06-13 18:26  Interaction\assets\bin\Data\sharedassets0.assets.split5

............此处省略41个文件信息

评论

共有 条评论