private void ReSetMaterial(XmlElement newMaterialNode, string effectName) { TreeNode materialRoot = treeViewAssets.Nodes["Materials"]; if (materialRoot == null) { return; } foreach (TreeNode child in materialRoot.Nodes) { if (child.FirstNode.Text != effectName) { continue; } XmlNode oldMaterialNode = child.Tag as XmlNode; if (oldMaterialNode == null) { continue; } XmlNode variables = newMaterialNode.SelectSingleNode("Variables"); foreach (XmlNode childVar in variables) { string varName = childVar.Name; XmlNode varNode = oldMaterialNode.SelectSingleNode(varName); if (varNode != null) { childVar.InnerText = varNode.InnerText; if (childVar.Attributes["resourcename"] != null && varNode.Attributes["resourcename"] != null) { childVar.Attributes["resourcename"].Value = varNode.Attributes["resourcename"].Value; } } } XmlDocument materialDoc = new XmlDocument(); materialDoc.LoadXml(newMaterialNode.OuterXml); XmlWriter writer = XmlWriter.Create(child.Name, new XmlWriterSettings() { Indent = true, IndentChars = "\t", OmitXmlDeclaration = true }); materialDoc.Save(writer); writer.Flush(); writer.Close(); child.Tag = newMaterialNode; RenderMethods.ModifyMaterial(@"Materials\" + Path.GetFileName(child.Name), true); } }
public void ModifyMaterial(string name, string value) { if (m_MaterialsHandle.Visible) { int select = m_MaterialsHandle.GetSelectedIndex(); TreeNode materialsRoot = treeViewAssets.Nodes["Materials"]; treeViewAssets.SelectedNode = materialsRoot.Nodes[select]; } XmlNode materialNode = treeViewAssets.SelectedNode.Tag as XmlNode; if (materialNode != null) { XmlNode varRoot = materialNode.SelectSingleNode("Variables"); if (varRoot == null) { return; } XmlNode variable = varRoot.SelectSingleNode(name); if (variable == null) { return; } if (variable.Attributes["resourcename"] != null) { variable.Attributes["resourcename"].Value = value; } else { variable.InnerText = value; } XmlDocument materialDoc = new XmlDocument(); materialDoc.LoadXml(materialNode.OuterXml); XmlWriter writer = XmlWriter.Create(treeViewAssets.SelectedNode.Name, new XmlWriterSettings() { Indent = true, IndentChars = "\t", OmitXmlDeclaration = true }); materialDoc.Save(writer); writer.Flush(); writer.Close(); treeViewAssets.SelectedNode.Tag = materialNode; m_MaterialsHandle.ModifyMaterial(); RenderMethods.ModifyMaterial(@"Materials\" + Path.GetFileName(treeViewAssets.SelectedNode.Name), false); } }