public static void printLoDSettings(int index, SerializedObject serializedObject, string prefix = "settings.lodSettings", bool showTessellation = true)
    {
        int    winId = serializedObject.FindProperty("windowId").intValue;
        string tt    = "";

        serializedObject.Update();
        SerializedProperty lodProperties = serializedObject.FindProperty(prefix);

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.BeginVertical();
            {
                tt = PiXYZUtils.getTooltipText <PiXYZLODSettings>("preset");

                for (int i = 0; i < lodProperties.arraySize; i++)
                {
                    if (lodProperties.GetArrayElementAtIndex(i).FindPropertyRelative("preset").intValue > 4)
                    {
                        int j = lodProperties.arraySize - 1;
                        while (j >= i)
                        {
                            removeLod(j, serializedObject, "settings");
                            j--;
                        }
                        break;
                    }
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();
                        GUILayout.Label(new GUIContent("LOD " + i, tt));
                        EditorGUILayout.PropertyField(lodProperties.GetArrayElementAtIndex(i).FindPropertyRelative("preset"), GUIContent.none, GUILayout.ExpandWidth(true));
                        for (int j = i; j < lodProperties.arraySize - 1; j++)
                        {
                            while (lodProperties.GetArrayElementAtIndex(j).FindPropertyRelative("preset").intValue >= lodProperties.GetArrayElementAtIndex(j + 1).FindPropertyRelative("preset").intValue)
                            {
                                lodProperties.GetArrayElementAtIndex(j + 1).FindPropertyRelative("preset").intValue++;
                            }
                        }

                        if (GUILayout.Button(new GUIContent("-"), GUILayout.MaxHeight(13)))
                        {
                            if (lodProperties.arraySize == 1)
                            {
                                if (EditorPrefs.GetBool("PiXYZ.ShowPopupLods", true))
                                {
                                    if (EditorUtility.DisplayDialog("PiXYZImporter", "If you remove the last LOD, the functionality will be disabled.", "Continue", "Cancel"))
                                    {
                                        serializedObject.FindProperty("settings.useLods").boolValue = false;
                                        EditorPrefs.SetBool("PiXYZ.ShowPopupLods", false);
                                    }
                                }
                                else
                                {
                                    serializedObject.FindProperty("settings.useLods").boolValue = false;
                                }
                            }
                            else
                            {
                                removeLod(i, serializedObject, "settings");
                            }
                        }

                        GUILayout.FlexibleSpace();
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (lodProperties.GetArrayElementAtIndex(lodProperties.arraySize - 1).FindPropertyRelative("preset").intValue < 4)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button(new GUIContent("Add LOD level")))
                        {
                            addLod(lodProperties.arraySize, serializedObject, lodProperties.arraySize - 1, 1f - lodProperties.arraySize * 0.2f, "settings");
                        }
                        GUILayout.FlexibleSpace();
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 2
0
    void printSettingsGUI(SerializedObject serializedObject, string prefix = PiXYZSettings.serializePrefix, string fileExt = "", GameObject gameObject = null)
    {
        serializedObject.Update();

        int  winId       = serializedObject.FindProperty("windowId").intValue;
        bool isInspector = serializedObject.FindProperty("isInspector") != null?serializedObject.FindProperty("isInspector").boolValue : false;

        string  tt = "";
        Vector2 scrollViewPosition;

        int focusId = EditorWindow.focusedWindow != null?EditorWindow.focusedWindow.GetInstanceID() : lastFocusedId;

        if (winId != focusId)
        {
            winId = 0;
        }
        if (!g_scrollViewPosition.ContainsKey(winId))   //winId = 0 is shared
        {
            scrollViewPosition          = new Vector2(0, 0);
            g_scrollViewPosition[winId] = scrollViewPosition;
        }
        else
        {
            scrollViewPosition = g_scrollViewPosition[winId];
        }
        if (!UvAnim.ContainsKey(winId) && winId != 0)
        {
            UvAnim[winId] = new AnimBool(false);
            UvAnim[winId].valueChanged.AddListener(EditorWindow.focusedWindow.Repaint);
        }
        if (!lodAnim.ContainsKey(winId) && winId != 0)
        {
            lodAnim[winId] = new AnimBool(false);
            lodAnim[winId].valueChanged.AddListener(EditorWindow.focusedWindow.Repaint);
        }
        if (!advancedToggle.ContainsKey(winId))
        {
            advancedToggle[winId] = false;
        }

        SerializedProperty serializedProperty = serializedObject.FindProperty(prefix);

        int lastShown = 0;

        scrollViewPosition = GUILayout.BeginScrollView(scrollViewPosition, GUILayout.MaxHeight(Screen.height - 30));
        {
            g_scrollViewPosition[winId] = scrollViewPosition;
            EditorGUI.indentLevel       = 0;
            EditorGUILayout.BeginVertical();
            {
                GUILayout.Space(10);
                tt = "Use the following settings to adapt the imported model’s units/transforms to Unity3D’s units/coordinate system (meters/left-handed).\n\nDefault settings change a millimeters / Z-up axis scene to Unity configuration.";
                beginGroupBox("Coordinate System", isInspector, tt);
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();
                    {
                        tt = PiXYZUtils.getTooltipText <PiXYZSettings>("scaleFactor");
                        EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("scaleFactor"), new GUIContent("Scale", tt));
                        GUILayout.Space(10);
                    }
                    EditorGUILayout.EndHorizontal();
                    tt = PiXYZUtils.getTooltipText <PiXYZSettings>("isRightHanded");
                    EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("isRightHanded"), new GUIContent("Right Handed", tt));
                    tt = PiXYZUtils.getTooltipText <PiXYZSettings>("isZUp");
                    EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("isZUp"), new GUIContent("Z-up", tt));
                    EditorGUILayout.Space();
                }
                endGroupBox();

                if (!isPiXYZExt(fileExt))
                {
                    GUILayout.Space(10);
                    tt = "Choose one of the following mode to optimize the imported model’s hierarchy (or tree)\n\n\nNone: No modification of the hierarchy (default mode)\n\nClean-up intermediary nodes: Compresses the hierarchy by removing empty nodes, or any node containing only one sub-node.\n\nTransfer all objects under root: Simplifies the hierarchy by transferring all imported 3D objects (or GameObject) under the root node.";
                    beginGroupBox("Hierarchy Optimization", isInspector, tooltip: tt);
                    {
                        tt = PiXYZUtils.getTooltipText <PiXYZSettings>("treeProcess");
                        EditorGUILayout.Space();
                        EditorGUILayout.BeginHorizontal();
                        {
                            GUILayout.Space(20);
                            float width = GUI.skin.label.CalcSize(new GUIContent("Quality")).x;
                            GUILayout.Label("Mode", GUILayout.Width(width));
                            List <string> propertyNames = new List <string>(3);
                            propertyNames.Add("None");
                            propertyNames.Add("Clean-up intermediary nodes");
                            propertyNames.Add("Transfer all objects under root");
                            propertyNames.Add("Merge all objects");
                            propertyNames.Add("Merge objects by material");
                            List <int> intValue = new List <int>(3);
                            intValue.Add(0);
                            intValue.Add(1);
                            intValue.Add(2);
                            intValue.Add(3);
                            intValue.Add(4);
                            width = (float)Math.Truncate(Screen.width * 0.6);
                            Rect rect = EditorGUILayout.GetControlRect();
                            rect.width = width;
                            GUILayout.FlexibleSpace();
                            serializedProperty.FindPropertyRelative("treeProcess").intValue = EditorGUI.IntPopup(rect, serializedProperty.FindPropertyRelative("treeProcess").intValue, propertyNames.ToArray(), intValue.ToArray());
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                    }
                    endGroupBox();
                    GUILayout.Space(10);
                    if (!serializedObject.FindProperty("settings.useLods").boolValue)
                    {
                        tt = "Choose the quality level (preset) for the imported model.\nQuality defines the density of the mesh that PiXYZ creates.\nDepending if you import a CAD model (exact geometry) or a mesh model (tessellated geometry), PiXYZ will either perform a Tessellation or a Decimation on the model (see documentation for more information and presets details).";
                        beginGroupBox("Mesh Quality", isInspector, tooltip: tt);
                        {
                            EditorGUILayout.Space();
                            EditorGUILayout.BeginHorizontal();
                            {
                                GUILayout.Space(20);
                                tt = PiXYZUtils.getTooltipText <PiXYZLODSettings>("preset");
                                GUILayout.Label(new GUIContent("Quality", tt));
                                int width = (int)(Math.Truncate(Screen.width * 0.5));
                                EditorGUILayout.PropertyField(serializedObject.FindProperty("settings.lodSettings").GetArrayElementAtIndex(0).FindPropertyRelative("preset"), GUIContent.none, GUILayout.Width(width));
                                EditorGUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(5);
                                    GUILayout.Label("Use LODs");
                                    EditorGUILayout.PropertyField(serializedObject.FindProperty("settings.useLods"), GUIContent.none, GUILayout.Width(40));
                                }
                                EditorGUILayout.EndHorizontal();
                                GUILayout.FlexibleSpace();
                            }
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.Space();
                        }
                        endGroupBox();
                    }
                    else
                    {
                        pixyzLods.printLoDSlider(serializedObject, prefix, winId, serializedProperty.FindPropertyRelative("treeProcess").intValue < 3, gameObject);
                    }
                    GUILayout.Space(10);
                    beginGroupBox("Post Process", isInspector, tooltip: "Generate UV : Use this setting to add a new primary UV set (channel #0). Set the size of the projection box used to create UVs.\n\nCaution: PiXYZ will override the existing UV set, do not Use this setting if you wish to preserve the UVs embedded in the imported model.\n\nOrient… : Use this setting for PiXYZ to perform a unification of all triangles orientation.\n\nCaution: Do not Use this setting if the imported model is a mesh (tessellated geometry) and is already correctly oriented.");
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            tt = PiXYZUtils.getTooltipText <PiXYZSettings>("mapUV");
                            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("mapUV"), GUIContent.none, true, GUILayout.Width(40));
                            GUILayout.Label(new GUIContent("Generate UV (size)", tt));
                            //GUILayout.FlexibleSpace();
                            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("mapUV3dSize"), GUIContent.none, true, GUILayout.Width(100));
                            GUILayout.Label(new GUIContent("millimeters", tt));
                            serializedProperty.FindPropertyRelative("mapUV3dSize").floatValue = Mathf.Clamp(serializedProperty.FindPropertyRelative("mapUV3dSize").floatValue, 1.0f, 1000f);
                            GUILayout.Space(10);
                        }
                        EditorGUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        {
                            tt = PiXYZUtils.getTooltipText <PiXYZSettings>("orient");
                            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("orient"), GUIContent.none, true, GUILayout.Width(40));
                            GUILayout.Label(new GUIContent("Orient normals of adjacent faces consistently", tt), GUILayout.ExpandWidth(true));
                            GUILayout.FlexibleSpace();
                        }
                        GUILayout.EndHorizontal();
                    }
                    endGroupBox();

                    GUILayout.Space(10);
                    bool before = advancedToggle[winId];
                    advancedToggle[winId] = EditorGUILayout.Foldout(advancedToggle[winId], "Advanced", true);
                    if (advancedToggle[winId])
                    {
                        if (!before)
                        {
                            g_scrollViewPosition[winId] = new Vector2(0, Screen.height);
                        }
                        GUILayout.Space(10);
                        EditorGUI.indentLevel++;
                        string version = InternalEditorUtility.GetFullUnityVersion();
                        version = version.Substring(0, version.LastIndexOf('.'));
                        if (float.Parse(version) >= 2017.3)    //Cannot change before 2017.3
                        {
                            EditorGUI.BeginDisabledGroup(isInspector);
                            {
                                EditorGUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(10);
                                    tt = PiXYZUtils.getTooltipText <PiXYZSettings>("useMergeFinalAssemblies");
                                    serializedProperty.FindPropertyRelative("useMergeFinalAssemblies").boolValue = EditorGUILayout.Toggle(serializedProperty.FindPropertyRelative("useMergeFinalAssemblies").boolValue, GUILayout.Width(40));
                                    GUILayout.Label(new GUIContent("Stitch unconnected surfaces", tt));
                                    GUILayout.FlexibleSpace();
                                }
                                EditorGUILayout.EndHorizontal();
                                EditorGUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(10);
                                    tt = PiXYZUtils.getTooltipText <PiXYZSettings>("splitTo16BytesIndex");
                                    serializedProperty.FindPropertyRelative("splitTo16BytesIndex").boolValue = EditorGUILayout.Toggle(serializedProperty.FindPropertyRelative("splitTo16BytesIndex").boolValue, GUILayout.Width(40));
                                    GUILayout.Label(new GUIContent("Split to limit vertex count per mesh", tt));
                                    GUILayout.FlexibleSpace();
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        EditorGUILayout.Space();
                    }
                    EditorGUILayout.EndFadeGroup();
                    Rect boxRect = GUILayoutUtility.GetLastRect();
                    lastShown = (int)(boxRect.y + boxRect.height);
                }
            }
            EditorGUILayout.EndVertical();
        }
        GUILayout.EndScrollView();
        Rect scrollRect     = GUILayoutUtility.GetLastRect();
        int  gradientHeight = 15;

        //up
        if (scrollViewPosition.y > 0f)
        {
            PiXYZUtils.gradientBox(new Rect(scrollRect.x, scrollRect.y, scrollRect.width, gradientHeight), new Vector2(0.5f, 1f));
        }
        //down
        if (scrollViewPosition.y < (lastShown - scrollRect.height))
        {
            PiXYZUtils.gradientBox(new Rect(scrollRect.x, scrollRect.y + scrollRect.height - gradientHeight, scrollRect.width, gradientHeight), new Vector2(0.5f, 0f));
        }
    }