Browse Source

修改报错地方

胡佳骏 1 year ago
parent
commit
edc06c3801
2 changed files with 25 additions and 7 deletions
  1. 9 3
      Assets/2.0/Tools/LoadManager.cs
  2. 16 4
      Assets/2.0/Tools/MsgHandler.cs

+ 9 - 3
Assets/2.0/Tools/LoadManager.cs

@@ -49,7 +49,7 @@ public class LoadManager : Singleton<LoadManager>
     public void load(ModelItem model, Action<float> onProgress, Action<GameObject> callback)
     {
         string dName = getLoadName(model.url, model.Version);
-        Debug.Log("dName ======>   " + dName);
+        Debug.Log("dName ======>   " + dName+ "   model.url==>"+ model.url);
         if (!downList.ContainsKey(dName))
         {
             GameObject obj = new GameObject(dName);
@@ -83,8 +83,14 @@ public class LoadManager : Singleton<LoadManager>
 
                             break;
                     }
-                    Debug.Log(" LoadManager  "+ dName + "  Length :  "+ downList[dName].downLoadData.Length);
-                    model.SetData(downList[dName].downLoadData);
+                    if(downList[dName].downLoadData!=null)
+                    {
+                        Debug.Log(" LoadManager  " + dName + "  Length :  " + downList[dName].downLoadData.Length);
+                        model.SetData(downList[dName].downLoadData);
+                    }else if(model.prefabModel==null)
+                    {
+                        model.prefabModel = new GameObject("空物体"+ downList[dName].id);
+                    }
                     callback.Invoke(model.prefabModel);
                 }
 

+ 16 - 4
Assets/2.0/Tools/MsgHandler.cs

@@ -1,6 +1,7 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using XRTool.Util;
 
 public class MsgHandler : MonoBehaviour
 {
@@ -16,11 +17,22 @@ public class MsgHandler : MonoBehaviour
     /// <param name="handler"></param>
     public static void AddListener(string msgType, DelMsgHandler handler)
     {
-        //判空
-        if (mDicMsgs == null) mDicMsgs = new Dictionary<string, DelMsgHandler>();
-        if (!mDicMsgs.ContainsKey(msgType)) mDicMsgs.Add(msgType, null);
+        try
+        {
+
+            //判空
+            if (mDicMsgs == null) mDicMsgs = new Dictionary<string, DelMsgHandler>();
+            if (!mDicMsgs.ContainsKey(msgType)) mDicMsgs.Add(msgType, null);
+            mDicMsgs[msgType] += handler;
+        }
+        catch
+        {
+            TimerMgr.Instance.CreateTimer(()=> {
+                handler.Invoke(new Msg("", null));
+            },1);
+           // mDicMsgs[msgType] += handler;
+        }
         //增加监听
-        mDicMsgs[msgType] += handler;
 
     }
     /// <summary>