lvjincheng 3 gadi atpakaļ
vecāks
revīzija
810c5e221b

+ 22 - 0
Assets/BowArrow/Scripts/Expand/GPSTool.cs

@@ -0,0 +1,22 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class GPSTool
+{
+    public static string[] GetAddress()
+    {
+        string[] address = null;
+        using (var clsU3D = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
+        {
+            using (var objCtx = clsU3D.GetStatic<AndroidJavaObject>("currentActivity"))
+            {
+                using (var objGPSTool = new AndroidJavaObject("com.example.smartbowlib.GPSTool"))
+                {
+                    address = objGPSTool.Call<string[]>("getProvince", objCtx);
+                }
+            }
+        }
+        return address;
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Expand/GPSTool.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8fc233d8737501a48ba3be1c0a0af852
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 21 - 9
Assets/BowArrow/Scripts/Manager/LoginMgr/RegisterView.cs

@@ -186,16 +186,28 @@ public class RegisterView : MonoBehaviour
         [SerializeField] GameObject locationPickerPrefab;
         private string countryCode = "", stateCode = "", cityCode = "";
         public void OpenLocationPicker() {
-            GameObject o = GameObject.Instantiate(locationPickerPrefab);
-            o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
-                countryCode = info.GetCountryRegion().Item2;
-                stateCode = info.GetState().Item2;
-                cityCode = info.GetCity().Item2;
+            // GameObject o = GameObject.Instantiate(locationPickerPrefab);
+            // o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
+            //     countryCode = info.GetCountryRegion().Item2;
+            //     stateCode = info.GetState().Item2;
+            //     cityCode = info.GetCity().Item2;
+            //     GetInputField(registerInLocation).text = 
+            //         info.GetCountryRegion().Item1 + " " + 
+            //         info.GetState().Item1 + " " + 
+            //         info.GetCity().Item1;
+            // };
+
+            //2022-12-6 gps获取地理位置
+            string[] address = GPSTool.GetAddress();
+            if (address != null) {
+                countryCode = address[0];
+                stateCode = address[1];
+                cityCode = address[2];
                 GetInputField(registerInLocation).text = 
-                    info.GetCountryRegion().Item1 + " " + 
-                    info.GetState().Item1 + " " + 
-                    info.GetCity().Item1;
-            };
+                    countryCode + " " + 
+                    stateCode + " " + 
+                    cityCode;
+            }
         }
     #endregion
 }

+ 29 - 11
Assets/BowArrow/Scripts/View/MeView.cs

@@ -96,11 +96,17 @@ public class MeView : MonoBehaviour, MenuBackInterface
                 inputField.text = LoginMgr.myUserInfo.birthday;
             }
             else if (i == 6) {
+                // countryCode = LoginMgr.myUserInfo.country;
+                // stateCode = LoginMgr.myUserInfo.state;
+                // cityCode = LoginMgr.myUserInfo.city;
+                // System.Tuple<string, string, string> xxx = JC.Unity.Picker.LocationParseComponent.ins.ParseNameByCode(countryCode, stateCode, cityCode);
+                // inputField.text = (xxx.Item1 + " " + xxx.Item2 + " " + xxx.Item3).Trim();
+
+                //渲染后端返回的gps地理位置
                 countryCode = LoginMgr.myUserInfo.country;
                 stateCode = LoginMgr.myUserInfo.state;
                 cityCode = LoginMgr.myUserInfo.city;
-                System.Tuple<string, string, string> xxx = JC.Unity.Picker.LocationParseComponent.ins.ParseNameByCode(countryCode, stateCode, cityCode);
-                inputField.text = (xxx.Item1 + " " + xxx.Item2 + " " + xxx.Item3).Trim();
+                inputField.text = (countryCode + " " + stateCode + " " + cityCode).Trim();
             }
         }
         nameText.text = LoginMgr.myUserInfo.nickname;
@@ -120,16 +126,28 @@ public class MeView : MonoBehaviour, MenuBackInterface
         [SerializeField] GameObject locationPickerPrefab;
         private string countryCode = "", stateCode = "", cityCode = "";
         public void OpenLocationPicker() {
-            GameObject o = GameObject.Instantiate(locationPickerPrefab);
-            o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
-                countryCode = info.GetCountryRegion().Item2;
-                stateCode = info.GetState().Item2;
-                cityCode = info.GetCity().Item2;
+            // GameObject o = GameObject.Instantiate(locationPickerPrefab);
+            // o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
+            //     countryCode = info.GetCountryRegion().Item2;
+            //     stateCode = info.GetState().Item2;
+            //     cityCode = info.GetCity().Item2;
+            //     GetInputField(inputs.transform.GetChild(6)).text = 
+            //         info.GetCountryRegion().Item1 + " " + 
+            //         info.GetState().Item1 + " " + 
+            //         info.GetCity().Item1;
+            // };
+
+            //2022-12-6 gps获取地理位置
+            string[] address = GPSTool.GetAddress();
+            if (address != null) {
+                countryCode = address[0];
+                stateCode = address[1];
+                cityCode = address[2];
                 GetInputField(inputs.transform.GetChild(6)).text = 
-                    info.GetCountryRegion().Item1 + " " + 
-                    info.GetState().Item1 + " " + 
-                    info.GetCity().Item1;
-            };
+                    countryCode + " " + 
+                    stateCode + " " + 
+                    cityCode;
+            }
         }
     #endregion
 

+ 8 - 4
Assets/BowArrow/Scripts/View/RankView.cs

@@ -92,8 +92,10 @@ public class RankView : MonoBehaviour, MenuBackInterface
                     o.transform.Find("Name").GetComponent<Text>().text = nickname;
                     o.transform.Find("Score").GetComponent<Text>().text = score.ToString();
                     if (rankArea == 0) {
-                        string countryStr = JC.Unity.Picker.LocationParseComponent.ins.ParseNameByCode(country, "", "").Item1.Trim();
-                        o.transform.Find("Country").GetComponent<Text>().text = countryStr;
+                        // string countryStr = JC.Unity.Picker.LocationParseComponent.ins.ParseNameByCode(country, "", "").Item1.Trim();
+                        // o.transform.Find("Country").GetComponent<Text>().text = countryStr;
+                        //后端返回的gps地理位置
+                        o.transform.Find("Country").GetComponent<Text>().text = country;
                     } else {
                         o.transform.Find("Country").GetComponent<Text>().text = "";
                     }
@@ -119,8 +121,10 @@ public class RankView : MonoBehaviour, MenuBackInterface
                     o.transform.Find("Name").GetComponent<Text>().text = nickname;
                     o.transform.Find("Score").GetComponent<Text>().text = score.ToString();
                     if (rankArea == 0) {
-                        string countryStr = JC.Unity.Picker.LocationParseComponent.ins.ParseNameByCode(country, "", "").Item1.Trim();
-                        o.transform.Find("Country").GetComponent<Text>().text = countryStr;
+                        // string countryStr = JC.Unity.Picker.LocationParseComponent.ins.ParseNameByCode(country, "", "").Item1.Trim();
+                        // o.transform.Find("Country").GetComponent<Text>().text = countryStr;
+                        //后端返回的gps地理位置
+                        o.transform.Find("Country").GetComponent<Text>().text = country;
                     } else {
                         o.transform.Find("Country").GetComponent<Text>().text = "";
                     }

BIN
Assets/Plugins/Android/smartbowlib-debug.aar