private AssetMenuItem LoadFolder(DirectoryInfo path, AssetMenuItem parent = null) { AssetMenuItem item = new AssetMenuItem(); item.Type = AssetItemType.Folder; item.Name = path.Name; item.Parent = parent; item.SystemPath = path.FullName; item.RelativePath = Path.GetRelativePath(AssetPath, path.FullName); foreach (FileSystemInfo entry in path.EnumerateFileSystemInfos()) { bool isFolder = entry.Attributes.HasFlag(FileAttributes.Directory); if (isFolder) { DirectoryInfo directory = new DirectoryInfo(entry.FullName); AssetMenuItem folderItem = LoadFolder(directory, item); item.Children.Add(folderItem); } else { if (Path.GetExtension(entry.FullName) == ".meta") { continue; } AssetMenuItem fileItem = LoadFile(entry, item); item.Children.Add(fileItem); } } return(item); }
private void LoadAssets() { DirectoryInfo projectDirectory = new DirectoryInfo(AssetPath); AssetMenuItem rootAsset = new AssetMenuItem(); rootAsset.Type = AssetItemType.Folder; rootAsset.Name = projectDirectory.Name; rootAsset.SystemPath = projectDirectory.FullName; rootAsset.RelativePath = Path.GetRelativePath(AssetPath, projectDirectory.FullName); foreach (FileSystemInfo entry in projectDirectory.EnumerateFileSystemInfos()) { bool isFolder = entry.Attributes.HasFlag(FileAttributes.Directory); if (isFolder) { DirectoryInfo directory = new DirectoryInfo(entry.FullName); AssetMenuItem folderItem = LoadFolder(directory, rootAsset); rootAsset.Children.Add(folderItem); } else { if (Path.GetExtension(entry.FullName) == ".meta") { continue; } AssetMenuItem fileItem = LoadFile(entry, rootAsset); rootAsset.Children.Add(fileItem); } } AssetRoot = rootAsset; }
public static void ApplyAssetItemMetaData(ref AssetMenuItem item, XElement metaData) { if (item.Type == AssetItemType.Mesh) { item.Children.Add(CreateSubMeshItem(item, metaData)); } else { } }
public static AssetMenuItem CreateSubMeshItem(AssetMenuItem parent, XElement item) { AssetMenuItem subItem = new AssetMenuItem(); subItem.Type = parent.Type; subItem.Name = item.InnerText(); subItem.Parent = parent; subItem.SystemPath = parent.SystemPath; subItem.RelativePath = parent.RelativePath; subItem.SubItem = true; foreach (XElement elem in item.Elements("Mesh")) { subItem.Children.Add(CreateSubMeshItem(subItem, elem)); } return(subItem); }
private AssetMenuItem LoadFile(FileSystemInfo file, AssetMenuItem parent = null) { string metaPath = Path.ChangeExtension(file.FullName, ".meta"); XElement metaData; if (!File.Exists(metaPath)) { using (StreamWriter metaWriter = File.CreateText(metaPath)) { metaData = CreateAssetMeta(file.FullName); metaData.Save(metaWriter); } File.SetAttributes(metaPath, FileAttributes.Hidden); } else { metaData = XElement.Load(metaPath); } AssetItemType assetType = GetAssetFileType(file.FullName); AssetMenuItem item = new AssetMenuItem(); item.Type = assetType; item.Name = file.Name; item.Parent = parent; item.SystemPath = file.FullName; item.RelativePath = Path.GetRelativePath(AssetPath, file.FullName); foreach (XElement elem in metaData.Elements()) { ApplyAssetItemMetaData(ref item, elem); } return(item); }