Tag: android

从Java调用Unity函数

我是团结的新手: 我在Unity中创建了一个简单的立方体并在其上放置了一些纹理 我旋转立方体…移动相机….然后导出到Android工作室。 当我运行一切看起来像Unity。 但我想从Android工作室代码(编程线)移动相机或立方体,我找不到任何方式..“findViewById”或类似的能够找到我的立方体:) 我尝试制作一个C#文件(我只在资源文件夹中创建一个)并放入: public class test : MonoBehaviour { public GameObject respawn; void Start () { Debug.Log(“aaaaaaaaaaaaa1111111111111111”); if (respawn == null) respawn = GameObject.FindWithTag(“mamaie”); respawn.transform.Rotate(10f, 50f, 10f); } // Update is called once per frame void Update () { transform.Rotate(10f, 50f, 10f); } void LateUpdate() { transform.Rotate(10f, 50f, 10f); } } 那么……我如何从编程线控制我的立方体(在统一设计并在android工作室中导入)?

从Unity3D代码启动android服务

在我的用于android的Unity3D应用程序中,我需要启动一个服务,它将在后台运行。 我无法弄清楚我该怎么做。 必须在活动上调用方法startService() ,但我不知道如何将当前的unity活动从unity脚本传递到我的android插件。 我还没有找到任何方法来获取静态方法中的活动并在其中运行startService() 。 据我了解序列,我需要获得主要的Unity3D活动并从中启动服务。 我的class级应该叫服务。 public final class StatusCheckStarter { public static void StartCheckerService() { startService(new Intent(this, CheckService.class)); } } 这段代码不起作用,因为“无法解析方法startService”而且我没有任何东西要传递给这个参数。 我需要获得当前的活动。

如何从Unity中的代码安装Android apk

我找到了Java代码片段。 如何在C#Unity中编写这样的代码? Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(new File(“link to downloaded file”)),”application/vnd.android.package-archive”); startActivity(intent);

反序列化从Android应用程序发送到WCF Web服务的JSON对象

我正在尝试将JSON对象发送到我的webservice方法,该方法定义如下: public String SendTransaction(string trans) { var json_serializer = new JavaScriptSerializer(); Transaction transObj = json_serializer.Deserialize(trans); return transObj.FileName; } 我想在哪里返回我作为参数获得的这个JSON字符串的FileName。 android应用程序的代码: HttpPost request = new HttpPost( “http://10.118.18.88:8080/Service.svc/SendTransaction”); request.setHeader(“Accept”, “application/json”); request.setHeader(“Content-type”, “application/json”); // Build JSON string JSONStringer jsonString; jsonString = new JSONStringer() .object().key(“imei”).value(“2323232323”).key(“filename”) .value(“Finger.NST”).endObject(); Log.i(“JSON STRING: “, jsonString.toString()); StringEntity entity; entity = new StringEntity(jsonString.toString(), “UTF-8”); entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, […]

UnityWebRequest嵌入HTTP基本身份validation的用户+密码数据不适用于Android

下面的代码用于从我们自己的系统中托管的Thingworx服务器获取温度值。 这在团结中非常有效 。 但是在andoird中 ,一旦生成了apk,它就不会从服务器获取任何数据,并且会建立连接。 但是,它只是不会获取数据并将其放入文本网格中。 我正在使用统一5.4.1 32位。 检入Android – 5.0.2和6。 using UnityEngine; using System.Collections; using UnityEngine.Networking; using System.Text.RegularExpressions; using System; using UnityEngine.UI; public class GETTempValue : MonoBehaviour { public GameObject TempText; static string TempValue; void Start() { StartCoroutine(GetText()); } IEnumerator GetText() { Debug.Log(“Inside Coroutine”); while (true) { yield return new WaitForSeconds(5f); string url = […]

安装时将Resources / StreamingAssets中的文件复制到Application.persistentDataPath

我有txt文件,其中包含我在游戏中的地图数据。 问题是文件存储在Application.persistentDataPath所以我甚至可以从我的android设备(创建的地图创建者)更改它,那么如何在我的PC上创建包含基本地图的txt文件并使其显示在我的android上的persistentDataPath我安装应用程序时的设备?

Unity的安装数据库(SQLite)

我看过太多教程列表,他们都推荐相同的东西。 但是,他们没有帮助解决我的问题。 我试图在我的项目中包含一个SQLite数据库,当构建PC,MAC和Linux Standalone(在Windows机器上测试)时,数据库按预期工作。 在Android设备上进行测试时,出现以下错误。 E/Unity: ArgumentException: Invalid ConnectionString format for parameter “/storage/emulated/0/Android/data/com.tbltools.tbl_project/files/TBLDatabase.db” at Mono.Data.Sqlite.SqliteConnection.ParseConnectionString (System.String connectionString) [0x00000] in :0 at Mono.Data.Sqlite.SqliteConnection.Open () [0x00000] in :0 at UIHandler+c__Iterator2.MoveNext () [0x00000] in :0 at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in :0 我认为对connectionString进行修改应该很简单,但这并没有解决我的问题。 这是我到目前为止: if (Application.platform != RuntimePlatform.Android) { // The name of the db. tblDatabase […]

在streamingAssetsPath上读写文件

这是我在android中读取我的文本文件的方式。 #if UNITY_ANDROID string full_path = string.Format(“{0}/{1}”,Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder); // Android only use WWW to read file WWW reader = new WWW(full_path); while (!reader.isDone){} json = reader.text; // PK Debug 2017.12.11 Debug.Log(json); #endif 这就是我从pc上读取我的文本文件的方法。 #if UNITY_STANDALONE string full_path = string.Format(“{0}/{1}”, Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder); StreamReader reader = new StreamReader(full_path); json = reader.ReadToEnd().Trim(); reader.Close(); #endif 现在我的问题是我不知道如何在移动设备上编写文件因为我在独立版上这样做 #if UNITY_STANDALONE StreamWriter […]