Просмотр исходного кода

1.修复android 微信登录 判断
2.添加单机上传分数

slambb 2 лет назад
Родитель
Сommit
53ef62e001

+ 3 - 0
Assets/BowArrow/Scripts/GlobalData.cs

@@ -12,6 +12,9 @@ public class GlobalData
     public static int matchGameType;
     public static int playerIndexInRoom;
     public static List<MatchPlayerInfo> matchPlayerInfos;
+
+    //单机游戏的gameType
+    public static int singlePlayerGameType;
 }
 /**接收别人的PK邀请时,会设置GlobalData的数据,如果这时候主页存在层级页面,接收PK邀请但又突然要返回,
 这时候层级页面设置过的GlobalData可能会被好友邀请修改过,因此主页用GlobalDataTemp存储可能会被干涉的数据,

+ 7 - 1
Assets/BowArrow/Scripts/Manager/LoginMgr/WeChatLoginHelper.cs

@@ -8,7 +8,13 @@ public class WeChatLoginHelper
 {
     public static bool IsWechatInstalled() {
 #if UNITY_ANDROID
-       return true;
+        using (var sdk = new AndroidJavaClass("com.xmjssvr.BowArrow.mi.WeChatSDK"))
+        {
+            bool bInstalled = sdk.CallStatic<bool>("IsWXAppInstalled");
+            //Debug.Log("°²Ñb΢ÐÅ£º"+ bInstalled);
+            return bInstalled;
+        }
+     
 #endif
 
 #if UNITY_IPHONE

+ 10 - 0
Assets/BowArrow/Scripts/Network/SocketComp/RankComp.cs

@@ -14,4 +14,14 @@ public class RankComp : JCUnityLib.Singleton<RankComp>
             gameRes
         );
     }
+
+    //单机上传结果
+    public void uploadSinglePlayerGameRes(int score)
+    {
+        UserPlayer.ins.call(
+            "rankComp.uploadSinglePlayerGameRes",
+            GlobalData.singlePlayerGameType,
+            score
+        );
+    }
 }

+ 1 - 0
Assets/BowArrow/Scripts/View/Home/HomeView_ChallengeOption.cs

@@ -188,6 +188,7 @@ public class HomeView_ChallengeOption : MonoBehaviour
         //Debug.Log("gameType:"+ gameType+ ",GlobalDataTemp.pkMatchType:"+ GlobalDataTemp.pkMatchType);
         AudioMgr.ins.PlayBtn();
         GameMgr.gameType = gameType;
+        GlobalData.singlePlayerGameType = gameType;
         if (gameType == 15)
         {
             SceneManager.LoadScene("FruitMaster", LoadSceneMode.Single);

+ 20 - 2
Assets/DuckHunter/Scripts/GameManager.cs

@@ -30,6 +30,8 @@ namespace DuckHunter
                 _CumulativeScore = 0;
             }
             level = DefaultLevel;
+
+            uploadScore = 0;
         }
 
         void OnDestroy()
@@ -89,6 +91,7 @@ namespace DuckHunter
         public static int DefaultLevel = 1;
         private static bool AutoNextLevel = false;
         [System.NonSerialized] public int hitScore; //得分
+        private int uploadScore;//上传服务器的分数
         [System.NonSerialized] public int level = 1;
         /// <summary>
         /// 通关需要击落的鸭子数量
@@ -263,6 +266,7 @@ namespace DuckHunter
             GameUI.Instance.RenderHitDuckCount(duck.config.type);
             // GameUI.Instance.RenderHitScore(hitScore, GetBestScore());
             _CumulativeScore += scoreToPlus;
+            uploadScore += scoreToPlus; //击杀野鸭分数
             GameUI.Instance.RenderHitScore(_CumulativeScore, GetBestScore());
             GameUI.Instance.ShowTextHitScore(scoreToPlus, duck.transform.position);
             RemoveArrows(duck);
@@ -273,7 +277,7 @@ namespace DuckHunter
             CrossHair.Instance?.UpdatePositionByModuleRotation(rotation);
         }
 
-        public void OnModuleShooting(float speed,bool bAddCount = false)
+        public void OnModuleShooting(float speed, bool bAddCount = false)
         {
             if (CrossHair.Instance)
             {
@@ -383,6 +387,7 @@ namespace DuckHunter
                     hitScore += plusScore;
                     // GameUI.Instance.RenderHitScore(hitScore, GetBestScore());
                     _CumulativeScore += plusScore;
+                    uploadScore += plusScore;
                     GameUI.Instance.RenderHitScore(_CumulativeScore, GetBestScore());
                     TextGameScreenCenter.Instance.ShowText(TextGameScreenCenter.TextName.SUPER_ARCHER, new object[] { plusScore }, ShowGamePass);
                     AudioManager.Instance.PlayFullScore();
@@ -393,10 +398,23 @@ namespace DuckHunter
                 }
             }
 
+            //通过关卡时候,上传一次分数
+            onUploadScore();
+
             SaveBestScore();
 
             GameOverInterface.OnGameOver(GameMgr.gameType);
         }
+        //野鸭退出时候保存分数到服务器
+        public void onUploadScore()
+        {
+            if (uploadScore > 0)
+            {
+                Debug.Log("野鸭上传的积分为:" + uploadScore);
+                RankComp.Instance.uploadSinglePlayerGameRes(uploadScore);
+                uploadScore = 0;
+            }
+        }
 
         void ShowGamePass()
         {
@@ -460,7 +478,7 @@ namespace DuckHunter
                 //         break;
                 //     }
                 // }
-                if(bAddCount) userGameAnalyse1.changeShootingCount(1);
+                if (bAddCount) userGameAnalyse1.changeShootingCount(1);
                 _arrowCount--;
                 GameUI.Instance.RenderArrowCount(arrowCount);
                 return true;

+ 4 - 0
Assets/DuckHunter/Scripts/GameUI.cs

@@ -45,6 +45,10 @@ namespace DuckHunter
                 AudioManager.Instance.PlayBtn();
                 // UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);
 
+                //野鸭退出时候操作一次分数
+                Debug.Log("野鸭btnBack上传的积分:" );
+                GameManager.Instance.onUploadScore();
+
                 //结束游戏页面
                 GameManager.Instance.userGameAnalyse1.showResultView(() => {
                     UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);

+ 19 - 0
Assets/FruitMaster/Scripts/GamingManager.cs

@@ -41,6 +41,7 @@ public class GamingManager : MonoBehaviour
     [SerializeField] private CannonController Cannon;
     [SerializeField] private GameObject FullscreenClearBubble;
     [SerializeField] private int StartScores;
+    private int uploadScore;//需要上传的分数
     [SerializeField] private float AimingCrossPosMultiplier = 1f;
 
     [SerializeField] private Camera Cam;
@@ -283,6 +284,7 @@ public class GamingManager : MonoBehaviour
         CameraToLook.ins.onParseRotation += UpdateRotation;
 
         Scores = StartScores;
+        uploadScore = Scores;
         ScoreText.text = "Scores : " + Scores;
         Combos = 0;
         MakeNewWaveCountdown = GamingValues.MakeNewWaveCountdown;
@@ -490,13 +492,29 @@ public class GamingManager : MonoBehaviour
         bGameStarted = false;
         ShowGamingUI(false);
 
+        //水果上传分数
+        onUploadScore();
+
         OnGameEnd.Invoke(reason, Scores);
+
+    
+    }
+    //水果上传分数到服务器
+    void onUploadScore() {
+        if (uploadScore > 0)
+        {
+            Debug.Log("水果游戏上传的积分为:" + uploadScore);
+            RankComp.Instance.uploadSinglePlayerGameRes(uploadScore);
+            uploadScore = 0;
+        }
     }
     /**
      * 点击结束按钮再触发
      */
     public void onShowResultView() {
 
+        onUploadScore();
+
         //结束游戏页面
         userGameAnalyse1.showResultView(()=> {
             UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);
@@ -686,6 +704,7 @@ public class GamingManager : MonoBehaviour
     {
         int last_scores = Scores;
         Scores += score;
+        uploadScore += score;
         ScoreText.text = "Scores : " + Scores; // update socres display
         return ((Scores / 100) == (last_scores / 100) + 1);
     }

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


+ 17 - 0
Assets/WildAttack/Scripts/Manager/GameMananger.cs

@@ -28,6 +28,7 @@ namespace WildAttack
         public int HPMax { get { return hpMax; } }
 
         private int totalScore = 0;
+        private int uploadScore = 0;
         public int TotalScore { get { return totalScore; } }
         public int barrelTriggerCount = 0;
 
@@ -87,6 +88,7 @@ namespace WildAttack
             hpMax = Mathf.FloorToInt(GameModule.GetInstance().GetData("wallHp"));
             hp = hpMax;
             totalScore = 0;
+            uploadScore = 0;
             barrelTriggerCount = 0;
             //shootSpawn = GameModule.GetInstance().GetData("downTime");
             shootSpawn = 0;
@@ -171,12 +173,25 @@ namespace WildAttack
                 ads.Play();
             }
 
+            //关卡结束时候触发
+            OnUploadScore();
+
             // 调用其他管理类的GameOver
             ProcessManager.GetInstance().GameOver(false);
             if (!isWin) EnemyManager.GetInstance().GameOver();
             UIManager.GetInstance().HideMainPanel();
         }
+        //荒野射击上传分数到服务器
+        public void OnUploadScore() {
+            if (uploadScore > 0)
+            {
+                //游戏结束上传一个分数
+                Debug.Log("荒野射击上传的积分为:" + uploadScore);
+                RankComp.Instance.uploadSinglePlayerGameRes(uploadScore);
+                uploadScore = 0;
+            }
 
+        }
         /// <summary>
         /// 血量
         /// </summary>
@@ -217,6 +232,8 @@ namespace WildAttack
         public void AddScore(int score)
         {
             totalScore += score;
+            //只记录一个上传的分数
+            uploadScore += score;
         }
         public void SetScore(int score)
         {

+ 3 - 0
Assets/WildAttack/Scripts/UI/GameOverPanel.cs

@@ -62,6 +62,9 @@ namespace WildAttack
             //#endif
             AudioMgr.ins.PlayBtn();
 
+            //退出按钮时候上传一次分数
+            GameMananger.GetInstance().OnUploadScore();
+
             UserGameAnalyse1.Instance.showResultView(() => {
                 UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);
             });