public static YamlObject[] FindScriptInSceneFile(string sceneFile, string guid, bool searchMultiple = true) { if (sceneFile == string.Empty) { return new YamlObject[] { } } ; List <YamlObject> objects = new List <YamlObject>(); try { var file = new FileInfo(sceneFile); var scope = new YamlScope(); using (var input = file.OpenText()) { while (scope.Parse(input)) { if (scope.IsScript(guid)) { objects.Add(new YamlObject(scope)); if (!searchMultiple) { break; } } } } } catch (Exception e) { Debug.LogException(e); } return(objects.ToArray()); }
public static YamlObject ParseAsset(string path) { if (string.IsNullOrEmpty(path)) { return(null); } YamlObject @object = null; try { var file = new FileInfo(path); var scope = new YamlScope(); using (var input = file.OpenText()) { if (scope.Parse(input)) { @object = new YamlObject(scope); } } } catch (Exception e) { Debug.LogException(e); } return(@object); }
public YamlObject(YamlScope scope) { foreach (var line in scope.Lines) { var delimiter = line.IndexOf(':'); if (delimiter < 0) { continue; } var isEmpty = delimiter == line.Length; Fields.Add(line.Substring(0, delimiter).Trim(), new YamlEntry() { Value = isEmpty ? string.Empty : line.Substring(delimiter + 1, line.Length - delimiter - 1).Trim() }); } }