| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class OpenGPSView : MonoBehaviour
- {
- private AndroidJavaClass _clsU3D;
- private AndroidJavaObject _objCtx;
- private AndroidJavaClass _objGPSTool;
- public System.Action onOpened;
- private static OpenGPSView ins;
- public static OpenGPSView Init()
- {
- // 已废弃:不再弹出「未开 GPS / 前往打开」引导。地区请在个人资料中填写;无 GPS 设备跳系统定位页无意义。(保留旧实现备查,勿删)
- // if (ins) return null;
- // ModalView modalView = ModalView.Show();
- // OpenGPSView openGPSView = modalView.gameObject.AddComponent<OpenGPSView>();
- // modalView.textKey = "gps_notopen";
- // modalView.onAgreeTextKey = "gps_go-to-open";
- // modalView.onRejectTextKey = "gps_giveup-open";
- // modalView.willDestroyAfterClick = false;
- // modalView.onAgree = () => openGPSView.GoToOpenGPS();
- // modalView.onReject = () => {
- // modalView.willDestroyAfterClick = true;
- // };
- // return openGPSView;
- return null;
- }
- void Awake()
- {
- ins = this;
- }
- void Start()
- {
- _clsU3D = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- _objCtx = _clsU3D.GetStatic<AndroidJavaObject>("currentActivity");
- _objGPSTool = new AndroidJavaClass("com.example.smartbowlib.GPSTool");
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- if (_objGPSTool != null)
- {
- _objGPSTool.Dispose();
- _objGPSTool = null;
- }
- if (_objCtx != null)
- {
- _objCtx.Dispose();
- _objCtx = null;
- }
- if (_objCtx != null)
- {
- _objCtx.Dispose();
- _objCtx = null;
- }
- onOpened = null;
- }
- float time = 0;
- void Update()
- {
- time += Time.deltaTime;
- if (time > 0.1f) {
- time = 0;
- CheckOpenGPS();
- }
- }
- void CheckOpenGPS()
- {
- if (_objGPSTool.CallStatic<bool>("hasOpenGPS", _objCtx))
- {
- Destroy(gameObject);
- Debug.Log("onOpenGPS");
- onOpened?.Invoke();
- Debug.Log("onOpenGPS-Callback-Invoke");
- }
- }
- void GoToOpenGPS()
- {
- // 旧:跳转系统「定位源/GPS」设置页(smartbowlib.GPSTool.goToOpenGPS → ACTION_LOCATION_SOURCE_SETTINGS)(保留,勿删)
- // _objGPSTool.CallStatic("goToOpenGPS", _objCtx);
- }
- }
|