private void LoadedOneCallback(CSResource obj) { int MaxCount = WaitLoadComponentKey.Count; //例如左手武器/右手武器,可能不同架构使用同种资源,这需要去判定 for (int i = 0; i < MaxCount; i++) { ModelComponentLoadData data = WaitLoadComponentKey[i]; if (obj.FileName == data.FileName) { data.ResPath = obj.Path; ModelComponentLoadedCacheDic[data.Key] = data; AddWaitModelComponent(data); SingleComponentLoaded(); WaitLoadComponentKey.RemoveAt(i); MaxCount--; i--; } } if (WaitLoadComponentKey.Count == 0) { AllComponentLoaded(); } }
/// <summary> /// 添加一个模型的加载数据 /// 在结束解析的时候,开始加载 /// </summary> /// <param name="model"></param> /// <param name="structure"></param> /// <param name="motion"></param> /// <param name="direction"></param> /// <param name="resourceType"></param> /// <param name="resourceAssistType"></param> protected void Load(uint model, EModelStructure structure, CSMotion motion, CSDirection direction, EResourceType resourceType, EResourceAssistType resourceAssistType) { //加载的模型不存在 if (model == 0) { //如果要加载身体模型不存在,那么要注意清理其他的组件 if (structure == EModelStructure.Body) { } return; } long key = GetKey((int)model, (int)motion, (int)direction, (int)structure); ModelComponentLoadData data = null; if (!ModelComponentLoadedCacheDic.TryGetValue(key, out data)) { data = new T(); ModelComponentLoadedCacheDic[key] = data; } data.Model = model; data.Key = key; data.Structure = structure; data.ResourceType = resourceType; data.ResourceAssistType = resourceAssistType; WaitLoadComponentKey.Add(data); }
/// <summary> /// 得到已经下载完成的组件 /// </summary> /// <param name="structure"></param> /// <returns></returns> public ModelComponentLoadData GetWaitModelComponent(EModelStructure structure) { ModelComponentLoadData data = null; if (SleftModelComponentLoadedDic.TryGetValue((int)structure, out data)) { return(data); } return(data); }
private void StartLoadModelRes() { for (int i = 0; i < WaitLoadComponentKey.Count; i++) { ModelComponentLoadData data = WaitLoadComponentKey[i]; data.FileName = data.GetFileName(); if (string.IsNullOrEmpty(data.ResPath)) { CSResourceManager.Instance.AddQueue(data.FileName, EResourceType.Body, LoadedOneCallback, data.ResourceAssistType, false); } } }
/// <summary> /// 每个组件下载完成后,都会加入到等待组装的队列中 /// 等Body完成后进行组装 /// </summary> public void AddWaitModelComponent(ModelComponentLoadData data) { SleftModelComponentLoadedDic[(int)data.Structure] = data; }