Пример #1
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);
    }
Пример #2
0
    private void DrawTransformationSelector()
    {
        NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>[] transformers = viewModel.Transformers;
        if (transformers == null)
        {
            return;
        }
        GUIStyle foldoutStyle         = new GUIStyle(EditorStyles.foldout);
        GUIStyle foldoutSelectedStyle = new GUIStyle(foldoutStyle);
        GUIStyle labelStyle           = new GUIStyle(EditorStyles.label);
        GUIStyle labelSelectedStyle   = new GUIStyle(labelStyle);
        GUIStyle deleteStyle          = new GUIStyle(EditorStyles.miniButtonMid);

        deleteStyle.fixedWidth = 70;

        foldoutSelectedStyle.fontStyle = FontStyle.Bold;
        labelSelectedStyle.fontStyle   = FontStyle.Bold;

        for (int i = 0; i < transformers.Length; i++)
        {
            NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer = transformers[i];

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

            bool isSelected        = i == viewModel.SelectedTransformationIndex;
            bool somethingSelected = viewModel.SelectedTransformationIndex != -1;
            bool isSelectedOrLast  = isSelected || (!somethingSelected && i == transformers.Length - 1);

            string name = transformer.GetInstanceName();
            if (name == null || name.Length < 1)
            {
                name = transformer.GetTypeName();
            }

            GUILayout.Label((i + 1) + (isSelectedOrLast ? "|A" : ""), isSelected ? labelSelectedStyle : labelStyle, GUILayout.Width(30));

            if (isSelected != EditorGUILayout.Foldout(isSelected, name, isSelected ? foldoutSelectedStyle : foldoutStyle))
            {
                if (isSelected)
                {
                    viewModel.SelectTransformation(-1);
                    unfocus();
                }
                else
                {
                    viewModel.SelectTransformation(i);
                }
            }

            GUILayout.Space(100);

            if (GUILayout.Button("Delete" + (isSelectedOrLast ? " (" + HOTKEY_DELETE_LAST_TRANSFOMRATION.ToString() + ")" : ""), deleteStyle))
            {
                viewModel.RemoveTransformationAt(i);
            }
            else if (GUILayout.Button("Copy", EditorStyles.miniButtonMid))
            {
                viewModel.CopyTransformation(i);
            }

            if (isSelected)
            {
                if (NPVoxGUILayout.HotkeyButton(new GUIContent("Up", "Move Up"), HOTKEY_MOVE_TRANSFORMATION_UP, false, false, false, EditorStyles.miniButtonMid))
                {
                    viewModel.MoveTransformation(i, -1);
                }

                if (NPVoxGUILayout.HotkeyButton(new GUIContent("Down", "Move Down"), HOTKEY_MOVE_TRANSFORMATION_DOWN, false, false, false, EditorStyles.miniButtonMid))
                {
                    viewModel.MoveTransformation(i, +1);
                }

                if (NPVoxGUILayout.HotkeyButton(new GUIContent("Duplicate", "Duplicate"), DUPLICATE_TRANSFORMATION, false, false, false, EditorStyles.miniButtonMid))
                {
                    viewModel.DuplicateTransformation(i);
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent("Up", "Move Up"), EditorStyles.miniButtonMid))
                {
                    viewModel.MoveTransformation(i, -1);
                }

                if (GUILayout.Button(new GUIContent("Down", "Move Down"), EditorStyles.miniButtonRight))
                {
                    viewModel.MoveTransformation(i, +1);
                }
            }

            GUILayout.EndHorizontal();

            if (isSelected && viewModel.SelectedTransformer != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.Space();
                    GUILayout.BeginVertical();
                    {
                        EditorGUILayout.Space();

                        if (viewModel.SelectedTransformer is NPVoxISceneEditable)
                        {
                            DrawTransformationToolbar();
                        }
                        {
                            if (viewModel.SelectedTransformer.DrawInspector(~NPipeEditFlags.TOOLS & ~NPipeEditFlags.INPUT & ~NPipeEditFlags.STORAGE_MODE))
                            {
                                GUI.changed = true;
                                viewModel.SelectedTransformerChanged();
                                viewModel.RegeneratePreview();
//                                GUI.changed = true; // TODO: is this still needed?
                            }
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.Space();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }

        GUILayout.BeginHorizontal();
        if (NPVoxGUILayout.HotkeyButton("+ New T", HOTKEY_APPEND_TRANSFORMATION))
        {
            viewModel.AddTransformation();
        }
        if (viewModel.IsSkeletonBuilderAppendable() && GUILayout.Button("+ Skeleton"))
        {
            viewModel.AddSkeletonBuilder();
        }
        if (viewModel.IsSkeletonTransformerAppendable() && NPVoxGUILayout.HotkeyButton("+ SkeletonT", HOTKEY_APPEND_BONETRANSFORMATION))
        {
            viewModel.AddSkeletonTransformer();
        }
        if (GUILayout.Button("+ Mirror"))
        {
            viewModel.AddMirrorTransformators();
        }
//        if (GUILayout.Button("+ Combiner"))
//        {
//            viewModel.AddSocketCombiner();
//        }
//        if (GUILayout.Button("+ SocketT"))
//        {
//            viewModel.AddSocketTransformer();
//        }
        List <System.Type> allTypes  = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute)));
        List <string>      allLabels = new List <string>();

        allLabels.Add("Other ...");
        foreach (System.Type factoryType in allTypes)
        {
            NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0];

            if (!attr.sourceType.IsAssignableFrom(typeof(NPVoxIModelFactory)))
            {
                continue;
            }
            allLabels.Add(attr.name);
        }
        int selection = EditorGUILayout.Popup(0, allLabels.ToArray());

        if (selection > 0)
        {
            viewModel.AddTransformer(allTypes[selection - 1]);
        }


        if (viewModel.HasTransformationToPaste() && GUILayout.Button("+ Paste"))
        {
            viewModel.Paste();
        }
        GUILayout.EndHorizontal();
    }
Пример #3
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();
    }