public void ImportUxmlFromProject(BuilderLibraryTreeItem projectCategory, bool includePackages) { var assets = AssetDatabase.FindAllAssets(m_SearchFilter); var categoryStack = new List <BuilderLibraryTreeItem>(); foreach (var asset in assets) { var assetPath = AssetDatabase.GetAssetPath(asset.instanceID); var prettyPath = assetPath; prettyPath = Path.GetDirectoryName(prettyPath); prettyPath = prettyPath.ConvertSeparatorsToUnity(); if (prettyPath.StartsWith("Packages/") && !includePackages) { continue; } if (prettyPath.StartsWith(BuilderConstants.UIBuilderPackageRootPath)) { continue; } var split = prettyPath.Split('/'); AddCategoriesToStack(projectCategory, categoryStack, split); var vta = asset.pptrValue as VisualTreeAsset; var newItem = new BuilderLibraryTreeItem(asset.name + ".uxml", null, typeof(TemplateContainer), () => { if (vta == null) { return(null); } var tree = vta.CloneTree(); tree.SetProperty(BuilderConstants.LibraryItemLinkedTemplateContainerPathVEPropertyName, assetPath); tree.name = vta.name; return(tree); }, (inVta, inParent, ve) => { var vea = inVta.AddTemplateInstance(inParent, assetPath) as VisualElementAsset; vea.AddProperty("name", vta.name); ve.SetProperty(BuilderConstants.ElementLinkedInstancedVisualTreeAssetVEPropertyName, vta); return(vea); }, null, vta); newItem.SetIcon((Texture2D)EditorGUIUtility.IconContent("UxmlScript Icon").image); newItem.HasPreview = true; if (categoryStack.Count == 0) { projectCategory.AddChild(newItem); } else { categoryStack.Last().AddChild(newItem); } } }
public void ImportUxmlFromProject(BuilderLibraryTreeItem projectCategory, bool includePackages) { var assets = AssetDatabase.FindAllAssets(m_SearchFilter); var categoryStack = new List <BuilderLibraryTreeItem>(); foreach (var asset in assets) { var assetPath = AssetDatabase.GetAssetPath(asset.instanceID); var prettyPath = assetPath; prettyPath = Path.GetDirectoryName(prettyPath); prettyPath = prettyPath.ConvertSeparatorsToUnity(); if (prettyPath.StartsWith("Packages/") && !includePackages) { continue; } if (prettyPath.StartsWith(BuilderConstants.UIBuilderPackageRootPath)) { continue; } // Check to make sure the asset is actually writable. var packageInfo = PackageInfo.FindForAssetPath(assetPath); if (packageInfo != null && packageInfo.source != PackageSource.Embedded && packageInfo.source != PackageSource.Local) { continue; } // Anoter way to check the above. Leaving it here for references in case the above stops working. //AssetDatabase.GetAssetFolderInfo(assetPath, out bool isRoot, out bool isImmutable); //if (isImmutable) //continue; var split = prettyPath.Split('/'); AddCategoriesToStack(projectCategory, categoryStack, split); var vta = asset.pptrValue as VisualTreeAsset; var newItem = new BuilderLibraryTreeItem(asset.name + ".uxml", null, typeof(TemplateContainer), () => { if (vta == null) { return(null); } var tree = vta.CloneTree(); tree.SetProperty(BuilderConstants.LibraryItemLinkedTemplateContainerPathVEPropertyName, assetPath); tree.name = vta.name; return(tree); }, (inVta, inParent, ve) => { var vea = inVta.AddTemplateInstance(inParent, assetPath) as VisualElementAsset; vea.AddProperty("name", vta.name); ve.SetProperty(BuilderConstants.ElementLinkedInstancedVisualTreeAssetVEPropertyName, vta); return(vea); }, null, vta); newItem.SetIcon((Texture2D)EditorGUIUtility.IconContent("UxmlScript Icon").image); newItem.hasPreview = true; if (categoryStack.Count == 0) { projectCategory.AddChild(newItem); } else { categoryStack.Last().AddChild(newItem); } } }