Unity中操作手机常用功能

最近在测试一个小Demo,用到很多手机功能。在这里一一贴出来,以供后期参考

备注:在打包发布时,Plugins下一定要导入如下dll文件,否则build后无法连接数据库<I18N,I18N.West,System.Data,Mysql.Data>

1、操作手机震动;  Handheld.Vibrate();  //震动前自己加条件判断

2、Input框 调用系统输入法:每个插件TextBox控件自带此功能,实用时开启即可,自动调用手机输入法。

3、退出应用程序<不完整>:if(Input.GetKeyDown(KeyCode.Escape)||Input.GetKeyDown(KeyCode.Home))

{

  OpenFileDialog ofd = new OpenFileDialog();

  if(ofd.ShowDialog() ==DialogResult.OK)

    {

      //退出程序

      UnityEngine.Application.Quit();

    }

}

4、调用手机摄像头

IEnumerator OpenCamera(int whichOne)
{
  yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
  if (Application.HasUserAuthorization(UserAuthorization.WebCam))
  {
    //通过调用硬件来获得手机摄像头,不考虑是否自动对焦
    WebCamDevice[] devices = WebCamTexture.devices;
    if (devices.Length <= whichOne)
    {
      cameraName = devices[0].name;
    }
    else
    {
      cameraName = devices[whichOne].name;
    }
    cameraTexture = new WebCamTexture(cameraName, Screen.height, Screen.width, 15);
    cameraTexture.Play(); //在OnGUI里,定义一个sprite 来接收图像。Sprite = cameraTexture;  
    isPlay = true;             //同理,如果是录像取实时图像也可实现?没验证
    }

}

5、Unity3D 连接mysql、sqlserver、sqllite数据库

注意事项:sqlserver、sqllite  需要到unity 安装文件中将  system.Data.dll 与system.sqllite.dll文件拷贝到Plugins目录下。其余操作与Ado.net一致

       操作mysql时,需要自己到网上下载一个mysql.Data.dll 文件。建议5.5版本一下,最好是5.0-5.2左右,版本太高,Unity无法识别加载。其余操作同上。

原文地址:https://www.cnblogs.com/sling/p/3812971.html