예제 #1
0
        public void AddOrChangeTexture(string type, string textureName)
        {
            ContentContainer cc = ContentContainer.Instance();

            if (info.Textures.ContainsKey(type))
            {
                cc.RemoveTextureListener(this, info.Textures[type]);
                info.textures[type] = textureName;
                cc.AddTextureListener(this, textureName);
                textures[type] = cc.GetTexture(textureName, true);
            }
            else
            {
                info.textures.Add(type, textureName);
                cc.AddTextureListener(this, textureName);
                textures.Add(type, cc.GetTexture(textureName, true));
            }
        }
예제 #2
0
        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;
                }
            };
        }