public static void ClearBuffer(string setup = "") { YAML.ClearBuffer(setup); if (setup == "") { named_setup.Clear(); } else { if (named_setup.ContainsKey(setup)) { named_setup.Remove(setup); } } }
public T GetChainedNode <T>(string s) where T : YamlNode { s = s.Replace(":", ";"); if (!buffer.ContainsKey(s)) { string[] steps = s.Split(new char[] { ';' }); YamlMappingNode current = YAML.Read(file); int i = 0; try { for (i = 0; i < steps.Length - 1; i++) { current = current.GetNode <YamlMappingNode>(steps[i]); } buffer.Add(s, current.GetNode <T>(steps[steps.Length - 1])); } catch (KeyNotFoundException e) { Debug.Log("failed at " + i + " : " + steps[i] + " of : " + s); throw e; } } return(buffer[s] as T); }
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 static bool SetupExists(string filename) { return(Resources.Load <TextAsset>(YAML.GetYamlFilePath(filename)) != null); }
public static YamlMappingNode GetFile(string filename) { return(YAML.Read(filename)); }