public void _Deserialize(YAML.Node node) { if (node == null) { UnityEngine.Debug.Log("No Data"); return; } if (node.Children != null) { for (int i = 0; i < node.Children.Count; ++i) { YAML.Node child = node.Children[i]; if (child.Value == null) { outPut += GeneralString(child.depth, " ") + child.Name + "\n"; } else { outPut += GeneralString(child.depth, " ") + child.Name + ":" + child.Value + "\n"; } if (child.Children != null) { _Deserialize(child); } } } }
protected bool ProcessCommandFile(string fileName, Dictionary <string, object> args) { bool ok = true; _log.InfoFormat("Processing command file {0}", fileName); YAML.Parser parser = new YAML.Parser(); YAML.Node root = parser.ParseFile(fileName, args); foreach (var cmdNode in root) { if (_commands.Contains(cmdNode.Key)) { var cmdArgs = cmdNode.ToDictionary(); DecryptValues(cmdArgs); ok = ok && InvokeCommand(cmdNode.Key, cmdArgs); } else { throw new ArgumentException(string.Format("Unknown command '{0}' encountered in command file {1}", cmdNode.Key, fileName)); } if (!ok) { break; } } return(ok); }
private static void GenerateCopySceneOrPrefabTest() { string outPut = ""; YAML.Node node = YAML.Load(Application.dataPath + "/prefabs/Canvas.prefab"); //test 1 // List<YAML.Node> lstAttributeNode = node.AttributeForGenerateCode();//将要产生在代码内的对象,未筛选 // List<YAML.Node> ScriptNodes = new List<YAML.Node>(); // node.Find("MonoBehaviour", ScriptNodes); // if (ScriptNodes.Count == 0) // return; // foreach (var sn in ScriptNodes) // { // foreach (var n in sn.Children) // { // if (n.Value != null) // { // Dictionary<string, YAML.Node> valueNode = YAML.DeserializeValue(n.Value); // foreach (KeyValuePair<string, YAML.Node> kvp in valueNode) // { // Debug.Log(string.Format("Key:{0}; Value:{1}", kvp.Value.Name, kvp.Value.Value)); // } // } // } // // } //test 2 /* * * --- !u!114 &360487655 * MonoBehaviour: * m_ObjectHideFlags: 0 * m_PrefabParentObject: {fileID: 0} * m_PrefabInternal: {fileID: 0} * m_GameObject: {fileID: 360487649} * m_Enabled: 1 * m_EditorHideFlags: 0 * m_Script: {fileID: 11500000, guid: 1c5fb6a982960fd4285cfe1773af15d7, type: 3} * m_Name: * m_EditorClassIdentifier: * TestButton: {fileID: 0} * hhhhText: {fileID: 0} */ YAML.Node nodeNew = new YAML.Node(); nodeNew.Name = "--- !u!114 &114437434465559884"; nodeNew.Value = null; node.Children.Add(nodeNew); YAML.Node nodeScriptNew = new YAML.Node(); nodeScriptNew.Name = "MonoBehaviour"; nodeScriptNew.Value = " "; nodeScriptNew.AddNode("m_ObjectHideFlags", " 1", 2, "114437434465559884", "");//fileID在非脚本属性里是随机的,只要保持唯一即可,格式是定死的。 nodeScriptNew.AddNode("m_PrefabParentObject", " {fileID: 0}", 2, "114437434465559884", ""); nodeScriptNew.AddNode("m_PrefabInternal", " {fileID: 100100000}", 2, "114437434465559884", ""); nodeScriptNew.AddNode("m_GameObject", " {fileID: 1659991782575188}", 2, "114437434465559884", ""); //此处是挂载对象 预设走m_RootGameObject属性。此外,需要在m_RootGameObject fileid归属上加上component,component的fileid与这个脚本的fileid保持一致 nodeScriptNew.AddNode("m_Enabled", " 1", 2, "114437434465559884", ""); nodeScriptNew.AddNode("m_EditorHideFlags", " 0", 2, "114437434465559884", ""); nodeScriptNew.AddNode("m_Script", " {fileID: 11500000, guid: 1c5fb6a982960fd4285cfe1773af15d7, type: 3}", 2, "114437434465559884", ""); nodeScriptNew.AddNode("m_Name", " ", 2, "114437434465559884", ""); nodeScriptNew.AddNode("m_EditorClassIdentifier", " ", 2, "114437434465559884", ""); nodeScriptNew.AddNode("TestButton", " {fileID: 0}", 2, "114437434465559884", ""); nodeScriptNew.AddNode("hhhhText", " {fileID: 0}", 2, "114437434465559884", ""); node.Children.Add(nodeScriptNew); foreach (var sn in node.Children) { if (sn.RootFileID == "1659991782575188") { } } outPut = YAML.Instance.Deserialize(node); YAML.Instance.Write(Application.dataPath + "/prefabs/CanvasCopy.prefab", outPut); }
public string Deserialize(YAML.Node node) { outPut = ""; _Deserialize(node); return(outPut); }