lvjincheng 2 лет назад
Родитель
Сommit
bf99b65666

+ 6 - 0
Assets/BowArrow/Modules/NewUserGuider/NewUserGuiderManager.cs

@@ -30,6 +30,12 @@ public class NewUserGuiderManager : MonoBehaviour
     void Start()
     {
         SceneManager.sceneLoaded += onSceneLoaded; onSceneLoaded_added = true;
+        if (CommonConfig.StandaloneMode)
+        {
+            configKeyList.Remove("切换好友/排行榜");
+            configKeyList.Remove("展开好友/排行榜");
+            configKeyList.Remove("联机游戏");
+        }
     }
 
     bool onSceneLoaded_added = false;

+ 9 - 0
Assets/BowArrow/Scripts/CommonConfig.cs

@@ -70,4 +70,13 @@ public class CommonConfig
     //游戏对战服务器
     public static string gamePKServerWsURL;
     public static int serverIndex { get => AppArea; }
+    /// <summary>
+    /// 弓箭SDK的服务端地址
+    /// </summary>
+    public static readonly string SmartBowSdkURL = "http://43.132.127.96/SmartBowBusinessServer";
+
+    /// <summary>
+    /// 单机模式是否开启
+    /// </summary>
+    public static bool StandaloneMode = true;
 }

+ 1 - 1
Assets/BowArrow/Scripts/Entry.cs

@@ -89,7 +89,7 @@ public class Entry : MonoBehaviour
         timeOnStartLoadScene = Time.realtimeSinceStartup;
         //加载场景名
         string sceneName = "Login";
-        if (LoginMgr.HasToken()) {
+        if (LoginMgr.HasToken() || CommonConfig.StandaloneMode) {
             sceneName = "Home";
         }
         countStr2 += sceneName;

+ 5 - 1
Assets/BowArrow/Scripts/Manager/HomeMgr.cs

@@ -35,7 +35,11 @@ public class HomeMgr : MonoBehaviour
 
     void Start()
     {
-        UserPlayer.ConnectServer();
+        if (CommonConfig.StandaloneMode)
+        {
+            DoTweenUtil.CallDelay(0.1f, () => new UserPlayer());
+        }
+        else UserPlayer.ConnectServer();
     }
 
     void OnDestroy()

+ 22 - 0
Assets/BowArrow/Scripts/Manager/LoginMgr/LoginMgr.cs

@@ -78,8 +78,30 @@ public class UserInfo
     //闯关记录(gameType:通关数)(野兔、野鸡、野狼的通关数)
     public Dictionary<int, int> challengeLevels = new Dictionary<int, int>();
     public string guideRecord = "";
+    public static UserInfo LoadLocal(int id)
+    {
+        UserInfo result = null;
+        if (CommonConfig.StandaloneMode)
+        {
+            try
+            {
+                result = JsonConvert.DeserializeObject<UserInfo>(PlayerPrefs.GetString("UserInfo_" + id));
+                if (result == null) throw new Exception("UserInfo.LoadLocal Null");
+            }
+            catch (Exception e)
+            {
+                Debug.LogError(e);
+            }
+        }
+        return result;
+    }
     public void Save()
     {
+        if (CommonConfig.StandaloneMode)
+        {
+            PlayerPrefs.SetString("UserInfo_" + id, JsonConvert.SerializeObject(this));
+            return;
+        }
         try { UserComp.Instance.saveUserInfo(this); } catch (System.Exception e) { Debug.LogError(e.Message); }
     }
     public void SetChallengeLevelPass(int gameType, int level)

+ 32 - 0
Assets/BowArrow/Scripts/Network/SocketComp/UserComp.cs

@@ -1,4 +1,8 @@
 using System;
+using System.Collections;
+using UnityEngine;
+using UnityEngine.Networking;
+using Newtonsoft.Json;
 
 /* Socket组件-用户 */
 public class UserComp : JCUnityLib.Singleton<UserComp>
@@ -29,6 +33,15 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
             };
             UserPlayer.ins.call("userComp.saveMac", new object[]{mac}, cb);
         }
+        if (CommonConfig.StandaloneMode)
+        {
+            WWWForm form = new WWWForm();
+            form.AddField("mac", mac);
+            JCUnityLib.CoroutineStarter.Start(Post(CommonConfig.SmartBowSdkURL + "/SmartBowSDK/getCalibrateRecord", form, (res) =>
+            {
+                if (res.code == 0) onResumeCalibrateRecord(res.data as string);
+            }));
+        }
     } 
 
     public void saveCalibrateRecord(string record) {
@@ -42,6 +55,13 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
             Axis9CalibrateRecord.CacheCalibrateRecord(mac, record);
             Axis9CalibrateRecord.SetCalibrateOkRecord(mac, true);
             UserPlayer.ins.call("userComp.saveCalibrateRecord2", type, record, mac);
+            if (CommonConfig.StandaloneMode)
+            {
+                WWWForm form = new WWWForm();
+                form.AddField("mac", mac);
+                form.AddField("record", record);
+                JCUnityLib.CoroutineStarter.Start(Post(CommonConfig.SmartBowSdkURL + "/SmartBowSDK/saveCalibrateRecord", form, null));
+            }
         }
     }
 
@@ -64,4 +84,16 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
         AimHandler.ins.ResumeCalibrateRecord(record);
     }
     #endregion
+
+    public static IEnumerator Post(string url, WWWForm form, Action<RequestResult> callback)
+    {
+        using (UnityWebRequest request = UnityWebRequest.Post(url, form))
+        {
+            yield return request.SendWebRequest();
+            if (request.result == UnityWebRequest.Result.Success)
+                callback?.Invoke(JsonConvert.DeserializeObject<RequestResult>(request.downloadHandler.text));
+            else
+                callback?.Invoke(new RequestResult());
+        }
+    }
 }

+ 7 - 0
Assets/BowArrow/Scripts/Network/UserPlayer.cs

@@ -107,6 +107,13 @@ public class UserPlayer : JCEntity
     //获取用户信息,失败了就重试
     public void GetUserInfo()
     {
+        if (CommonConfig.StandaloneMode)
+        {
+            UserInfo userInfo = UserInfo.LoadLocal(0);
+            if (userInfo == null) userInfo = new();
+            DoAfterGetUserInfo(userInfo);
+            return;
+        }
         UserPlayer userPlayer = this;
         CoroutineStarter.Start(LoginController.Instance.GetUserInfo((res) =>
         {

+ 8 - 2
Assets/BowArrow/Scripts/View/Home/HomeView.cs

@@ -39,13 +39,19 @@ public class HomeView : JCUnityLib.ViewBase
         TopBarView.NeedShowIt(this);
         if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
 
-        if (LoginMgr.myUserInfo.id > 0) {
+        if (LoginMgr.myUserInfo.id > 0 || (CommonConfig.StandaloneMode && UserPlayer.ins != null && UserPlayer.ins.hasGetUserInfo)) {
             RenderNameOrGender();
             RenderMyAvatarSprite();
             RenderDeviceNames();
         }
 
-        StartCoroutine(RefreshFriendBar());
+        if (CommonConfig.StandaloneMode)
+        {
+            transform.Find("FriendBar").gameObject.SetActive(false);
+            transform.Find("RightPanel/Line (1)").gameObject.SetActive(false);
+            transform.Find("RightPanel/Item (1)").gameObject.SetActive(false);
+        }
+        else StartCoroutine(RefreshFriendBar());
     }
 
     void OnDestroy()

+ 5 - 1
Assets/BowArrow/Scripts/View/Home/MeView.cs

@@ -21,12 +21,16 @@ public class MeView : ViewBase, MenuBackInterface
             inputs.transform.GetChild(2).gameObject.SetActive(false);
             transform.Find("BtnSave").Translate(Vector3.up * 25, Space.Self);
         }
-        if (CommonConfig.banBindRelateAccount)
+        if (CommonConfig.banBindRelateAccount || CommonConfig.StandaloneMode)
         {
             inputs.transform.GetChild(2).gameObject.SetActive(false);
             inputs.transform.GetChild(3).gameObject.SetActive(false);
             (transform.Find("BtnSave") as RectTransform).anchoredPosition = new Vector2(154, -208);
         }
+        if (CommonConfig.StandaloneMode)
+        {
+            transform.Find("BtnDeleteAccount").gameObject.SetActive(false);
+        }
 
         RenderAfterSave();
     }

+ 5 - 0
Assets/BowArrow/Scripts/View/Home/SettingsView.cs

@@ -11,6 +11,11 @@ public class SettingsView : JCUnityLib.ViewBase, MenuBackInterface
             transform.Find("Items/GameSetup").GetComponentInChildren<TextAutoLanguage>().SetText(1234560);
             transform.Find("BtnQuitGame").GetComponentInChildren<TextAutoLanguage>().SetText(1234561);
         }
+        if (CommonConfig.StandaloneMode)
+        {
+            transform.Find("Items/BtnsRow/BtnQutiLogin").gameObject.SetActive(false);
+            transform.Find("Items/BtnsRow/BtnQuitGame").transform.localPosition = Vector3.zero;
+        }
     }
 
     void Start()