// [MenuItem("NPVox/Select All Instances &s", true)] static bool Validate() { UnityEngine.Object[] objects = Selection.objects; for (int i = 0; i < objects.Length; i++) { NPipeContainer o = objects[i] as NPipeContainer; if (o) { NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(o)))); foreach (NPipeIImportable imp in outputPipes) { if (imp is NPVoxMeshOutput) { return(true); } } } NPVoxMeshInstance inst = objects[i] as NPVoxMeshInstance; if (inst) { return(true); } } return(false); }
private static bool ImportVoxModel(string asset) { string filename = Path.GetFileNameWithoutExtension(asset); string basename = Path.GetDirectoryName(asset); EnsureDirectoriesExist(basename); string pipelinePath = Path.Combine(Path.Combine(basename, "Pipeline/"), filename + ".asset"); NPipeContainer pipeContainer = NPipelineUtils.GetContainerForVoxPath(asset); if (!pipeContainer) { if (File.Exists(pipelinePath)) { // We don't need this anymore, as assets are reimported by the NPipeImporter anyway // AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default); // Debug.Log("Did not create Pipeline for asset '" + asset + "' due to pipeline not yet ready (no problem as will get imported by the NPipeContainer anyway)"); return(false); } Debug.Log("Creating Pipeline for Voxmodel: " + asset); NPipeContainer template; bool unavailable; NPVoxUtils.LoadTemplateMetadata(out template, out unavailable); if (template == null) { if (!unavailable) { // We don't need this anymore, as assets are reimported by the NPipeImporter anyway // AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default); // Debug.Log("Delay import of '" + asset + "' due to template not yet ready"); Debug.Log("did not import '" + asset + "' due to template not yet ready"); } return(false); } pipeContainer = NPipelineUtils.ClonePipeContainer(template, pipelinePath); } NPipeIImportable[] importables = NPipelineUtils.GetImportables(pipeContainer); // NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(importables); foreach (NPipeIImportable importable in importables) { if (importable is NPVoxMagickaSource) { ((NPVoxMagickaSource)importable).VoxModelUUID = AssetDatabase.AssetPathToGUID(asset); } importable.Invalidate(); EditorUtility.SetDirty(importable as UnityEngine.Object); } AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(pipelinePath, ImportAssetOptions.ForceSynchronousImport); // try ForceSynchronousImport return(true); }
public static T CreatePipeContainer <T>(string path) where T : NPipeContainer { T pipeContainer = (T)NPipeContainer.CreateInstance(typeof(T)); // Undo.RegisterCreatedObjectUndo(pipeContainer, "Created a pipe Container"); AssetDatabase.CreateAsset(pipeContainer, path); pipeContainer.OnAssetCreated(); AssetDatabase.SaveAssets(); return(pipeContainer); }
public static NPipeContainer GetContainerForVoxPath(string asset) { string filename = Path.GetFileNameWithoutExtension(asset); string basename = Path.GetDirectoryName(asset); string pipelinePath = Path.Combine(Path.Combine(basename, "Pipeline/"), filename + ".asset"); // Create or Load existing Pipeline NPipeContainer pipeContainer = (NPipeContainer)AssetDatabase.LoadAssetAtPath(pipelinePath, typeof(NPipeContainer)); return(pipeContainer); }
static void CreateNPVoxFont() { var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxFont>(); if (path.Length != 0) { NPVoxFont npVoxFont = (NPVoxFont)NPipeContainer.CreateInstance(typeof(NPVoxFont)); UnityEditor.AssetDatabase.CreateAsset(npVoxFont, path); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.Selection.objects = new Object[] { npVoxFont }; } }
public static NPipeContainer ClonePipeContainer(NPipeContainer container, string path) { NPipeContainer newContainer = NPipeContainer.CreateInstance <NPipeContainer>(); AssetDatabase.CreateAsset(newContainer, path); NPipeIImportable[] templateImportables = NPipelineUtils.GetImportables(container); foreach (NPipeIImportable pipe in NPipelineUtils.FindOutputPipes(templateImportables)) { CloneRecursive(templateImportables, pipe, path); } return(newContainer); }
static void MakeVoxPrefabs() { var path = EditorUtility.SaveFolderPanel( "Select target folder for the generated Prefabs ", "Prefabs", "Select Path for the generated Prefabs"); path = path.Remove(0, path.LastIndexOf("Assets")); if (path.Length != 0) { Object[] SelectedObjects = Selection.objects; int generatedCount = 0; foreach (Object o in SelectedObjects) { NPipeContainer container = o as NPipeContainer; if (!container) { continue; } NPVoxMeshOutput[] output = NPipelineUtils.GetByType <NPVoxMeshOutput>(container); foreach (NPVoxMeshOutput pipe in output) { NPVoxMeshInstance instance = pipe.Instatiate().GetComponent <NPVoxMeshInstance>(); string prefabPath = Path.Combine(path, instance.name) + ".prefab"; PrefabUtility.CreatePrefab(prefabPath, instance.gameObject); GameObject.DestroyImmediate(instance.gameObject); generatedCount++; } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); if (generatedCount > 0) { Debug.Log("Generated " + generatedCount + " Prefabs"); } else { Debug.LogWarning("No NPVoxMetadata selected"); } } }
public static void LoadTemplateMetadata(out NPipeContainer metadata, out bool unavailable) { if (templateImportable != null) { metadata = templateImportable; unavailable = false; return; } string metadataTemplatePath = AssetDatabase.GUIDToAssetPath(NPVoxConstants.PIPELINE_TEMPLATE); if (metadataTemplatePath == null) { UnityEngine.Debug.LogWarning( "NPVox: Could not find the Metadata Template with GUID '" + NPVoxConstants.PIPELINE_TEMPLATE + "' (" + metadataTemplatePath + "), if you removed the Asset, please create a new Asset and set it's GUID in Preferences -> NPVox" ); unavailable = true; metadata = templateImportable; return; } unavailable = false; metadata = templateImportable = (NPipeContainer)AssetDatabase.LoadAssetAtPath(metadataTemplatePath, typeof(NPipeContainer)); }
static void MenuNew() { UnityEngine.Object[] objects = Selection.objects; for (int i = 0; i < objects.Length; i++) { NPipeContainer o = objects[i] as NPipeContainer; if (o) { NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(o)))); foreach (NPipeIImportable imp in outputPipes) { if (imp is NPVoxMeshOutput) { ((NPVoxMeshOutput)imp).Instatiate(); } } } NPVoxMeshInstance inst = objects[i] as NPVoxMeshInstance; if (inst) { ((NPVoxMeshOutput)inst.meshFactory).Instatiate(); } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { List <NPipeImportFile> listOfImportableAssets = new List <NPipeImportFile>(); bool importedSomething = false; listOfImportableAssets.AddRange(RetryFiles.Values); RetryFiles.Clear(); // gather list foreach (var asset in importedAssets) { if (!File.Exists(asset)) { continue; } // string uuid = AssetDatabase.AssetPathToGUID(asset); string extension = Path.GetExtension(asset); if (extension == ".asset") { Object[] allAssets = AssetDatabase.LoadAllAssetsAtPath(asset); NPipeContainer container = NPipelineUtils.GetContainer(allAssets); if (container) { container.OnImport(); } NPipeIImportable[] importables = NPipelineUtils.GetImportables(allAssets); NPipeIImportable[] ordered = NPipelineUtils.FindOutputPipes(importables); // those should be sufficient as they will import all the pipes they depend on anyway if (ordered.Length > 0) { NPipeImportFile file = new NPipeImportFile(); file.importables = ordered; file.Path = asset; file.Container = container; listOfImportableAssets.Add(file); importedSomething = true; } } } if (!importedSomething) { return; } if (importedSomething) { int lengthBefore = listOfImportableAssets.Count; listOfImportableAssets.Sort(new NPipeImportFileComparer()); Assert.AreEqual(lengthBefore, listOfImportableAssets.Count); string plan = "--------======== NPipeline Import Plan ( " + listOfImportableAssets.Count + " files ) =======-------\n"; int count = 1; foreach (NPipeImportFile importFile in listOfImportableAssets) { plan += string.Format(" - {0}. {1} ({2} Importables) \n", count++, importFile.Path, importFile.importables.Length); } Debug.Log(plan); foreach (NPipeImportFile importFile in listOfImportableAssets) { foreach (NPipeIImportable importable in importFile.importables) { Assert.IsNotNull(importable); if (((UnityEngine.Object)importable)) { try { importable.Import(); importedSomething = true; } catch (NPipeException e) { Debug.LogWarning("Got Exception " + e.Message + " importing a pipe in " + importFile.Path + " (THIS IS ONLY A PROBLEM IF THERE IS NO SUCCESSFUL REPORT FOLLOWING) - ELSE RESTART UNITY"); NPipeImportFile file = RetryFiles.ContainsKey(importFile.Path) ? RetryFiles[importFile.Path] : new NPipeImportFile(); file.Path = importFile.Path; file.Container = importFile.Container; if (file.importables == null) { file.importables = new NPipeIImportable[0]; } ArrayUtility.Add(ref file.importables, importable); RetryFiles[file.Path] = file; } } } } AssetDatabase.SaveAssets(); // AssetDatabase.Refresh(); } }
public static T DrawSourcePropertySelector <T>(GUIContent label, Rect position, T oldValue, NPipeIImportable exclude = null) where T : class { UnityEngine.Object obj = oldValue as UnityEngine.Object; string path = AssetDatabase.GetAssetPath(obj); NPipeContainer container = AssetDatabase.LoadAssetAtPath(path, typeof(NPipeContainer)) as NPipeContainer; // EditorGUILayout.BeginHorizontal(); Rect containerPosition = new Rect(position.x, position.y, position.width / 4 * 3, position.height); Rect pipePosition = new Rect(position.x + position.width / 4 * 3, position.y, position.width / 4, position.height); container = (NPipeContainer)EditorGUI.ObjectField(containerPosition, label, container, typeof(NPipeContainer), false); path = AssetDatabase.GetAssetPath(container); T[] factories = GetTypedFactories <T>(container ? container.GetAllSelectableFactories() : new UnityEngine.Object[0] { }); if (factories.Length != 1) { string[] options = new string[factories.Length]; int i = 0; int selected = -1; for (int j = 0; j < factories.Length; j++) { NPipeIImportable fact = factories[j] as NPipeIImportable; if (fact == oldValue) { selected = i; } if (fact != exclude && !IsPrevious(fact, exclude, true)) { options[i] = i + " " + container.GetDisplayName(fact); factories[i] = factories[j]; i++; } } Array.Resize(ref options, i); Array.Resize(ref factories, i); if (selected == -1 && options.Length > 0) { selected = 0; } int newSelected = EditorGUI.Popup(pipePosition, selected, options); if (newSelected == -1) { return(null); } //return oldValue; return(factories[newSelected]); } else { if (factories[0] != exclude && !IsPrevious(factories[0] as NPipeIImportable, exclude, true)) { EditorGUI.LabelField(pipePosition, container.GetDisplayName(factories[0] as NPipeIImportable)); return(factories[0]); } return(null); } }
/// <summary> /// Gets the matching pipes in all input containers that follow the same path (used for multiinstance editing) /// </summary> /// <returns>The matching pipes.</returns> /// <param name="InputContainers">Input containers.</param> /// <param name="lookup">Lookup.</param> public static NPipeIImportable[] GetSimiliarPipes(UnityEngine.Object[] inputContainers, NPipeContainer referenceContainer, NPipeIImportable lookup, out string warningMessage) { // TODO: check for exact matchin structure, there may be cases where we have multiple pipes in a container warningMessage = ""; List <NPipeIImportable> result = new List <NPipeIImportable>(); bool bFoundMultiple = false; bool bNotFound = false; foreach (UnityEngine.Object container in inputContainers) { NPipeIImportable[] instances2 = GetByType <NPipeIImportable>(container); bool bFound = false; foreach (NPipeIImportable item in instances2) { if (item.GetType() == lookup.GetType()) { result.Add(item); if (bFound) { bFoundMultiple = true; } bFound = true; } } if (!bFound) { bNotFound = true; } } if (bFoundMultiple) { warningMessage += "Found Multiple Occurences in some containers. "; } if (bNotFound) { warningMessage += "Not foundt in some containers. "; } return(result.ToArray()); }
public static NPipeIImportable[] GetImportables(NPipeContainer container) { return(GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(container)))); }