/// <summary>
 /// Inspector GUI shown in the Editor window.
 /// </summary>
 /// <param name="brushSettings"></param>
 internal virtual void DrawGUI(BrushSettings brushSettings)
 {
     if (PolyGUILayout.HeaderWithDocsLink(PolyGUI.TempContent(ModeSettingsHeader, "")))
     {
         Application.OpenURL(DocsLink);
     }
 }
Пример #2
0
        // Inspector GUI shown in the Editor window.  Base class shows BrushSettings by default
        internal override void DrawGUI(BrushSettings brushSettings)
        {
            base.DrawGUI(brushSettings);

            /// Verify dependencies
            VerifyLoadedAssetsIntegrity();

            EditorGUI.BeginChangeCheck();

            /// Interface
            s_UsePivotForPlacement.value = PolyGUILayout.Toggle(m_GCUsePrefabPivot, s_UsePivotForPlacement);

            s_ParentObjectWithSurface.value     = PolyGUILayout.Toggle(m_GCHitSurfaceIsParent, s_ParentObjectWithSurface);
            s_AvoidOverlappingGameObjects.value = PolyGUILayout.Toggle(m_GcAvoidOverlappingGameObjects, s_AvoidOverlappingGameObjects);

            EditorGUI.BeginChangeCheck();
            m_CurrentPaletteIndex = EditorGUILayout.Popup(m_CurrentPaletteIndex, m_AvailablePalettesAsStrings);
            if (EditorGUI.EndChangeCheck())
            {
                if (m_CurrentPaletteIndex >= m_AvailablePalettes.Length)
                {
                    SetPrefabPalette(PrefabPaletteEditor.AddNew());
                }
                else
                {
                    SetPrefabPalette(m_AvailablePalettes[m_CurrentPaletteIndex]);
                }
            }

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Preview Size");
                s_PreviewThumbSize.value = (int)EditorGUILayout.Slider((float)s_PreviewThumbSize, 60f, 128f);
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (m_CurrentPaletteIndex >= m_AvailablePalettes.Length)
                {
                    SetPrefabPalette(PrefabPaletteEditor.AddNew());
                }
                else
                {
                    SetPrefabPalette(m_AvailablePalettes[m_CurrentPaletteIndex]);
                }

                PolybrushSettings.Save();
            }

            using (new GUILayout.VerticalScope())
            {
                if (prefabLoadoutEditor != null)
                {
                    prefabLoadoutEditor.OnInspectorGUI_Internal(s_PreviewThumbSize);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Editor for blend.  Returns true if blend has been modified.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="blend"></param>
        /// <param name="attribs"></param>
        /// <returns></returns>
        internal static int OnInspectorGUI(int index, ref SplatWeight blend, AttributeLayout[] attribs)
        {
            // if(blend == null && attribs != null)
            //  blend = new SplatWeight( SplatWeight.GetChannelMap(attribs) );

            // bool mismatchedOrNullAttributes = blend == null || !blend.MatchesAttributes(attribs);

            Rect r    = GUILayoutUtility.GetLastRect();
            int  yPos = (int)Mathf.Ceil(r.y + r.height);

            index = PolyGUILayout.ChannelField(index, attribs, thumbSize, yPos);

            return(index);
        }
        /// <summary>
        /// Inspector GUI shown in the Editor window.  Base class shows BrushSettings by default
        /// </summary>
        /// <param name="brushSettings">Current brush settings</param>
        internal override void DrawGUI(BrushSettings brushSettings)
        {
            base.DrawGUI(brushSettings);

            using (new GUILayout.HorizontalScope())
            {
                if (colorPalette == null)
                {
                    RefreshAvailablePalettes();
                }

                EditorGUI.BeginChangeCheck();
                m_CurrentPaletteIndex = EditorGUILayout.Popup(m_CurrentPaletteIndex, m_AvailablePalettesAsString);
                if (EditorGUI.EndChangeCheck())
                {
                    if (m_CurrentPaletteIndex >= m_AvailablePalettes.Length)
                    {
                        SetColorPalette(ColorPaletteEditor.AddNew());
                    }
                    else
                    {
                        SetColorPalette(m_AvailablePalettes[m_CurrentPaletteIndex]);
                    }
                }

                paintMode = (PaintMode)GUILayout.Toolbar((int)paintMode, modeIcons);
            }

            bool likelySupportsVertexColors = m_EditableObjectsData.Count == 0;

            foreach (var kvp in m_EditableObjectsData)
            {
                likelySupportsVertexColors |= kvp.Value.LikelySupportsVertexColors;
            }

            if (!likelySupportsVertexColors)
            {
                EditorGUILayout.HelpBox("It doesn't look like any of the materials on this object support vertex colors!", MessageType.Warning);
            }

            colorPaletteEditor.onSelectIndex = (color) => { SetBrushColor(color, brushSettings.strength); };
            colorPaletteEditor.onSaveAs      = SetColorPalette;

            mask = PolyGUILayout.ColorMaskField("Color Mask", mask);

            colorPaletteEditor.OnInspectorGUI();
        }
Пример #5
0
        internal override void DrawGUI(BrushSettings settings)
        {
            base.DrawGUI(settings);

            EditorGUI.BeginChangeCheck();

            s_IgnoreOpenEdges.value = PolyGUILayout.Toggle(BrushModeSculpt.Styles.gcIgnoreOpenEdges, s_IgnoreOpenEdges);
            if (s_SmoothDirection == PolyDirection.BrushNormal)
            {
                s_UseFirstNormalVector.value = PolyGUILayout.Toggle(BrushModeSculpt.Styles.gcBrushNormalIsSticky, s_UseFirstNormalVector);
            }
            s_SmoothDirection.value = (PolyDirection)PolyGUILayout.PopupFieldWithTitle(BrushModeSculpt.Styles.gcDirection,
                                                                                       (int)s_SmoothDirection.value, BrushModeSculpt.Styles.s_BrushDirectionList);

            if (EditorGUI.EndChangeCheck())
            {
                PolybrushSettings.Save();
            }
        }
        internal void OnGUI()
        {
            using (new GUILayout.VerticalScope("box"))
            {
                if (PolyGUILayout.HeaderWithDocsLink(Styles.headerLabel))
                {
                    Application.OpenURL(PrefUtility.documentationBrushMirroringLink);
                }

                using (new GUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();
                    s_MirrorAxes.value  = (BrushMirror)PolyGUILayout.BitMaskField((uint)s_MirrorAxes.value, Styles.axesNameArray, Styles.axesFieldTooltip);
                    s_MirrorSpace.value = (MirrorCoordinateSpace)GUILayout.Toolbar((int)s_MirrorSpace.value, Styles.mirrorSpaces);
                    if (EditorGUI.EndChangeCheck())
                    {
                        PolybrushSettings.Save();
                        RefreshSettings();
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Draw everything concerning a single Prefab Palette in the Polybrush Window
        /// </summary>
        /// <param name="thumbSize">size of the preview textures</param>
        internal void OnInspectorGUI_Internal(int thumbSize)
        {
            PolyGUILayout.Label(m_GCCurrentPaletteLabel);

            serializedObject.Update();
            int  count        = prefabs != null ? prefabs.arraySize : 0;
            Rect dropDownZone = EditorGUILayout.BeginVertical(paletteStyle);

            dropDownZone.width = EditorGUIUtility.currentViewWidth;
            Rect backGroundRect = new Rect(dropDownZone);

            if (count != 0)
            {
                const int pad  = 4;
                int       size = thumbSize + pad;
                backGroundRect.x += 8;
                backGroundRect.y += 4;
                // The backgroundRect is currently as wide as the current view.
                // Adjust it to take the size of the vertical scrollbar and padding into account.
                backGroundRect.width -= (20 + (int)GUI.skin.verticalScrollbar.fixedWidth);
                // size variable will not take into account the padding to the right of all the thumbnails,
                // therefore it needs to be substracted from the width.
                int container_width = ((int)Mathf.Floor(backGroundRect.width) - (pad + 1));
                int columns         = (int)Mathf.Floor(container_width / size);
                int rows            = count / columns + (count % columns == 0 ? 0 : 1);
                if (rows < 1)
                {
                    rows = 1;
                }

                backGroundRect.height = 8 + rows * thumbSize + (rows - 1) * pad;
                EditorGUI.DrawRect(backGroundRect, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);

                int currentIndex = 0;
                for (int i = 0; i < rows; i++)
                {
                    var horizontalRect = EditorGUILayout.BeginHorizontal();
                    for (int j = 0; j < columns; j++)
                    {
                        GUILayout.Space(pad);
                        var prefab          = prefabs.GetArrayElementAtIndex(currentIndex);
                        var previewRectXPos = pad + j * size + horizontalRect.x;
                        DrawPrefabPreview(prefab, currentIndex, thumbSize, previewRectXPos, horizontalRect.y);
                        currentIndex++;
                        if (currentIndex >= count)
                        {
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(pad);
                }

                EditorGUILayout.EndVertical();

                if (selected.Count > 0)
                {
                    EditorGUILayout.LabelField(m_GCPlacementSettingsLabel);
                    GUILayout.Space(pad);
                }

                EditorGUILayout.BeginVertical();

                foreach (var i in selected)
                {
                    DrawSinglePrefabPlacementSettings(prefabs.GetArrayElementAtIndex(i), i);
                }

                /// Little Hack to get the Rect for dropping new prefabs
                Rect endDropDownZone = EditorGUILayout.BeginVertical();
                dropDownZone.height = endDropDownZone.y - dropDownZone.y;
                EditorGUILayout.EndVertical();
            }
            else
            {
                dropDownZone.height = thumbSize;
                var r = EditorGUILayout.BeginVertical(GUILayout.Height(thumbSize + 4));
                EditorGUI.DrawRect(r, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);
                GUILayout.FlexibleSpace();
                GUILayout.Label("Drag Prefabs Here!", EditorStyles.centeredGreyMiniLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();

            Event e = Event.current;

            if (dropDownZone.Contains(e.mousePosition) &&
                (e.type == EventType.DragUpdated || e.type == EventType.DragPerform) && DragAndDrop.objectReferences.Length > 0)
            {
                if (PolyEditorUtility.ContainsPrefabAssets(DragAndDrop.objectReferences))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }

                if (e.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    IEnumerable <GameObject> dragAndDropReferences = DragAndDrop.objectReferences
                                                                     .Where(x => x is GameObject && PolyEditorUtility.IsPrefabAsset(x)).Cast <GameObject>();

                    foreach (GameObject go in dragAndDropReferences)
                    {
                        prefabs.InsertArrayElementAtIndex(prefabs.arraySize);
                        SerializedProperty last       = prefabs.GetArrayElementAtIndex(prefabs.arraySize - 1);
                        SerializedProperty gameObject = last.FindPropertyRelative("gameObject");
                        gameObject.objectReferenceValue = go;
                        PlacementSettings.PopulateSerializedProperty(last.FindPropertyRelative("settings"));
                        last.FindPropertyRelative("name").stringValue = go.name;
                    }
                }
            }

            if (e.type == EventType.KeyUp)
            {
                if (IsDeleteKey(e) && !GUI.GetNameOfFocusedControl().Contains("cancelbackspace"))
                {
                    PrefabPalette t = target as PrefabPalette;
                    t.RemoveRange(selected.ToArray());

                    selected.Clear();

                    if (onSelectionChanged != null)
                    {
                        onSelectionChanged(null);
                    }

                    PolybrushEditor.DoRepaint();
                }
            }

            serializedObject.ApplyModifiedProperties();
            redrawCounter += 1;
        }
Пример #8
0
        void DrawBrushSettings()
        {
            // Brush preset selector
            using (new GUILayout.VerticalScope("box"))
            {
                // Show the settings header in PolyEditor so that the preset selector can be included in the block.
                // Can't move preset selector to BrushSettingsEditor because it's a CustomEditor for BrushSettings,
                // along with other issues.
                if (PolyGUILayout.HeaderWithDocsLink(PolyGUI.TempContent("Brush Settings")))
                {
                    Application.OpenURL(PrefUtility.documentationBrushSettingsLink);
                }

                using (new GUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();

                    m_CurrentBrushIndex = EditorGUILayout.Popup(m_CurrentBrushIndex, m_AvailableBrushesStrings, "Popup");

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (m_CurrentBrushIndex >= m_AvailableBrushes.Count)
                        {
                            SetBrushSettings(BrushSettingsEditor.AddNew(brushSettings));
                        }
                        else
                        {
                            SetBrushSettings(m_AvailableBrushes[m_CurrentBrushIndex]);
                        }
                    }

                    if (GUILayout.Button(m_GCSaveBrushSettings, GUILayout.Width(40)))
                    {
                        if (brushSettings != null && brushSettingsAsset != null)
                        {
                            // integer 0, 1 or 2 corresponding to ok, cancel and alt buttons
                            int res = EditorUtility.DisplayDialogComplex("Save Brush Settings", "Overwrite brush preset, or Create a New brush preset? ", "Overwrite", "Create New", "Cancel");

                            if (res == 0)
                            {
                                brushSettings.CopyTo(brushSettingsAsset);
                                EditorGUIUtility.PingObject(brushSettingsAsset);
                            }
                            else if (res == 1)
                            {
                                BrushSettings dup = BrushSettingsEditor.AddNew(brushSettings);
                                SetBrushSettings(dup);
                                EditorGUIUtility.PingObject(brushSettingsAsset);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Something went wrong saving brush settings.");
                        }
                    }
                }
                EditorGUI.BeginChangeCheck();

                brushEditor.OnInspectorGUI();
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Manually show the settings header in PolyEditor so that the preset selector can be included in the block
            // if(PolyGUILayout.HeaderWithDocsLink(PolyGUI.TempContent("Brush Settings")))
            //  Application.OpenURL("http://procore3d.github.io/polybrush/brushSettings/");

            showSettingsBounds = PolyGUILayout.Foldout(showSettingsBounds, m_GCBrushSettingsMinMax);

            if (showSettingsBounds)
            {
                using (new EditorGUI.IndentLevelScope())
                {
                    using (new GUILayout.VerticalScope())
                    {
                        brushRadiusMin.floatValue = PolyGUILayout.FloatField(m_GCRadiusMin, brushRadiusMin.floatValue);
                        brushRadiusMin.floatValue = Mathf.Clamp(brushRadiusMin.floatValue, .0001f, Mathf.Infinity);

                        brushRadiusMax.floatValue = PolyGUILayout.FloatField(m_GCRadiusMax, brushRadiusMax.floatValue);
                        brushRadiusMax.floatValue = Mathf.Clamp(brushRadiusMax.floatValue, brushRadiusMin.floatValue + .001f, Mathf.Infinity);

                        allowNonNormalizedFalloff.boolValue = PolyGUILayout.Toggle(m_GCAllowUnclampedFalloff, allowNonNormalizedFalloff.boolValue);
                    }
                }
            }

            radius.floatValue   = PolyGUILayout.FloatFieldWithSlider(m_GCRadius, radius.floatValue, brushRadiusMin.floatValue, brushRadiusMax.floatValue);
            strength.floatValue = PolyGUILayout.FloatFieldWithSlider(m_GCStrength, strength.floatValue, 0f, 1f);
            falloff.floatValue  = PolyGUILayout.FloatFieldWithSlider(m_GCFalloff, falloff.floatValue, 0f, 1f);

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField(m_GCFalloffCurve, GUILayout.Width(100));

                if (allowNonNormalizedFalloff.boolValue)
                {
                    curve.animationCurveValue = EditorGUILayout.CurveField(curve.animationCurveValue, GUILayout.MinHeight(22));
                }
                else
                {
                    curve.animationCurveValue = EditorGUILayout.CurveField(curve.animationCurveValue, Color.green, RECT_ONE, GUILayout.MinHeight(22));
                }
            }

            Keyframe[] keys = curve.animationCurveValue.keys;

            if ((approx(keys[0].time, 0f) && approx(keys[0].value, 0f) && approx(keys[1].time, 1f) && approx(keys[1].value, 1f)))
            {
                Keyframe[] rev = new Keyframe[keys.Length];

                for (int i = 0; i < keys.Length; i++)
                {
                    rev[keys.Length - i - 1] = new Keyframe(1f - keys[i].time, keys[i].value, -keys[i].outTangent, -keys[i].inTangent);
                }

                curve.animationCurveValue = new AnimationCurve(rev);
            }
            serializedObject.ApplyModifiedProperties();

            SceneView.RepaintAll();
        }
Пример #10
0
        /// <summary>
        /// Show the list of current loadouts
        /// </summary>
        /// <param name="thumbSize">Size of the preview texture</param>
        internal void DrawLoadoutList(int thumbSize)
        {
            SyncLoadoutWithPalettes();

            int count = m_CurrentLoadouts.Count;

            PolyGUILayout.Label(Styles.brushLoadoutLabel);

            Rect backGroundRect = EditorGUILayout.BeginVertical(PrefabPaletteEditor.paletteStyle);

            backGroundRect.width = EditorGUIUtility.currentViewWidth;
            if (count == 0)
            {
                var r = EditorGUILayout.BeginVertical(GUILayout.Height(thumbSize + 4));
                EditorGUI.DrawRect(r, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);
                GUILayout.FlexibleSpace();
                GUILayout.Label("Select items from the Palette below", EditorStyles.centeredGreyMiniLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndVertical();
                return;
            }

            const int pad  = 4;
            int       size = thumbSize + pad;

            backGroundRect.x += 8;
            backGroundRect.y += 4;
            // The backgroundRect is currently as wide as the current view.
            // Adjust it to take the size of the vertical scrollbar and padding into account.
            backGroundRect.width -= (20 + (int)GUI.skin.verticalScrollbar.fixedWidth);
            // size variable will not take into account the padding to the right of all the thumbnails,
            // therefore it needs to be substracted from the width.
            int container_width = ((int)Mathf.Floor(backGroundRect.width) - (pad + 1));
            int columns         = (int)Mathf.Floor(container_width / size);

            if (columns == 0)
            {
                columns = 1;
            }
            int rows = count / columns + (count % columns == 0 ? 0 : 1);

            if (rows < 1)
            {
                rows = 1;
            }

            backGroundRect.height = 8 + rows * thumbSize + (rows - 1) * pad;
            EditorGUI.DrawRect(backGroundRect, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);

            int currentIndex = 0;

            for (int i = 0; i < rows; i++)
            {
                var horizontalRect = EditorGUILayout.BeginHorizontal();
                for (int j = 0; j < columns; j++)
                {
                    LoadoutInfo         loadoutInfo  = m_CurrentLoadouts[currentIndex];
                    PrefabPaletteEditor prefabEditor = prefabPaletteEditors[loadoutInfo.palette];
                    SerializedProperty  prefabs      = prefabEditor.prefabs;
                    SerializedProperty  prefab       = prefabs.GetArrayElementAtIndex(loadoutInfo.palette.FindIndex(loadoutInfo.prefab));

                    var previewRectXPos = pad + j * size + horizontalRect.x;
                    DrawSingleLoadout(prefab, thumbSize, loadoutInfo, previewRectXPos, horizontalRect.y);
                    if (j != columns - 1)
                    {
                        GUILayout.Space(pad);
                    }
                    currentIndex++;
                    if (currentIndex >= count)
                    {
                        break;
                    }
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(4);
            }
            EditorGUILayout.EndVertical();

            if (toUnload != null)
            {
                RemovePrefabFromLoadout(toUnload);
                toUnload = null;
                SaveUserCurrentLoadouts();
            }
        }