Browse Source

修复null exception

大爷 1 year ago
parent
commit
b83e9abadb

+ 5 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/Camera/CameraMgr.cs

@@ -21,8 +21,12 @@ namespace ET.Client
             MainCamera = Camera.main;
             MainCamera.transform.SetPositionAndRotation(new Vector3(90, 35, 26.6f), Quaternion.Euler(20, 20, 0));
             MainCamera.fieldOfView = 60;
+
             var light = GameObject.Find("/Light");
-            light.transform.rotation = Quaternion.Euler(0, 20, 0);
+            if (light != null)
+            {
+                light.transform.rotation = Quaternion.Euler(0, 20, 0);
+            }
 
             if (Director == null)
             {

+ 52 - 47
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/CreateHUD.cs

@@ -80,62 +80,53 @@ namespace ET.Client
         }
     }
 
-    /*[Event]
-    public class SkillChangeEventHandler : BEvent<SkillChangeEvent>
-    {
-        protected override async ETTask OnEvent(SkillChangeEvent a)
-        {
-            Log.Debug("actor's skill changed.");
-            await ETTask.CompletedTask;
-        }
-    }*/
-
     [Event]
     public class HPRefreshEventHandler : BEvent<HPRefresh>
     {
         protected override async ETTask OnEvent(HPRefresh a)
         {
-            var view = UIHelper.GetUI("HUD") as GComponent;
-            if (view != null)
+            if (UIHelper.GetUI("HUD") == null)
+            {
+                return;
+            }
+
+            GProgressBar progress = null;
+            switch (a.HPIndex)
+            {
+                case HPRefresh.Index.Tower:
+                    progress = HUDComonent.pgTower;
+                    HUDComonent.pgTKLike.visible = a.Visible;
+                    break;
+                case HPRefresh.Index.Boss1:
+                    progress = HUDComonent.pgBoss1;
+                    break;
+                case HPRefresh.Index.Boss2:
+                    progress = HUDComonent.pgBoss2;
+                    break;
+                case HPRefresh.Index.Boss3:
+                    progress = HUDComonent.pgBoss3;
+                    break;
+                case HPRefresh.Index.Boss4:
+                    progress = HUDComonent.pgBoss4;
+                    break;
+                case HPRefresh.Index.TiktokLike:
+                    progress = HUDComonent.pgTKLike;
+                    break;
+            }
+                
+            progress.visible = a.Visible;
+            if (a.Visible)
             {
-                GProgressBar progress = null;
-                switch (a.HPIndex)
+                progress.value = a.Progress;
+                var name = progress.GetChild("name");
+                if (name != null)
                 {
-                    case HPRefresh.Index.Tower:
-                        progress = HUDComonent.pgTower;
-                        HUDComonent.pgTKLike.visible = a.Visible;
-                        break;
-                    case HPRefresh.Index.Boss1:
-                        progress = HUDComonent.pgBoss1;
-                        break;
-                    case HPRefresh.Index.Boss2:
-                        progress = HUDComonent.pgBoss2;
-                        break;
-                    case HPRefresh.Index.Boss3:
-                        progress = HUDComonent.pgBoss3;
-                        break;
-                    case HPRefresh.Index.Boss4:
-                        progress = HUDComonent.pgBoss4;
-                        break;
-                    case HPRefresh.Index.TiktokLike:
-                        progress = HUDComonent.pgTKLike;
-                        break;
+                    name.text = a.Name;
                 }
-                
-                progress.visible = a.Visible;
-                if (a.Visible)
+                var txt = progress.GetChild("title");
+                if (txt != null)
                 {
-                    progress.value = a.Progress;
-                    var name = progress.GetChild("name");
-                    if (name != null)
-                    {
-                        name.text = a.Name;
-                    }
-                    var txt = progress.GetChild("title");
-                    if (txt != null)
-                    {
-                        txt.text = a.Title;
-                    }
+                    txt.text = a.Title;
                 }
             }
             await ETTask.CompletedTask;
@@ -147,6 +138,11 @@ namespace ET.Client
     {
         protected override async ETTask OnEvent(RankChangeEvent a)
         {
+            if (UIHelper.GetUI("HUD") == null)
+            {
+                return;
+            }
+
             var list = HUDComonent.listRank;
             if (list == null) return;
 
@@ -197,6 +193,10 @@ namespace ET.Client
     {
         protected override async ETTask OnEvent(ShowUIAnimation a)
         {
+            if (UIHelper.GetUI("HUD") == null)
+            {
+                return;
+            }
             var view = HUDComonent.Root;
             if (view == null) return;
 
@@ -245,6 +245,11 @@ namespace ET.Client
     {
         protected override async ETTask OnEvent(TiktokGiftEvent a)
         {
+            if (UIHelper.GetUI("HUD") == null)
+            {
+                return;
+            }
+
             var comp = HUDComonent.listGift[a.index - 1];
             comp.GetChild("Text1").text = a.nickname;
             comp.GetChild("Text2").text = "X" + a.num;