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(); 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("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("hasOpenGPS", _objCtx)) { Destroy(gameObject); Debug.Log("onOpenGPS"); onOpened?.Invoke(); Debug.Log("onOpenGPS-Callback-Invoke"); } } void GoToOpenGPS() { _objGPSTool.CallStatic("goToOpenGPS", _objCtx); } }