unity3D调用安卓 Toast.makeText
来源:互联网 发布:网络直播版权 编辑:程序博客网 时间:2024/04/29 21:56
有时候开发过程中想在屏幕输出一些调试的信息,新建一个Activity,然后配置AndroidManifest等等但是每个工程都要弄一下很麻烦。
开发过安卓的朋友都知道安卓里面有一个Toast.makeText 的方法可以在屏幕显示一段话,直接调用方法就可以显示,不用配置其他东西。
下面介绍在unity3d中怎么调用:
先看看效果:
打开eclipse
新建一个java项目
加入unity的classes.jar
路径在......\Unity\Editor\Data\PlaybackEngines\androidplayer\bin
新建java文件
package com.cc.debug;import android.widget.Toast;public class MyDebug{public static void Debug(String src){MyRunnable runnable = new MyRunnable(src);com.unity3d.player.UnityPlayer.currentActivity.runOnUiThread(runnable); } }class MyRunnable implements Runnable{private String src;public MyRunnable(String src){this.src = src;}@Overridepublic void run(){ Toast.makeText(com.unity3d.player.UnityPlayer.currentActivity, src, Toast.LENGTH_LONG).show();} }
Toast.makeText得在UI线程中调用,直接在方法中调用会报错
public static void Debug(String src){Toast.makeText(com.unity3d.player.UnityPlayer.currentActivity, src, Toast.LENGTH_LONG).show();}
在方法中开启新线程unity会崩溃
public static void Debug(String src){MyRunnable runnable = new MyRunnable(src);Thread payThread = new Thread(runnable);payThread.start(); }
在网上查了一遍原来unity里面有给出的方法
com.unity3d.player.UnityPlayer.currentActivity.runOnUiThread()
用这个调用就没有问题了
public static void Debug(String src){MyRunnable runnable = new MyRunnable(src);com.unity3d.player.UnityPlayer.currentActivity.runOnUiThread(runnable); }最后导出jar包放unity3D里面
最后在unity3D里面调用
public static void MyDebug(string src) {#if UNITY_ANDROID AndroidJavaClass jc = new AndroidJavaClass("com.cc.debug.MyDebug"); jc.CallStatic("Debug", src);#endif Debug.Log(src); }
com.cc.debug.MyDebug 中的com.cc.debug 是包名,MyDebug 是类名。
0 0
- unity3D调用安卓 Toast.makeText
- Toast.makeText
- Toast.makeText 操作便利
- Toast.makeText用法
- Toast.makeText用法
- Android Toast.makeText
- Toast.makeText使用方法
- Toast.makeText().show();
- Toast.makeText()的使用方法
- Toast.maketext()方法解析
- Toast.makeText 程序崩溃
- Toast.makeText 初解
- 消息模式Toast.makeText用法
- 消息模式Toast.makeText用法
- 消息模式Toast.makeText用法
- 消息模式Toast.makeText用法
- 消息模式Toast.makeText用法
- 消息模式Toast.makeText用法
- Java笔记---其他对象、IO流
- Star Schema完全参考手册读书笔记三
- 关于queue和stack没有clear方法
- IOS 系统常用功能
- poj 3974 Palindrome(manacher)
- unity3D调用安卓 Toast.makeText
- LEETCODE-Remove Element
- mysql笔记
- Oracle服务详解
- JAVA从学会配置开发环境开始
- 【软件工程】概览
- IOS 获取系统图库与打开拍照
- test10.1
- sqlite采用UUID主键和int型自增主键性能对比测试