Пример #1
0
    public virtual void SetContext(NPVoxNormalProcessorPreviewContext _context)
    {
        if (m_context != null)
        {
            m_context.Invalidate();
        }

        m_context = _context;
        NPVoxNormalProcessor processor = m_context.ViewedProcessor;
        NPVoxAttributeNormalProcessorListItem listItemAttribute = NPipeReflectionUtil.GetAttribute <NPVoxAttributeNormalProcessorListItem>(processor);

        m_title = listItemAttribute.EditorName;

        InitScene();
    }
Пример #2
0
    public static NPVoxNormalProcessorPreview ShowWindow(Type _processorType)
    {
        if (s_materialHandles == null)
        {
            s_materialHandles = ( Material )EditorGUIUtility.LoadRequired("Assets/Vendor/UnityVoxelTools/NPVox/Materials/GL.mat");
        }

        foreach (Type type in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPVoxAttributeNormalProcessorPreview)))
        {
            if (type.BaseType == typeof(NPVoxNormalProcessorPreview))
            {
                NPVoxAttributeNormalProcessorPreview attr = NPipeReflectionUtil.GetAttribute <NPVoxAttributeNormalProcessorPreview>(type);
                if (attr != null && attr.ProcessorType == _processorType)
                {
                    return(( NPVoxNormalProcessorPreview )GetWindow(type, false, "Normal Editor", true));
                }
            }
        }

        return(GetWindow <NPVoxNormalProcessorPreview>("Normal Editor", true));
    }
Пример #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        NPVoxMeshOutput          target        = property.serializedObject.targetObject as NPVoxMeshOutput;
        NPVoxNormalProcessorList processorList = target.NormalProcessors;

        EditorGUI.BeginProperty(position, label, property);
        // Customize gui style
        Color previousBGColor = GUI.backgroundColor;
        Color previousFGColor = GUI.contentColor;

        GUI.backgroundColor = s_colorBackgroundGUIPrimary;
        GUI.backgroundColor = s_colorBackgroundGUIPrimary;
        // GUI.contentColor = s_colorForegroundGUI; // Doesn't seem to work

        // Header + Expand / Collapse Button
        GUILayout.BeginHorizontal();
        GUILayout.Label("Normal Processors (" + processorList.GetProcessors().Count + ")", GUILayout.Width(s_widthHeaderLabel));

        if (!m_expanded)
        {
            if (GUILayout.Button("Expand", GUILayout.Width(s_widthExpandButton)))
            {
                m_expanded = true;
            }
        }
        else
        {
            if (GUILayout.Button("Collapse", GUILayout.Width(s_widthExpandButton)))
            {
                m_expanded = false;
            }
        }

        GUILayout.EndHorizontal();

        if (!m_expanded)
        {
            GUILayout.Space(12.0f);
        }

        // List management
        if (m_expanded)
        {
            Dictionary <string, System.Type> processorClasses = new Dictionary <string, System.Type>();
            processorClasses.Add("<None>", null);
            List <System.Type> allTypes = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPVoxAttributeNormalProcessorListItem)));
            allTypes = allTypes.OrderBy(x => (( NPVoxAttributeNormalProcessorListItem )x.GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0]).ListPriority).ToList();
            foreach (System.Type factoryType in allTypes)
            {
                NPVoxAttributeNormalProcessorListItem attr = ( NPVoxAttributeNormalProcessorListItem )factoryType.GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0];

                if (attr.ClassType.BaseType != typeof(NPVoxNormalProcessor))
                {
                    continue;
                }

                processorClasses.Add(attr.EditorName, factoryType);
            }

            string[] processorKeys = processorClasses.Keys.ToArray();

            GUILayout.BeginHorizontal();
            GUILayout.Space(s_widthTab);
            m_indexPopupAddProcessor = EditorGUILayout.Popup(m_indexPopupAddProcessor, processorKeys);
            bool optionAdded = GUILayout.Button("Add");
            GUILayout.EndHorizontal();

            if (optionAdded)
            {
                System.Type processorClass = processorClasses[processorKeys[m_indexPopupAddProcessor]];
                if (processorClass != null)
                {
                    if (UnityEditor.AssetDatabase.GetAssetPath(processorList).Length == 0)
                    {
                        target.IncludeSubAssets(UnityEditor.AssetDatabase.GetAssetPath(target));
                    }
                    processorList.AddProcessor(processorClass)
                    .AddToAsset(UnityEditor.AssetDatabase.GetAssetPath(target));
                }
            }

            NPVoxNormalProcessor itemToMoveBack    = null;
            NPVoxNormalProcessor itemToMoveForward = null;

            foreach (NPVoxNormalProcessor processor in processorList.GetProcessors())
            {
                NPVoxAttributeNormalProcessorListItem attr = ( NPVoxAttributeNormalProcessorListItem )processor.GetType().GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0];

                GUILayout.Space(s_verticalSpacePerItem);

                GUILayout.BeginHorizontal();
                GUILayout.Space(s_widthTab);
                GUILayout.Label(attr.EditorName, GUILayout.MinWidth(s_widthMinItemName));

                GUILayout.Space(20.0f);

                GUI.backgroundColor = s_colorBackgroundGUISecondary;

                if (GUILayout.Button("View / Edit"))
                {
                    NPVoxNormalProcessorPreview preview = NPVoxNormalProcessorPreview.ShowWindow(processor.GetType());
                    preview.SetContext(processor.GeneratePreviewContext(target));
                }

                GUILayout.Space(20.0f);

                if (GUILayout.Button("^", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    itemToMoveBack = processor;
                }

                if (GUILayout.Button("v", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    itemToMoveForward = processor;
                }

                if (GUILayout.Button("X", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    processorList.DestroyProcessor(processor);
                    break;
                }

                GUI.backgroundColor = s_colorBackgroundGUIPrimary;

                GUILayout.EndHorizontal();

                processor.OnGUI();
                GUILayout.Space(10.0f);
            }

            if (itemToMoveBack)
            {
                processorList.MoveProcessorBack(itemToMoveBack);
                itemToMoveBack = null;
            }

            if (itemToMoveForward)
            {
                processorList.MoveProcessorForward(itemToMoveForward);
                itemToMoveForward = null;
            }

            GUILayout.Space(s_verticalSpaceEnd);
        }

        // Restore previous gui style
        GUI.backgroundColor = previousBGColor;
        GUI.contentColor    = previousFGColor;

        EditorGUI.EndProperty();
    }
Пример #4
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();
    }
Пример #5
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);
    }
Пример #6
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();
    }