lvjincheng 3 лет назад
Родитель
Сommit
8de5921aed

+ 9 - 6
Assets/BowArrow/Scripts/Components/ScreenShotTester.cs

@@ -6,9 +6,10 @@ using UnityEngine;
 //游戏全屏截图-快捷截图
 public class ScreenShotTester : MonoBehaviour
 {
-    private string saveDir; 
+    private string saveDir;
 
-    public static void Init(string saveDir) {
+    public static void Init(string saveDir = "C:\\Users\\JC\\Desktop\\弓箭截图\\")
+    {
         if (!saveDir.EndsWith("\\")) throw new System.Exception("路径错误");
         if (FindObjectOfType<ScreenShotTester>()) return;
         var comp = new GameObject(typeof(ScreenShotTester).Name).AddComponent<ScreenShotTester>();
@@ -16,14 +17,16 @@ public class ScreenShotTester : MonoBehaviour
         DontDestroyOnLoad(comp);
     }
 
-    void Update() {
-        #if UNITY_EDITOR
-        if (Input.GetKeyDown(KeyCode.S)) {
+    void Update()
+    {
+#if UNITY_EDITOR
+        if (Input.GetKeyDown(KeyCode.S))
+        {
             TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
             string fileName = ts.TotalMilliseconds + ".jpg";
             ScreenCapture.CaptureScreenshot(saveDir + fileName);
             Debug.LogWarning("截图成功-" + fileName);
         }
-        #endif
+#endif
     }
 }

+ 24 - 13
Assets/BowArrow/Scripts/Expand/GPSTool.cs

@@ -9,15 +9,19 @@ public class GPSTool
     //GPS获取地址
     //成功返回:string[]{国,省,市} (数组中不允许有null)
     //失败返回:null
-    public static void GetAddress(Action<string[]> callback) {
-        #if UNITY_ANDROID
-        Func<string[]> func = delegate() {
+    public static void GetAddress(Action<string[]> callback)
+    {
+#if UNITY_ANDROID
+        Func<string[]> func = delegate ()
+        {
+            if (Application.isEditor) return null;
             using (var clsU3D = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
             using (var objCtx = clsU3D.GetStatic<AndroidJavaObject>("currentActivity"))
             using (var objGPSTool = new AndroidJavaClass("com.example.smartbowlib.GPSTool"))
             {
                 string[] address = objGPSTool.CallStatic<string[]>("getAddress", objCtx);
-                if (address != null) {
+                if (address != null)
+                {
                     foreach (var item in address)
                         if (item == null) return null;
                 }
@@ -27,27 +31,34 @@ public class GPSTool
         List<string> permissions = new List<string>();
         permissions.Add(Permission.CoarseLocation);
         permissions.Add(Permission.FineLocation);
-        for (int i = permissions.Count - 1; i >= 0; i--) {
+        for (int i = permissions.Count - 1; i >= 0; i--)
+        {
             if (Permission.HasUserAuthorizedPermission(permissions[i])) permissions.RemoveAt(i);
-        } 
-        if (permissions.Count > 0) {
+        }
+        if (permissions.Count > 0)
+        {
             var requestCB = new PermissionCallbacks();
             int needPermissionCount = permissions.Count;
-            requestCB.PermissionGranted += (s) => {
+            requestCB.PermissionGranted += (s) =>
+            {
                 Debug.Log("用户同意" + s);
                 needPermissionCount--;
                 if (needPermissionCount == 0) callback.Invoke(func.Invoke());
-            }; 
-            requestCB.PermissionDenied += (s) => {
+            };
+            requestCB.PermissionDenied += (s) =>
+            {
                 Debug.Log("用户拒绝" + s);
             };
-            requestCB.PermissionDeniedAndDontAskAgain += (s) => {
+            requestCB.PermissionDeniedAndDontAskAgain += (s) =>
+            {
                 Debug.Log("用户拒绝且要求不再询问" + s);
             };
             Permission.RequestUserPermissions(permissions.ToArray(), requestCB);
-        } else {
+        }
+        else
+        {
             callback?.Invoke(func.Invoke());
         }
-        #endif
+#endif
     }
 }

+ 2 - 2
Assets/BowArrow/Scripts/Manager/HomeMgr.cs

@@ -21,9 +21,9 @@ public class HomeMgr : MonoBehaviour
         Instantiate(SceneResourceManager.Instance.GetPrefab("NewUserGuiderManager"));
     }
 
-    void Start() {
+    void Start()
+    {
         UserPlayer.ConnectServer();
-        // ScreenShotTester.Init("C:\\Users\\JC\\Desktop\\弓箭截图\\");
     }
 
     void OnDestroy()

+ 66 - 33
Assets/BowArrow/Scripts/Manager/LoginMgr/LoginMgr.cs

@@ -11,37 +11,44 @@ public class LoginMgr : MonoBehaviour
 
     public static UserInfo myUserInfo = new UserInfo();
 
-    public void showRegisterView() {
+    public void showRegisterView()
+    {
         loginView.SetActive(false);
         registerView.SetActive(true);
         forgetPWD_View.SetActive(false);
         AgreenmentOption.ins.gameObject.SetActive(true);
     }
 
-    public void showLoginView() {
+    public void showLoginView()
+    {
         loginView.SetActive(true);
         registerView.SetActive(false);
         forgetPWD_View.SetActive(false);
         AgreenmentOption.ins.gameObject.SetActive(true);
     }
 
-    public void showForgetPWD_View() {
+    public void showForgetPWD_View()
+    {
         loginView.SetActive(false);
         registerView.SetActive(false);
         forgetPWD_View.SetActive(true);
         AgreenmentOption.ins.gameObject.SetActive(false);
     }
     public const string LoginTokenKey = "LoginToken";
-    public static bool HasToken() {
+    public static bool HasToken()
+    {
         string loginToken = PlayerPrefs.GetString(LoginMgr.LoginTokenKey, "");
         return string.IsNullOrEmpty(loginToken) ? false : true;
     }
 
-    void Awake() {
+    void Awake()
+    {
         transform.Find("AgreementPopup").gameObject.SetActive(true);
+        ViewMgr.Instance.DestroyAllViews();
     }
 }
-public class UserInfo {
+public class UserInfo
+{
     public int id;
     public int avatarID = 0;
     public string nickname = "超级射手";
@@ -66,47 +73,61 @@ public class UserInfo {
     {
         try { UserComp.Instance.saveUserInfo(this); } catch (System.Exception e) { Debug.LogError(e.Message); }
     }
-    public void SetChallengeLevelPass(int gameType, int level) {
+    public void SetChallengeLevelPass(int gameType, int level)
+    {
         if (gameType != 3 && gameType != 4 && gameType != 5) return;
-        if (challengeLevels.ContainsKey(gameType)) {
-            if (level <= challengeLevels[gameType]) {
+        if (challengeLevels.ContainsKey(gameType))
+        {
+            if (level <= challengeLevels[gameType])
+            {
                 return;
             }
         }
         challengeLevels.Remove(gameType);
         challengeLevels.Add(gameType, level);
     }
-    public int GetChallengeLevelPass(int gameType) {
-        if (challengeLevels.ContainsKey(gameType)) {
+    public int GetChallengeLevelPass(int gameType)
+    {
+        if (challengeLevels.ContainsKey(gameType))
+        {
             return challengeLevels[gameType];
         }
         return 0;
     }
     //判断引导是否完成(服务端保存)
     //index0: 新手引导NewUserGuide
-    public bool IsGuideFinish(int index) {
-        if (index == 0) {
+    public bool IsGuideFinish(int index)
+    {
+        if (index == 0)
+        {
             return PlayerPrefs.GetInt("NewUserGuideFinish_" + LoginMgr.myUserInfo.id, 0) == 1;
         }
         char[] chars = guideRecord.ToCharArray();
-        if (index < chars.Length) {
+        if (index < chars.Length)
+        {
             return chars[index] == '1';
         }
         return false;
     }
-    public void SaveGuideFinish(int index) {
-        if (index == 0) {
+    public void SaveGuideFinish(int index)
+    {
+        if (index == 0)
+        {
             PlayerPrefs.SetInt("NewUserGuideFinish_" + LoginMgr.myUserInfo.id, 1);
             return;
         }
         char[] chars = guideRecord.ToCharArray();
-        if (index < chars.Length) {
+        if (index < chars.Length)
+        {
             if (chars[index] == '1') return;
             chars[index] = '1';
-        } else {
+        }
+        else
+        {
             int newLen = index + 1;
             char[] newChars = new char[newLen];
-            for (int i = 0; i < newLen; i++) {
+            for (int i = 0; i < newLen; i++)
+            {
                 newChars[i] = i < chars.Length ? chars[i] : '0';
             }
             newChars[index] = '1';
@@ -116,7 +137,8 @@ public class UserInfo {
         UserPlayer.ins?.call("userComp.saveGuideRecord", this.guideRecord);
     }
 }
-public class UserSettings {
+public class UserSettings
+{
     //打开BGM
     public bool openBGM = true;
     //打开音效
@@ -126,7 +148,7 @@ public class UserSettings {
     //射击难度
     public int shootLevel = 0;
     //游戏里的箭重,单位克
-    public float actualArrowWeight = 20; 
+    public float actualArrowWeight = 20;
     //弓箭旋转转化
     public BowRotateConvert bowRotateConvert = new BowRotateConvert();
     //游戏中是否固定镜头
@@ -140,19 +162,26 @@ public class UserSettings {
     public HashSet<int> gameRuleGuideFinish = new HashSet<int>();
 
     private static UserSettings _ins;
-    public static UserSettings ins {
-        get {
-            if (_ins == null) {
+    public static UserSettings ins
+    {
+        get
+        {
+            if (_ins == null)
+            {
                 string dataStr = PlayerPrefs.GetString("UserSettings", "{}");
-                try {
+                try
+                {
                     _ins = JsonConvert.DeserializeObject<UserSettings>(dataStr);
                 }
-                catch (System.Exception) {}
-                if (_ins == null) {
+                catch (System.Exception) { }
+                if (_ins == null)
+                {
                     _ins = new UserSettings();
                 }
-                if (CommonConfig.SpecialVersion1) {
-                    if (PlayerPrefs.GetInt("sv1_UserSettings_2", 0) == 0) {
+                if (CommonConfig.SpecialVersion1)
+                {
+                    if (PlayerPrefs.GetInt("sv1_UserSettings_2", 0) == 0)
+                    {
                         PlayerPrefs.SetInt("sv1_UserSettings_2", 1);
                         UserSettings us = _ins;
                         us.bowRotateConvert.screenSize = 60;
@@ -165,7 +194,8 @@ public class UserSettings {
         }
     }
 
-    public void Save() {
+    public void Save()
+    {
         PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
     }
 }
@@ -192,13 +222,15 @@ public class UserSettings {
 结果:
     游戏转动角度:实际转动角度 = r / e
 */
-public class BowRotateConvert {
+public class BowRotateConvert
+{
     public float screenSize = 60; //屏幕尺寸(英寸)
     public float screenDistance = 2.5f; //玩家距离屏幕多远(米)
     [NonSerialized] public float fieldOfView = 25;
 
     //获取建议的屏幕距离
-    public float GetAdviseScreenDistance() {
+    public float GetAdviseScreenDistance()
+    {
         float w = 16;
         float h = 9;
         float s1 = screenSize * 0.0254f;
@@ -208,7 +240,8 @@ public class BowRotateConvert {
     }
 
     // 游戏旋转角度 : 实际旋转角度 (这个版本丢弃掉这个功能-所以直接返回1)
-    public float GetRate() {
+    public float GetRate()
+    {
         return 1;
     }