| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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()
- {
- 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;
- }
- 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()
- {
- _objGPSTool.CallStatic("goToOpenGPS", _objCtx);
- }
- }
|