public void ChangeEffect(string newEffectName) { ContentContainer cc = ContentContainer.Instance(); cc.RemoveEffectListener(this, effectName); info.RequiredShader = newEffectName; //We should register before we will use immediately mode. cc.AddEffectListener(this, newEffectName); effect = cc.GetEffect(newEffectName, true); }
public Material(MaterialInformation info, ContentContainer contentContainer, bool immediately = false) { this.name = info.Name; this.info = info; foreach (var p in info.Textures) { contentContainer.AddTextureListener(this, p.Value); textures.Add(p.Key, contentContainer.GetTexture(p.Value, immediately)); } effectName = info.RequiredShader; contentContainer.AddEffectListener(this, info.RequiredShader); effect = contentContainer.GetEffect(info.RequiredShader, immediately)?.Clone(); TextureChangedHandler += (s, e) => { string type = ""; foreach (var p in info.Textures) { if (p.Value.Equals(e.LastName)) { type = p.Key; break; } } switch (e.Action) { case ContentAction.Add: textures[type] = e.New; break; case ContentAction.Remove: textures[type] = null; break; case ContentAction.Rename: ContentContainer cc = ContentContainer.Instance(); info.textures.Remove(type); textures.Remove(type); cc.RemoveTextureListener(this, e.LastName); info.textures.Add(type, e.NewName); cc.AddTextureListener(this, e.NewName); textures.Add(type, cc.GetTexture(e.NewName, true)); break; case ContentAction.Replace: textures[type] = e.New; break; } }; EffectChangedHandler += (s, e) => { ContentContainer cc = ContentContainer.Instance(); switch (e.Action) { case ContentAction.Add: //TODO, assert effect == null effect = e.New.Clone(); break; case ContentAction.Remove: effect.Dispose(); effect = null; break; case ContentAction.Rename: cc.RemoveEffectListener(this, e.LastName); info.RequiredShader = e.NewName; effectName = e.NewName; cc.AddEffectListener(this, e.NewName); if (effect != null) { effect.Dispose(); } effect = cc.GetEffect(e.NewName, true)?.Clone(); break; case ContentAction.Replace: if (effect != null) { effect.Dispose(); } effect = e.New?.Clone(); break; } }; }