// [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);
 }
 static void MenuInvalidateAndImportSelectedDeep()
 {
     foreach (UnityEngine.Object target in Selection.objects)
     {
         NPipeIImportable[] allImportables = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetByType <NPipeIImportable>(target));
         NPipelineUtils.InvalidateAll(allImportables, true);
         EditorUtility.SetDirty(target as UnityEngine.Object);
     }
     AssetDatabase.SaveAssets();
 }
    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 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();
        }
    }
Beispiel #6
0
    protected bool DrawPipelineElements()
    {
        //==================================================================================================================================
        // setup colors
        //==================================================================================================================================
        normalStyle = new GUIStyle((GUIStyle)"helpbox");
        normalStyle.normal.textColor = Color.black;
        normalStyle.fontStyle        = FontStyle.Normal;
        boldStyle = new GUIStyle((GUIStyle)"helpbox");
        boldStyle.normal.textColor = Color.black;
        boldStyle.fontStyle        = FontStyle.Bold;
        thisContainerColor         = new Color(0.8f, 1.0f, 0.6f);
        thisContainerMultiColor    = new Color(0.8f, 0.6f, 1.0f);

        string assetPath = AssetDatabase.GetAssetPath(target);

        NPipeIImportable[] allImportables = NPipelineUtils.GetByType <NPipeIImportable>(target);
        NPipeIImportable[] outputPipes    = NPipelineUtils.FindOutputPipes(allImportables);

        //==================================================================================================================================
        // Tool Buttons (Select Me, Invalidation)
        //==================================================================================================================================

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Select Me"))
        {
            Selection.objects = this.targets;
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Invalidate & Reimport All"))
        {
            NPipelineUtils.InvalidateAndReimportAll(targets);
        }
        if (GUILayout.Button("Invalidate & Reimport All Deep"))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(targets);
        }
        GUILayout.EndHorizontal();
        GUILayout.EndHorizontal();

        //==================================================================================================================================
        // Single Instance Mode Only for Lazyness Tool Buttons (Deleta all Payload, Instantiate)
        //==================================================================================================================================

        if (!this.isMultiInstance)
        {
            if (GUILayout.Button("Delete all Payload"))
            {
                UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                foreach (UnityEngine.Object obj in allObjects)
                {
                    if (!(obj is NPipeIImportable) && !(obj is NPipeContainer))
                    {
                        DestroyImmediate(obj, true);
                    }
                }
                EditorUtility.SetDirty(target);
            }

            foreach (NPipeIImportable imp in allImportables)
            {
                if (imp is NPipeIInstantiable && GUILayout.Button("Instantiate " + imp.GetInstanceName() + " (" + imp.GetTypeName() + ")"))
                {
                    ((NPipeIInstantiable)imp).Instatiate();
                }
            }
        }

        //==================================================================================================================================
        // Draw Pipelines
        //==================================================================================================================================
        {
            GUILayout.Space(10f);

            // headline
            GUILayout.Label(string.Format("Pipelines", allImportables.Length), EditorStyles.boldLabel);

            // pipelines
            GUILayout.BeginHorizontal();
            HashSet <NPipeIImportable> visited = new HashSet <NPipeIImportable>();
            foreach (NPipeIImportable iimp in outputPipes)
            {
                DrawPipelineElements(assetPath, iimp, visited, false);
            }

            GUI.backgroundColor = isMultiInstance ? thisContainerMultiColor : thisContainerColor;

            if (!isMultiInstance)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Add: ");
                {
                    GUILayout.BeginVertical();
                    foreach (Type factoryType in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeStartingAttribute)))
                    {
                        NPipeStartingAttribute attr = (NPipeStartingAttribute)factoryType.GetCustomAttributes(typeof(NPipeStartingAttribute), true)[0];
                        if (attr.attached && GUILayout.Button(attr.name))
                        {
                            NPipelineUtils.CreateAttachedPipe(assetPath, factoryType);
                        }
                    }

                    List <System.Type> allTypes  = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute)));
                    List <string>      allLabels = new List <string>();
                    allLabels.Add("Other ...");
                    foreach (Type factoryType in allTypes)
                    {
                        NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0];
                        allLabels.Add(attr.name);
                    }
                    int selection = EditorGUILayout.Popup(0, allLabels.ToArray());
                    if (selection > 0)
                    {
                        NPipelineUtils.CreateAttachedPipe(assetPath, allTypes[selection - 1]);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndHorizontal();
        }

        drawPipeEditor(assetPath);

        return(false);
    }