public static XmlDocument LoadXmlDocument(string documentPath) { Pair <string, string> split = ProtocolUtility.SplitProtocol(documentPath); string protocol = split.First; string path = split.Second; if (protocol == "assets") { throw new Exception("LoadXmlDocument does not support asynchronous protocols (" + protocol + "). Use Client Asset Repository."); } XmlDocument result = new XmlDocument(); switch (protocol) { case "resources": TextAsset styleTextAsset = (TextAsset)Resources.Load(path); if (styleTextAsset == null) { throw new FileNotFoundException("Unable to load the TextFile from resource path: " + path); } result.LoadXml(styleTextAsset.text); break; case "file": FileInfo file = new FileInfo(path); if (!file.Exists) { throw new FileNotFoundException(documentPath + " must point to an existing file on disk.", file.FullName); } result.Load(file.FullName); break; default: throw new Exception("Unrecognized protocol (" + protocol + ")"); } // Remove all the comment nodes (this feels like it shouldn't be necessary, but the comments end up getting parsed in weird places as Nodes) List <XmlNode> toRemove = new List <XmlNode>(); foreach (XmlNode node in result.SelectNodes("//comment()")) { toRemove.Add(node); } foreach (XmlNode node in toRemove) { node.ParentNode.RemoveChild(node); } return(result); }
private string UniqueKey(AssetInfo assetInfo) { string path = assetInfo.Path; if (path == null) { Console.Log("NULL Path"); Console.Log("Null path assetinfo = " + assetInfo); //, assetId = " + assetInfo.AssetId.Value.ToString()); Console.Log("Null path asstId = " + assetInfo.AssetId); //, assetId = " + assetInfo.AssetId.Value.ToString()); } if (path == "" || ProtocolUtility.SplitProtocol(path).First == "resources") { return(AssetId.AssetIdNamespace + assetInfo.AssetId.Value.ToString()); } else { return(path); } }
public TweakablesHandler(string path, object objectWithTweakableFields) { if (path == null) { throw new ArgumentNullException("path"); } if (objectWithTweakableFields == null) { throw new ArgumentNullException("objectWithTweakableFields"); } mTweakedObject = objectWithTweakableFields; if (Application.isEditor) { string pathInResources = ProtocolUtility.SplitProtocol(path).Second; FileInfo fileInfo = new FileInfo(Application.dataPath + "/Resources/" + pathInResources + ".xml"); if (!fileInfo.Exists) { throw new FileNotFoundException(fileInfo.FullName); } mWatcher = new FileWatcher(fileInfo); mWatcher.Changed += delegate() { XmlDocument doc = new XmlDocument(); doc.Load(fileInfo.FullName); LoadTweakables(doc); }; } XmlDocument resourcesDoc = XmlUtility.LoadXmlDocument(path); LoadTweakables(resourcesDoc); }