public SkillBase(SpriteController obj, int skillID) { State = SkillState.None; this.owner = obj; this.CurCD = 0f; dataVo = ConfigManager.GetSkillDataById(skillID); if (owner.actionMng != null && owner.actionMng.TryGetAnimationLength(dataVo.actionName, out curAniLength)) { curAniLength -= 0f; } else { curAniLength = 1f; } if (dataVo.BufferID.Length > 0) { dataVo.bufferEntity = new BufferDataVo[dataVo.BufferID.Length]; for (int i = 0; i < dataVo.bufferEntity.Length; i++) { dataVo.bufferEntity[i] = ConfigManager.GetConfigBufferData(dataVo.BufferID[i]); } } aniName = dataVo.actionName; //加载特效 GameObject effecPre = LoadCache.LoadEffect(dataVo.effectName); if (effecPre != null) { effect = GameObject.Instantiate(effecPre) as GameObject; effect.SetActive(false); } }
/// <summary> /// 获取需要删除的资源配置表 by吴江 /// </summary> /// <param name="_newData">新场景所需要的整体资源</param> /// <param name="_oldData">原场景已经有的整体资源</param> /// <returns>新场景还需要加载的资源表</returns> public static void UnLoadUseness(List<SceneConfigData> _newData) { List<string> unloadTexList = new List<string>(); List<string> unloadMatList = new List<string>(); SceneConfigData allNeed = MergeNeed(_newData); foreach (var item in LoadCache.textureRefDic.Keys) { if (!allNeed.textureDataList.Contains(item)) unloadTexList.Add(item); } foreach (var item in LoadCache.materialRefDic.Keys) { if (!allNeed.materialDataList.Contains(item)) unloadMatList.Add(item); } for (int i = 0; i < unloadTexList.Count; i++) { LoadCache.UnLoad(unloadTexList[i], AssetType.texture); } for (int i = 0; i < unloadMatList.Count; i++) { LoadCache.UnLoad(unloadMatList[i], AssetType.material); } }
/// <summary> /// 获取需要新加载的资源配置表 by吴江 /// </summary> /// <param name="_newData">新场景所需要的整体资源</param> /// <param name="_oldData">原场景已经有的整体资源</param> /// <returns>新场景还需要加载的资源表</returns> private SceneConfigData GetNeedLoad(SceneConfigData _newData) { SceneConfigData needLoadData = SceneConfigData.CreateInstance<SceneConfigData>(); needLoadData.name = _newData.name; needLoadData.instanceID = _newData.instanceID; //获取旧场景中不存在的新资源 foreach (var newData in _newData.textureDataList) { if (!LoadCache.HasLoaded(newData, AssetType.texture) && !needLoadData.textureDataList.Contains(newData)) { needLoadData.textureDataList.Add(newData); } } foreach (var newData in _newData.shaderDataList) { if (!LoadCache.HasLoaded(newData, AssetType.shader) && !needLoadData.shaderDataList.Contains(newData)) { needLoadData.shaderDataList.Add(newData); } } foreach (var newData in _newData.materialDataList) { if (!LoadCache.HasLoaded(newData, AssetType.material) && !needLoadData.materialDataList.Contains(newData)) { needLoadData.materialDataList.Add(newData); } } return needLoadData; }
private void ConfigureLoadCommand() { LoadCache = ReactiveCommand.Create(_cacheService.LoadCachedRepositories); LoadCache.IsExecuting.ToPropertyEx(this, x => x.Loading); LoadCache.ThrownExceptions.Subscribe(x => { //TODO handle exceptions }); LoadCache.Where(x => x != null && x.Any()) .Do(async cache => await AddRepositories(cache)).Subscribe(); LoadCache.Where(x => x != null && !x.Any()) .Select(x => Unit.Default) .InvokeCommand(LoadNext); }
protected void BindMaterialDepend(List<MaterialAsset> _materialAssetList) { foreach (var materialAsset in _materialAssetList) { string matName = materialAsset.matName.ToLower(); if (!LoadCache.HasLoaded(matName, AssetType.material)) { Debug.Log(matName + "找不到"); continue; } MaterialRelationship rl = materialAsset.materialRelationship; Material mat = LoadCache.GetMaterial(matName);//materialAssetBundleRefDic[materialAsset.matName].mainAsset as Material; if (rl != null && mat.name.ToLower().Equals(rl.matName.ToLower())) { mat.shader = Shader.Find(rl.sdName);//GetShader(rl.sdName);//shaderAssetBundleRefDic[rl.sdName].mainAsset as Shader; foreach (var item in rl.propertyPairList) { ShaderPropertyType type = (ShaderPropertyType)item.type; switch (type) { case ShaderPropertyType.Color: mat.SetColor(item.propertyName, item.color); break; case ShaderPropertyType.Vector: mat.SetVector(item.propertyName, item.v4); break; case ShaderPropertyType.Float: case ShaderPropertyType.Range: mat.SetFloat(item.propertyName, item.value); break; case ShaderPropertyType.TexEnv: if (LoadCache.HasLoaded(item.texName, AssetType.texture)) { mat.SetTexture(item.propertyName, LoadCache.GetTexture(item.texName));//textureAssetBundleRefDic[item.texName].mainAsset as Texture); } break; default: break; } } } } }
/// <summary> /// 根据关联性配置组装物体 /// </summary> /// <param name="_prefab"></param> /// <param name="_relationship"></param> public void ProcessGameObjectRelation(GameObject _prefab, GameObjectRelationship _relationship) { if (_prefab == null || _relationship == null) return;//如果物体为空或关联性配置为空,返回 if (_relationship.matNames.Count > 0 && _prefab.GetComponent<Renderer>() != null)//如果关联性配置中数据为0或者该物体没有渲染组件,返回 { int count = _relationship.matNames.Count; Material[] matArray = _prefab.GetComponent<Renderer>().sharedMaterials; for (int i = 0; i < count; i++)//遍历关联性配置数据 { if (i >= matArray.Length) { Debug.LogError(_prefab.name + "的配置文件记录的材质数量与实际材质数量不符合,请美术检查资源!"); break; } if (LoadCache.HasLoaded(_relationship.matNames[i], AssetType.material))//如果材质资源缓存中有关联性配置中需求的材质 { matArray[i] = LoadCache.GetMaterial(_relationship.matNames[i]);//materialAssetBundleRefDic[_relationship.matNames[i]].mainAsset as Material; if (matArray[i] != null && matArray[i].shader != null) { Shader temp = Shader.Find(matArray[i].shader.name); if (temp != null) matArray[i].shader = temp; } } else { Debug.LogError(_prefab.name + " , can't find material that names " + _relationship.matNames[i] + " , please check it ! " + LoadCache.materialRefDic.Count); } } _prefab.GetComponent<Renderer>().sharedMaterials = matArray; //_prefab.SetActive(true); } //对子物体进行递归 if (_prefab.transform.childCount > 0 && _relationship.childRelationList.Count > 0) { int fixedCount = Mathf.Min(_prefab.transform.childCount, _relationship.childRelationList.Count); for (int i = 0; i < fixedCount; i++) { ProcessGameObjectRelation(_prefab.transform.GetChild(i).gameObject, _relationship.childRelationList[i]); } } }
/// <summary> /// 驱动贴图加载进程的递归函数 /// </summary> /// <param name="_mainPath">资源主路径</param> /// <param name="_list">资源列表</param> /// <param name="_index">当前进度</param> protected void DownloadTexture(string _mainPath, List<string> _list, int _index) { if (_list.Count > _index) { string name = _list[_index]; //如果缓存列表中已经有,则不再重复下载 if (LoadCache.HasLoaded(name, AssetType.texture) || LoadCache.waitTexture.Contains(name)) { return; } else { texturePendings++; LoadCache.waitTexture.Add(name); string Path = _mainPath + name + ".texture"; AssetMng.instance.LoadAsset<Texture>(Path, (x, y) => { texturePendings--; LoadCache.waitTexture.Remove(name); LoadCache.textureRefDic[name] = x; }); } } }
/// <summary> /// 驱动材质加载进程的递归函数 /// </summary> /// <param name="_mainPath">资源主路径</param> /// <param name="_list">资源列表</param> /// <param name="_index">当前进度</param> protected void DownloadMaterial(string _mainPath, List<string> _list, int _index) { if (_list.Count > _index) { string name = _list[_index]; //如果缓存列表中已经有,则不再重复下载 if (LoadCache.HasLoaded(name, AssetType.material) || LoadCache.waitMaterial.Contains(name)) { return; } else { materialPendings++; LoadCache.waitMaterial.Add(name); string Path = _mainPath + name + ".material"; AssetMng.instance.LoadAsset<Material>(Path, (x, y) => { materialPendings--; LoadCache.waitMaterial.Remove(name); LoadCache.materialRefDic[name] = x; }); } } }