internal override void OnDestroy() { // 删除所有材质 // // 删除new shared Material // foreach (KeyValuePair <Renderer, Material[]> kayValue in mNewMatDic) { for (int j = 0; j < kayValue.Value.Length; ++j) { if (kayValue.Value[j] != null) { Material.Destroy(kayValue.Value[j]); kayValue.Value[j] = null; } } } mNewMatDic.Clear(); mNewMatDic = null; // 删除效果上的材质 // foreach (KeyValuePair <string, MaterialEffect> kayValue in mMatEffectDic) { MaterialEffect me = kayValue.Value; me.DestoryMaterial(); me = null; } mMatEffectDic.Clear(); mMatEffectDic = null; base.OnDestroy(); }
internal void UpdateSharedMaterials(string[] repalceShaderName) { foreach (Renderer r in Entity.GameObject.GetComponentsInChildren <Renderer>(true)) { if (LayerDef.Effect == r.transform.gameObject.layer) { continue; } if (!(r is MeshRenderer || r is SkinnedMeshRenderer)) { continue; } Material[] ms = r.materials;// new Material[r.sharedMaterials.Length]; if (!mNewMatDic.ContainsKey(r)) { mNewMatDic.Add(r, ms); } } if (repalceShaderName != null) { int count = repalceShaderName.Length; for (int i = 0; i < count; i++) { MaterialEffect outEffect = null; if (mMatEffectDic.TryGetValue(repalceShaderName[i], out outEffect)) { outEffect.UpdateNewMatDic(); } } } }
internal void ClearEffect() { mNewMatDic.Clear(); mNewMatDic = null; // 删除效果上的材质 // foreach (KeyValuePair <string, MaterialEffect> kayValue in mMatEffectDic) { MaterialEffect me = kayValue.Value; me.DestoryMaterial(); me = null; } mMatEffectDic.Clear(); mMatEffectDic = null; }
internal void ReplaceShader(MaterialEffectInfo info) { if (mNewMatDic.Count <= 0) { // 创建新的材质,防止材质的泄露 // ChangeSharedMaterials(); } mIsOriginalshader = false; mCurShaderName = info.shaderName; MaterialEffect outEffect = null; if (!mMatEffectDic.TryGetValue(info.name, out outEffect)) { outEffect = new MaterialEffect(info, this.Entity); mMatEffectDic.Add(info.name, outEffect); outEffect.ReplaceMaterial(); } else { outEffect.mInfo = info; outEffect.ReplaceMaterial(true); } }