public void DoLoadModel(string modelPath, string texturePath, object userData, OnLoadModelOverHandler callback, bool instantiate) { if (string.IsNullOrEmpty(modelPath)) { return; } if (callback == null) { Debug.LogError("Empty Callback when LoadResource"); return; } #if UNITY_EDITOR || UNITY_ANDROID // editor模式下可以优先加载Resources目录下的资源,方便测试。发布版本时要清掉不需要的资源 GameObject obj = Resources.Load <GameObject>("model/" + modelPath); if (obj != null) { GameObject goModel; if (instantiate) { goModel = Instantiate(obj) as GameObject; } else { goModel = obj; } if (!string.IsNullOrEmpty(texturePath)) { // 额外加载纹理 Texture tex = Resources.Load <Texture>("model/" + texturePath); callback(goModel, null, userData); } else { // 没有纹理,直接使用 callback(goModel, null, userData); } return; } #endif ModelTaskInfo taskInfo = new ModelTaskInfo(); taskInfo.instantiate = instantiate; taskInfo.userData = userData; // 模型 taskInfo.task = CreateWWW("model/" + modelPath); // 纹理 if (!string.IsNullOrEmpty(texturePath)) { taskInfo.subTask = CreateWWW("texture/" + texturePath); } // 依赖项 List <string> deps = new List <string>(); string key = "model/" + modelPath + GameConfig.ASSETBUNDLE; CollectDependencies(key, ref deps); if (deps.Count > 0) { foreach (var dep in deps) { WWWInfo depTask = CreateWWW(dep); if (depTask != null) { taskInfo.depTask.Add(depTask); } } } // 设置回调 taskInfo.callback = callback; _taskQueue.Add(taskInfo); }
// 加载模型但是不实例化,主要用于换装 public void LoadModel(string modelPath, string texturePath, object userData, OnLoadModelOverHandler callback) { DoLoadModel(modelPath, texturePath, userData, callback, false); }