/// <summary>
        /// Copy or paste settings to selected PlacementSettings
        /// </summary>
        /// <param name="loadout">The loadout that got clicked</param>
        /// <param name="copy">do we copy or paste ?</param>
        /// <param name="selected">the list of currently selected PlacementSettings for edition in the current PrefabPalette</param>
        private void CopyPasteSettings(LoadoutInfo loadout, bool copy, HashSet <int> selected)
        {
            if (copy)
            {
                copyPastePrefabSettings = loadout;
            }
            else
            {
                if (copyPastePrefabSettings == null)
                {
                    return;
                }

                PrefabPaletteEditor sourceEditor = prefabPaletteEditors[copyPastePrefabSettings.palette];
                PrefabPaletteEditor destEditor   = prefabPaletteEditors[loadout.palette];
                SerializedProperty  srcPAS       = sourceEditor.prefabs.GetArrayElementAtIndex(loadout.palette.FindIndex(loadout.prefab));
                SerializedProperty  srcPS        = srcPAS.FindPropertyRelative("settings");
                destEditor.serializedObject.Update();
                foreach (int i in selected)
                {
                    SerializedProperty destPAS = destEditor.prefabs.GetArrayElementAtIndex(i);
                    SerializedProperty destPS  = destPAS.FindPropertyRelative("settings");
                    PlacementSettings.CopySerializedProperty(srcPS, destPS);
                }
                destEditor.serializedObject.ApplyModifiedProperties();
            }
        }
        // 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);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Verify if all loaded assets haven't been touched by users.
        /// If one or multiples assets are missing, refresh the Palettes list and loadouts.
        /// </summary>
        void VerifyLoadedAssetsIntegrity()
        {
            if (m_AvailablePalettes.Length > 0 &&
                !System.Array.TrueForAll(m_AvailablePalettes, x => x != null))
            {
                RefreshAvailablePalettes();
                m_CurrentPaletteIndex = 0;
                if (m_AvailablePalettes.Length > 0)
                {
                    SetPrefabPalette(m_AvailablePalettes[m_CurrentPaletteIndex]);
                }
                else
                {
                    SetPrefabPalette(PrefabPaletteEditor.AddNew());
                }

                prefabLoadoutEditor.RefreshPalettesList(m_AvailablePalettes.ToList());
            }
        }
        /// <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();
            }
        }
        /// <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;

            EditorGUILayout.LabelField(Styles.brushLoadoutLabel);

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

            if (count == 0)
            {
                var r = EditorGUILayout.BeginVertical(GUILayout.Height(thumbSize));
                EditorGUI.DrawRect(r, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);
                GUILayout.FlexibleSpace();
                if (GUI.skin.name.Contains("polybrush"))
                {
                    EditorGUILayout.LabelField("No loadout selected yet", "dragprefablabel");
                }
                else
                {
                    EditorGUILayout.LabelField("No loadout selected yet", EditorStyles.centeredGreyMiniLabel);
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndVertical();
                return;
            }

            const int margin_x        = 8;
            const int pad             = 4;
            int       size            = thumbSize + pad;
            float     width           = EditorGUIUtility.currentViewWidth;
            int       container_width = (int)Mathf.Floor(EditorGUIUtility.currentViewWidth) - (margin_x * 2);
            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.x     += 4;
            backGroundRect.y     += 4;
            backGroundRect.width -= 8;
            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++)
            {
                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));

                    DrawSingleLoadout(prefab, thumbSize, loadoutInfo);
                    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();
            }
        }