-
Unity 定位
2017-11-07 11:32:08获取经纬度 可以用Unity本身的Input.location。(弊端:性能不强 ,部分手机获取不到,信号不好时获取不到,手机太老获取不到,始终显示状态为:LocationServiceStatus.Initializing) 方法二: 接SDK (我这里接...老样子 只说操作
定位的方法:1. 获取经纬度 可以用Unity本身的Input.location。(弊端:性能不强 ,部分手机获取不到,信号不好时获取不到,手机太老获取不到,始终显示状态为:LocationServiceStatus.Initializing)
方法二: 接SDK (我这里接的是高德定位)
先说方法一:
创建脚本:
方法二:SDK定位using UnityEngine; using System.Collections; public class GetGPS : MonoBehaviour { public string gps_info = ""; public int flash_num = 1; // Use this for initialization void Start() { } void OnGUI() { GUI.skin.label.fontSize = 28; GUI.Label(new Rect(20, 20, 600, 300), this.gps_info); GUI.Label(new Rect(20, 350, 600, 48), this.flash_num.ToString()); GUI.skin.button.fontSize = 50; if (GUI.Button(new Rect(Screen.width / 2 - 110, 200, 220, 85), "GPS定位")) { StartGPS(); } if (GUI.Button(new Rect(Screen.width / 2 - 110, 500, 220, 85), "刷新GPS")) { this.gps_info = " 刷新GPSN:" + Input.location.lastData.latitude + " 刷新GPSE:" + Input.location.lastData.longitude; this.gps_info +=" 状态:" + Input.location.status; this.flash_num += 1; } } //开启定位 void StartGPS() { if (!Input.location.isEnabledByUser) { this.gps_info += "定位没有开启:" + Input.location.isEnabledByUser.ToString(); } else { Input.location.Start(10.0f, 10.0f); this.gps_info += "正在开启定位Start:"; } } //获取定位 void GetUnityGPS() { if (Input.location.status == LocationServiceStatus.Stopped) { this.gps_info="定位服务已经停止"; } else if (Input.location.status == LocationServiceStatus.Initializing) { this.gps_info = " 定位服务正在初始化,在一段时间后,状态会切换回来"; } else if (Input.location.status == LocationServiceStatus.Running) { this.gps_info = "成功定位"; } else if (Input.location.status == LocationServiceStatus.Failed) { this.gps_info = "位置服务失败(用户拒绝访问位置服务)"; } } }
1.获取key (官网上有,关于在发布正式版本的时候要把自己Unity生成的签名key放在C:\Users\Administrator\.android下,然后用控制台的方式输出你的key)
2.获取Jar包(下载高德的一键下载包里 有一个AMapLocation文件 里面只有一个jar包,在eclips编译的时候用(我这里只说的是定位))
3.参考http://blog.csdn.net/u011192809/article/details/52355125?locationNum=3(里面已经说的很详细了可以获取的很全面)
我留了两个测试apk和完整Unity项目
-
unity 定位
2015-12-27 22:45:27定位玩家的当前位置,(不用太精细)实现步骤:(说明,因为项目不需要定位太过精细,所以将逆地址解析放在了服务端,如果需要精细的定位的话,需要在客户端接SDK的)1、使用unity的api获取当前设备的经纬度, ...总结一下前段时间做的地理定位功能吧
需求:定位玩家的当前位置,(不用太精细)
实现步骤:(说明,因为项目不需要定位太过精细,所以将逆地址解析放在了服务端,如果需要精细的定位的话,需要在客户端接SDK的)
1、使用unity的api获取当前设备的经纬度,
\
2、将经纬度上传到服务端,3、通过服务端访问百度或者高德的定位服务(这一步不再细说,需要注册百度或高德的开发者账户然后获得key)
4、从服务端获得地址解析的信息
具体实现如下:
IEnumerator StartGPS() { //MyDebuger.LogWarning("IEnumerator StartGPS()"); GetGPSStatus status = GetGPSStatus.Initializing; // Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置 // LocationService.isEnabledByUser 用户设置里的定位服务是否启用 if (!Input.location.isEnabledByUser) { gps_info = "isEnabledByUser value is:" + Input.location.isEnabledByUser.ToString() + " Please turn on the GPS"; } //LocationService.Start();//启动位置服务的更新,最后一个位置坐标会被使用 Input.location.Start(1.0f, 1.0f); int maxWait = 20; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { // 暂停协同程序的执行(1秒) yield return new WaitForSeconds(1); maxWait--; } if (Input.location.status == LocationServiceStatus.Failed) { gps_info = "Unable to determine device location"; } else { gps_info = "N南北:" + Input.location.lastData.latitude + " E东西:" + Input.location.lastData.longitude; gps_info = gps_info + " Time:" + Input.location.lastData.timestamp; } if (maxWait < 1) { gps_info = "超时";//"Init GPS service time out"; status = GetGPSStatus.OutTime; } else { status = (GetGPSStatus)Enum.Parse(typeof(GetGPSStatus),Input.location.status.ToString()); } StopGPS(); List<object> list_obj = new List<object>(); list_obj.Add(status); //UIMgr.Single().postMsg((int)_eUiMsg.GetGPSStatus,list_obj); //发送定位点的经纬度 }
其中的Input.location.lastData.latitude 和 Input.location.lastData.longitude就是获得的设备经纬度
-
Unity定位SDK介绍
2020-03-23 16:11:59Unity地图及定位SDK是腾讯位置服务专门为游戏开发者打造的国内首套纯Unity矢量渲染引擎。它是基于真实地图数据建立的统一应用程序的工具集合,帮助游戏开发人员在游戏中轻松添加需要LBS能力...其中Unity定位SDK是一...Unity地图及定位SDK是腾讯位置服务专门为游戏开发者打造的国内首套纯Unity矢量渲染引擎。它是基于真实地图数据建立的统一应用程序的工具集合,帮助游戏开发人员在游戏中轻松添加需要LBS能力支持的游戏场景。如街区排行,实景展示,陌生人社交,附近好友等。同时因为它是基于Unity开发的,所以极大降低了游戏开发者的接入成本,可以通过C#脚本和图形化界面轻松创建游戏对象。
其中Unity定位SDK是一套基于Unity引擎并且简单易用的LBS服务定位接口,开发者可以在游戏场景中便捷地为应用程序添加定位功能,包括开启定位、获取指定精度的位置信息、结束定位等。前期准备
申请开发者密钥,申请地址:https://lbs.qq.com/dev/console/key/manage
在进行key设置时, 填写key名称及描述,代表key的作用和使用场景。
下载Unity开发工具
版本要求:Unity 5.6.3及以上
下载地址:
1. https://store.unity.com/cn/download?ref=personal
库和资源导入
1. 创建一个新的工程,在Assets目录下新建一个文件夹,命名为Plugins;将下载的压缩包解压,将TencentLocationSDK.dll放到Assets/Plugins目录下。
- 如果准备发布到Android平台,请选择DLL4Android目录下TencentLocationSDK.dll;
- 如果准备发布到IOS平台,请选择DLL4Ios目录下的TencentLocationSDK.dll\
-
2. 将解压出的TencentLocationSDK.unitypackage资源包导入工程。点击上方主菜单中的Assets,选择 Import Package ->Custom Package, 之后选择解压出的TencentLocationSDK.unitypackage文件,在弹出的窗口中显示导入资源的名称;
- 如果准备发布到Android平台,请选择Android⽬录;
- 如果准备发布到IOS平台,请选择iOS目录。
1. 点击主菜单中的File——New Scene,新建一个场景。
2. 将TencentLocationService.cs挂载到任意一个GameObject上,例如Main Camera。
3. 挂载TencentLocationService.cs后, 配置申请的API_Key;
下载地址:
-
unity 定位服务GPS API
2017-04-21 15:23:54在unity的官方文档中,与设备定位(GPS经纬度、水平精度等等)相关的API,目前我只找到两个:LocationService 和 LocationInfo 。 先来个简单的理解: LocationService 负责启动和关闭定位服务。 LocationInfo ...Unity使用GPS 的API
在unity的官方文档中,与设备定位(GPS经纬度、水平精度等等)相关的API,目前我只找到两个:LocationService 和 LocationInfo 。
先来个简单的理解:
LocationService 负责启动和关闭定位服务。
LocationInfo 在服务启动后,获取定位数据信息。
LocationService
官方说明链接:
http://docs.unity3d.com/Documentation/ScriptReference/LocationService.Start.html
LocationService 中有三个属性,和两个方法:
(1)isEnabledByUser -- 用户设置里的定位服务是否启用。(实测发现,都为true,似乎不大起作用)
(2)lastData -- 最近一次测量的地理位置(LocationInfo lastData; 也就是要和 LocationInfo 关联了)
(3)status -- 定位服务的状态。
定位服务的状态包括:
Stopped
Location service is stopped. 定位服务已经停止
Initializing
Location service is initializing, some time later it will switch to. 定位服务正在初始化,在一段时间后,状态会切换回来。
Running
Location service is running and locations could be queried. 位置服务正在运行,位置可以获取。
Failed
Location service failed (user denied access to location service). 位置服务失败(用户拒绝访问位置服务)。(4)Start ( ) -- 启动定位服务,更新定位数据。可以获取最近更新的位置坐标。
数据接收,是通过
Input.location.lastData 来实现的。服务不能马上获得定位数据。
代码必须检查Input.location.status
以获取当前的定位服务状态。看一下函数定义:
void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);
参数详解:
desiredAccuracyInMeters 服务所需的精度,以米为单位。如果使用较高的值,比如500,那么通常不需要打开GPS芯片(比如可以利用信号基站进行三角定位),从而节省电池电量。像5-10这样的值,可以被用来获得最佳的精度。默认值是10米。
updateDistanceInMeters 最小距离(以米为单位)的设备必须横向移动前Input.location属性被更新。较高的值,如500意味着更少的开销。默认值是10米。(5)Stop ( ) -- 停止定位服务的定位更新。这对节省电池的电量非常有用。void
LocationInfo
属性如下:
(1) altitude -- 海拔高度
(2) horizontalAccuracy -- 水平精度
(3) latitude -- 纬度
(4) longitude -- 经度
(5) timestamp -- 最近一次定位的时间戳,从1970开始
(6) verticalAccuracy -- 垂直精度
这些属性,除了timestamp为double外, 其余全为 float 型。
下面是Unity使用GPS 的例子
1,新建一个项目。
2,编写脚本 GetGPS.cs ,挂到主摄像机上。
- using UnityEngine;
- using System.Collections;
- public class GetGPS : MonoBehaviour {
- public string gps_info = "";
- public int flash_num = 1;
- // Use this for initialization
- void Start () {
- }
- void OnGUI () {
- GUI.skin.label.fontSize = 28;
- GUI.Label(new Rect(20,20,600,48),this.gps_info);
- GUI.Label(new Rect(20,50,600,48),this.flash_num.ToString());
- GUI.skin.button.fontSize = 50;
- if (GUI.Button(new Rect(Screen.width/2-110,200,220,85),"GPS定位"))
- {
- // 这里需要启动一个协同程序
- StartCoroutine(StartGPS());
- }
- if (GUI.Button(new Rect(Screen.width/2-110,500,220,85),"刷新GPS"))
- {
- this.gps_info = "N:" + Input.location.lastData.latitude + " E:"+Input.location.lastData.longitude;
- this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
- this.flash_num += 1;
- }
- }
- // Input.location = LocationService
- // LocationService.lastData = LocationInfo
- void StopGPS () {
- Input.location.Stop();
- }
- IEnumerator StartGPS () {
- // Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置
- // LocationService.isEnabledByUser 用户设置里的定位服务是否启用
- if (!Input.location.isEnabledByUser) {
- this.gps_info = "isEnabledByUser value is:"+Input.location.isEnabledByUser.ToString()+" Please turn on the GPS";
- return false;
- }
- // LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用
- Input.location.Start(10.0f, 10.0f);
- int maxWait = 20;
- while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
- // 暂停协同程序的执行(1秒)
- yield return new WaitForSeconds(1);
- maxWait--;
- }
- if (maxWait < 1) {
- this.gps_info = "Init GPS service time out";
- return false;
- }
- if (Input.location.status == LocationServiceStatus.Failed) {
- this.gps_info = "Unable to determine device location";
- return false;
- }
- else {
- this.gps_info = "N:" + Input.location.lastData.latitude + " E:"+Input.location.lastData.longitude;
- this.gps_info = this.gps_info + " Time:" + Input.location.lastData.timestamp;
- yield return new WaitForSeconds(100);
- }
- }
- }
3,导出到手机,运行,即可看到效果。
转职至:http://blog.csdn.net/chenggong2dm/article/details/24488469
-
Unity定位安卓闪退问题
2020-11-04 16:28:43具体参考 http://www.xuanyusong.com/archives/4441 -
基于腾讯地图SDK的Unity定位交友功能的实现
2018-08-09 14:29:53》层级处理 1)地图 、 UI 层级处理 UI摄像机有五个,camera的depth从49-56。地图的要在所有UI之下,所以depth设为48。 2)UI,特效层级 特效要夹在在UI之间,所有特效之下的UI的RenderQ改成StartAt调... -
Unity之GPS定位
2020-08-01 17:18:24Unity之GPS定位 -
unity 自带定位
2018-07-24 17:58:29public struct Longlatitude { public double Longitude; public double latitude; } public class GPSManager { private const double EARTH_RADIUS = 6378137;... private static bool bStart=f... -
Unity ScrollRect滑动定位优化
2017-04-06 08:56:01Unity ScrollRect滑动定位优化 -
Unity快速定位指定路径
2019-06-24 10:45:11在做Unity安卓的文件序列化和反序列化的时候,用到了...用到编译器扩展的方式,以下代码,快速定位 using UnityEngine; using UnityEditor; public class FindData : MonoBehaviour { [MenuItem("Assets/Open... -
Unity GPS定位之逆地理编码(获取经纬度并转换成地理位置)
2019-09-03 23:21:11unity定位 前言 最近在做一款手游,然后策划给的需求就是定位到当前用户所在的城市,然后花了一个上午给做了出来,思路大概就是 新的改变 我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown... -
unity+百度定位
2019-09-26 14:25:43最近一直在弄双百大赛的事情,昨天参加了一个交流会,讲了一些通过...再说说定位吧,昨天下定决心弄了一晚上,终于弄好了,果然只有制定短时间计划才能有效率工作,期间遇到了超多的困难,首先就是android与unity交... -
Unity ios 高德定位
2017-11-22 16:50:54这篇文章主要说的是 Unity 发布ios 接高德定位 获取定位信息 教程尽量说详细点 稍后配上工程目录 1.登录高德开放平台 主要参照高德文档来 第一步 点击获取key 然后按照里面的教程来很详细,我就不多说了 ... -
oculus unity_呼吁所有VR爱好者:通过Unity Free定位Oculus Rift
2020-09-07 04:09:13oculus unity 好消息! 现在可以使用 Oculus 的 Unity Free集成 。 (Great news! The Unity Free integration for Oculus is now available.) Oculus的Unity Free集成使您可以访问与Unity Pro用户完全相同的Oculus... -
Unity之GPS定位详解
2017-09-21 12:13:15关于gps的定位服务,原生的IOS和Android都可以实现,但是Unity和ios、android的交互略微麻烦。因此Unity官方给我们提供好了关于gps的服务,就在我们熟悉的Input当中。他就是Input.Location; 相关的API,有... -
unity crash 问题定位
2020-03-03 17:55:00跟据平台用不通的命令 类似 这样 D:\android-ndk-r16b-windows-x86_64\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin\aarch64-... -
Unity系统自带定位系统
2018-07-24 20:09:56之前发了一篇unity获取 当前 IP地址所在的位置信息 而且是利用百度的接口返回结果的:链接 https://blog.csdn.net/chenzhe_n/article/details/81133887 今天这是unity系统内部 主要应用LocationService 和 ... -
unity3d父子定位
2017-05-26 09:03:09跟着动,如果限定世界方向,就必须同时限定位置(update); 跟着动,如果不限定世界方向,位置也不能限定;(不需要 update) -
安卓GPS地图导航定位指南相关-unity高德定位=pokemongo山寨demo安卓版.rar
2019-07-29 16:28:57unity 高德定位=pokemon go 山寨demo安卓版.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。 -
unity通过GPS定位
2017-03-23 18:02:11using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Net; using System.Xml; using System.IO; using System.Text;...public class NewB -
Unity UGUI ScrollView 定位功能
2020-12-14 12:24:53using UnityEngine; using UnityEngine.UI; namespace Core.Misc.Utils ... /// ScrollView定位。自动获取子物体来得到对应scrollRect.vertical(horizontal)NormalizedPosition /// 不支持vertical和horizon -
Unity2018定位游戏场景视图到Scene视图工具编写
2019-11-01 10:23:15当Unity场景中的物体太多,无法在scene视图定位到游戏中看到的物体时,可以通过使用SceneView对当前视图进行定位 应用举例 using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif public class ... -
在Unity中实现GPS定位
2018-03-26 17:03:22关于GPS的定位服务,原生的iOS和Android都可以实现,但是Unity和ios、android的交互略微麻烦。因此Unity官方给我们提供好了关于GPS的服务,就在我们熟悉的Input当中。他就是Input.Location;相关的API,有两个:... -
unity开发 百度地图后台定位
2020-12-09 09:02:09下面展示 百度地图后台定位。...using MR_LBS.Client.Unity3D; using LitJson; using UnityEngine.SceneManagement; //切换到地图界面,与Android相互传递消息,后台定位 public class BaiduMapAPI : M -
Hololens2+Unity——在场景中定位对象(Unity 入门教程 4)
2020-09-11 14:59:04文章目录Hololens2+Unity——在场景中定位对象(Unity 入门教程 4)基础环境导入教程资源添加父对象添加子对象 Hololens2+Unity——在场景中定位对象(Unity 入门教程 4) 基础环境 官方参考教程 编 辑 者: Lance ... -
[Unity]Unity自动添加Android定位权限问题
2019-07-16 19:26:14今年权限问题比较严重,大厂提出去掉一些权限(敏感权限),不然下架。说实话,我们游戏根本就很少用到这些权限,... 但是打包后发现还在申请定位权限,怎么回事。反编译我们游戏的AndroidMainfest文件,咦,ACCESS... -
一次UNITY闪退问题的定位心得
2020-04-11 17:29:17一次UNITY闪退问题的定位心得 https://www.cnblogs.com/timeObjserver/p/10561276.html 最近项目测试发现,运行unity后不退出运行模式,玩了一局后点击 “再来一局”,反复十几局后unity崩掉。 经观察,发现在这...
-
【2021】UI自动化测试框架(Selenium3)
-
CINTA作业九
-
KDDCUP99.zip
-
gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz
-
TimeTable.zip
-
新一轮5G建设招标开启
-
SubstancePainter插件开发-基础入门
-
iapp禁止抓包软件代码
-
转行做IT-第5章 流程控制语句
-
FPGA 之 SOPC 系列(八)程序固化
-
acuity切台.pdf
-
2020牛客暑期多校集训营第六场题解.pdf
-
30个生涯锦囊,带你跳出迷茫,找到适合你的职业方向
-
基于FPGA的滤波器的课程设计与烧录仿真
-
DEV C++安装-2021.01.17.pdf
-
matlab产生正弦波及.mif文件的程序-其它文档类资源
-
课程设计综合最终材料.zip
-
CINTA作业十二
-
中文说明worldserver.conf
-
three.js入门速成