Пример #1
0
    override public void OnAssetCreated()
    {
        base.OnAssetCreated();
        NPVoxMeshOutput output = NPipelineUtils.GetByType <NPVoxMeshOutput>(NPVoxUtils.GetTemplatePipeline())[0];

        MeshFactory              = (NPVoxMeshOutput)output.Clone();
        MeshFactory.StorageMode  = NPipeStorageMode.RESOURCE_CACHE;
        MeshFactory.Input        = null;
        MeshFactory.InstanceName = "_TEMPLATE_";
        NPipelineUtils.CreateAttachedPipe(UnityEditor.AssetDatabase.GetAssetPath(this), MeshFactory);
        UnityEditor.AssetDatabase.SaveAssets();
    }
Пример #2
0
    public static NPipeIImportable CloneRecursive(NPipeIImportable[] allImportables, NPipeIImportable sourcePipe, string targetPath)
    {
        NPipeIImportable clone = (NPipeIImportable)sourcePipe.Clone();

        NPipelineUtils.CreateAttachedPipe(targetPath, clone);

        if (clone is NPipeIComposite)
        {
            NPipeIImportable sourceOfSource = ((NPipeIComposite)clone).Input;
            if (ArrayUtility.IndexOf(allImportables, sourceOfSource) > -1)
            {
                ((NPipeIComposite)clone).Input = (NPipeIImportable)CloneRecursive(allImportables, sourceOfSource, targetPath);
            }
        }
        return(clone);
    }
Пример #3
0
    public NPVoxFrame(NPVoxAnimation animation)
    {
        this.animation = animation;

        output           = (NPVoxMeshOutput)animation.MeshFactory.Clone();
        output.hideFlags = HideFlags.HideInHierarchy;

//        Debug.Log("invalidating");
#if UNITY_EDITOR
        AssetDatabase.AddObjectToAsset(output, AssetDatabase.GetAssetPath(animation));
        preOutput = (NPVoxModelForwarder)NPVoxModelForwarder.CreateInstance <NPVoxModelForwarder>();
        NPipelineUtils.CreateAttachedPipe(AssetDatabase.GetAssetPath(animation), preOutput);
        preOutput.Input = null;
#endif
        output.Input = preOutput;
        output.Invalidate();
        preOutput.Invalidate();
    }
Пример #4
0
    public override void OnInspectorGUI()
    {
        NPVoxMeshInstance instance = (NPVoxMeshInstance)target;
        string            path     = AssetDatabase.GetAssetPath(instance);
        bool isTemplate            = path.Length > 0 && AssetDatabase.AssetPathToGUID(path) == NPVoxConstants.GAMEPOBJECT_TEMPLATE;

        if (isTemplate)
        {
            GUILayout.Label("This is the Prefab used to construct new instances of your models.\nAdjust as your liking, but don't move or rename it!");
            return;
        }

        DrawDefaultInspector();

        if (instance.MeshFactory == null)
        {
            GUILayout.Label("NPVox: No NP Vox Mesh Factory assigned.");

            return;
        }

        if ((instance.MeshFactory is NPVoxProcessorBase <Mesh>) && ((NPVoxProcessorBase <Mesh>)instance.MeshFactory).StorageMode == NPipeStorageMode.ATTACHED)
        {
            if (instance.SharedMash != instance.MeshFactory.GetProduct())
            {
                Undo.RecordObject(instance, "Updated shared mesh");
                instance.SharedMash = instance.MeshFactory.GetProduct();
            }
        }
        else
        {
            GUILayout.Label(
                "NPVox: The Storage Mode is not set to ATTACHED, thus you are not able to preview the item in the editor, sorry");
            GUILayout.Label(" to see any preview during Editor time.\n", new GUILayoutOption[] { });
            if (instance.SharedMash != null)
            {
                Undo.RecordObject(instance, "Unset shared mesh");
            }
            instance.SharedMash = null;
        }

        bool isPrefab = PrefabUtility.GetPrefabParent(target) == null && PrefabUtility.GetPrefabObject(target) != null;

        if (!isPrefab)
        {
            if (GUILayout.Button("Align (Shortcut ALT+a)"))
            {
                Align(instance.transform);
            }
        }

        NPVoxCubeSimplifier[] simplifiers = NPipelineUtils.FindNextPipeOfType <NPVoxCubeSimplifier>(NPipelineUtils.GetImportables(AssetDatabase.GetAssetPath(instance.MeshFactory as UnityEngine.Object)), instance.MeshFactory);

        if (simplifiers.Length > 0)
        {
            if (GUILayout.Button("Switch to Cube Simplifier instance"))
            {
                NPVoxCubeSimplifierInstance cubeSimplifier = instance.gameObject.AddComponent <NPVoxCubeSimplifierInstance>();
                cubeSimplifier.CubeSimplifier = simplifiers[0];
                cubeSimplifier.UpdateMesh();
                DestroyImmediate(instance, true);
                return;
            }
        }
        else
        {
            if (GUILayout.Button("Create Cube Simplifier"))
            {
                string assetPath = AssetDatabase.GetAssetPath(instance.MeshFactory as UnityEngine.Object);
                NPVoxCubeSimplifier simplifier = (NPVoxCubeSimplifier)NPipelineUtils.CreateAttachedPipe(assetPath, typeof(NPVoxCubeSimplifier), instance.MeshFactory);
                simplifier.TextureAtlas   = (NPVoxTextureAtlas)UnityEditor.AssetDatabase.LoadAssetAtPath(UnityEditor.AssetDatabase.GUIDToAssetPath("b3ed00785c29642baae5806625c1d3c1"), typeof(NPVoxTextureAtlas));
                simplifier.SourceMaterial = instance.GetComponent <MeshRenderer>().sharedMaterial;
                AssetDatabase.SaveAssets();
            }
        }

        if (GUILayout.Button("Select Pipe Container (Edit Import Settings)"))
        {
            Selection.objects = new Object[] { AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.meshFactory), typeof(NPipeContainer)) };
        }


        if (GUILayout.Button("Invalidate Pipe Container Deep "))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.meshFactory), typeof(NPipeContainer)));
        }
    }
Пример #5
0
    public void FixStuff()
    {
        #if UNITY_EDITOR
        if (!preOutput)
        {
            Debug.LogWarning("Added Preoutput");
            preOutput = (NPVoxModelForwarder)NPVoxModelForwarder.CreateInstance <NPVoxModelForwarder>();

            NPipelineUtils.CreateAttachedPipe(AssetDatabase.GetAssetPath(animation), preOutput);
//            AssetDatabase.AddObjectToAsset(preOutput, AssetDatabase.GetAssetPath(animation));
            preOutput.Invalidate();
            EditorUtility.SetDirty(animation);
        }

        if (output.Input == null || output.Input != preOutput as NPipeIImportable)
        {
            Debug.LogWarning("Fixed output");
            output.Input = preOutput;
            output.Invalidate();
            EditorUtility.SetDirty(animation);
        }

        int invalidateFrom = -1;
        for (int i = 0; i < this.transformers.Length; i++)
        {
            if (i == 0)
            {
                if (((NPipeIComposite)this.transformers[i]).Input != Source)
                {
                    ((NPipeIComposite)this.transformers[i]).Input = Source;
                    if (invalidateFrom == -1 || invalidateFrom > i)
                    {
                        invalidateFrom = i;
                    }
                    Debug.LogWarning("Fixed source of transformer 0");
                }
            }
            else
            {
                if (((NPipeIComposite)this.transformers[i]).Input != ((NPipeIComposite)this.transformers[i - 1]))
                {
                    ((NPipeIComposite)this.transformers[i]).Input = ((NPipeIComposite)this.transformers[i - 1]);
                    if (invalidateFrom == -1 || invalidateFrom > i)
                    {
                        invalidateFrom = i;
                    }
                    Debug.LogWarning("Fixed source of transformer " + i);
                }
            }
        }

        if (transformers.Length > 0)
        {
            if (preOutput.Input != ((NPipeIComposite)this.transformers[transformers.Length - 1]))
            {
                if (invalidateFrom == -1)
                {
                    invalidateFrom = transformers.Length;
                }
                preOutput.Input = ((NPipeIComposite)this.transformers[transformers.Length - 1]);
                Debug.LogWarning("Fixed source of preOutput");
            }
        }
        else if (preOutput.Input != Source)
        {
            preOutput.Input = Source;
            Debug.LogWarning("Fixed source of preOutput");
        }

        if (invalidateFrom > -1)
        {
            this.InvalidateFromStep(invalidateFrom);
        }
        #endif
    }
Пример #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);
    }
Пример #7
0
    private void drawPipeEditor(string assetPath)
    {
        NPipeIImportable importable = editingImportable as NPipeIImportable;

        if (importable == null)
        {
            return;
        }

        //====================================================================================================================
        // Selected Importable(s) Label
        //====================================================================================================================

        NPipeIImportable[] multiInstanceEditingImportables = null;

        if (isMultiInstance)
        {
            string warningMessage = "";
            multiInstanceEditingImportables = NPipelineUtils.GetSimiliarPipes(this.targets, this.target as NPipeContainer, this.editingImportable as NPipeIImportable, out warningMessage);

            GUILayout.Space(10f);
            GUILayout.Label(string.Format("Selected: {0} ( {1} instances )", editingImportable.GetTypeName(), multiInstanceEditingImportables.Length), EditorStyles.boldLabel);

            if (warningMessage.Length > 0)
            {
//                GUI.backgroundColor = Color.yellow;
                GUILayout.Label("WARNING: " + warningMessage);
            }
        }
        else
        {
            GUILayout.Space(10f);
            GUILayout.Label("Selected: " + editingImportable.GetTypeName(), EditorStyles.boldLabel);
        }

        //====================================================================================================================
        // Selected Importable(s) Editor Inspectors
        //====================================================================================================================

        NPipeIEditable editable = editingImportable as NPipeIEditable;

        if (editable != null)
        {
            GUILayout.Label("Edit:");
            if (isMultiInstance)
            {
                editable.DrawMultiInstanceEditor(~NPipeEditFlags.TOOLS, NPipelineUtils.GetUntypedFactories <NPipeIImportable>(multiInstanceEditingImportables));
            }
            else
            {
                editable.DrawInspector(~NPipeEditFlags.TOOLS);
            }
        }

        GUILayout.Space(10f);
        GUILayout.BeginVertical();
        GUILayout.Space(10f);

        //====================================================================================================================
        // append other pipes
        //====================================================================================================================

        if (!isMultiInstance)
        {
            GUILayout.BeginHorizontal();
            List <System.Type> allTypes = new List <System.Type>();
            List <NPipeAppendableAttribute> allAttrsa = new List <NPipeAppendableAttribute>();
            List <string> allLabels = new List <string>();
            foreach (Type factoryType in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute)))
            {
                NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0];
                if (!attr.sourceType.IsAssignableFrom(importable.GetType()))
                {
                    continue;
                }
                allTypes.Add(factoryType);
                allAttrsa.Add(attr);
                allLabels.Add(attr.name);
            }
            if (allTypes.Count > 0)
            {
                GUILayout.Label("Append: ");
                selectedAppendIndex = EditorGUILayout.Popup(selectedAppendIndex, allLabels.ToArray());
                if (selectedAppendIndex >= 0 && selectedAppendIndex < allTypes.Count)
                {
                    NPipeAppendableAttribute pipe          = allAttrsa[selectedAppendIndex];
                    NPipeIComposite          newImportable = null;

                    if (pipe.attached && GUILayout.Button("This Container"))
                    {
                        newImportable         = NPipelineUtils.CreateAttachedPipe(assetPath, allTypes[selectedAppendIndex], importable) as NPipeIComposite;
                        editingImportable     = newImportable;
                        lastEditingImportable = newImportable;
                        confirmDeletion       = false;
                    }
                    if (pipe.separate && GUILayout.Button("New Container"))
                    {
                        newImportable = NPipelineUtils.CreateSeparatedPipe(assetPath, allTypes[selectedAppendIndex], importable) as NPipeIComposite;
                    }

                    if (newImportable != null)
                    {
                        AssetDatabase.SaveAssets();
                        UnityEditor.Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(newImportable as UnityEngine.Object));
                    }
                }
                else
                {
                    selectedAppendIndex = 0;
                }
            }
            GUILayout.EndHorizontal();
        }


        GUILayout.EndVertical();
    }