Пример #1
0
        void OnDisable()
        {
            Selection.selectionChanged -= OnSelectionChanged;
#if UNITY_2019_1_OR_NEWER
            SceneView.duringSceneGui -= OnSceneGUI;
#else
            SceneView.onSceneGUIDelegate -= OnSceneGUI;
#endif
            Undo.undoRedoPerformed -= UndoRedoPerformed;
            //EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyWindowItemChanged;

#if PROBUILDER_4_0_OR_NEWER
            if (ProBuilderBridge.ProBuilderExists())
            {
                ProBuilderBridge.UnsubscribeToSelectModeChanged(OnProBuilderSelectModeChanged);
            }
#endif


            // store local changes to brushSettings
            if (brushSettings != null)
            {
                var js = JsonUtility.ToJson(brushSettings, true);
                EditorPrefs.SetString(k_BrushSettingsPref, js);
            }

            // don't iterate here!  FinalizeAndReset does that
            OnBrushExit(m_LastHoveredGameObject);
            FinalizeAndResetHovering();

            PreviewsDatabase.UnloadCache();
        }
Пример #2
0
        /// <summary>
        /// Draw a single loadout
        /// </summary>
        /// <param name="loadout">The loadout being drawn</param>
        /// <param name="thumbSize">Size of the preview</param>
        /// <param name="infos">additionnal infos about the loadout being drawn (parent prefab palette and index in it)</param>
        void DrawSingleLoadout(SerializedProperty loadout, int thumbSize, LoadoutInfo infos, float x, float y)
        {
            var editor = prefabPaletteEditors[infos.palette];

            editor.serializedObject.Update();
            Rect r = new Rect(x, y, thumbSize, thumbSize);

            // Texture Preview
            Texture2D preview = PreviewsDatabase.GetAssetPreview(loadout.FindPropertyRelative("gameObject").objectReferenceValue);

            EditorGUI.DrawPreviewTexture(r, preview);
            float pad = thumbSize * 0.05f;

            GUILayoutUtility.GetRect(thumbSize, thumbSize);

            Rect r3 = new Rect(r);

            r3.width  = Styles.deleteButtonStyle.fixedWidth;
            r3.height = Styles.deleteButtonStyle.fixedHeight;
            r3.x     += thumbSize - pad - r3.width;
            r3.y     += pad;
            if (GUI.Button(r3, "", Styles.deleteButtonStyle))
            {
                toUnload    = infos;
                GUI.changed = true;
            }
            r.y    += thumbSize - pad - 10;
            r.x    += pad;
            r.width = thumbSize - (2 * pad);
            var prefabOccurence = loadout.FindPropertyRelative("settings").FindPropertyRelative("m_Strength");

            prefabOccurence.floatValue = GUI.HorizontalSlider(r, prefabOccurence.floatValue, BrushModePrefab.k_PrefabOccurrenceMin, BrushModePrefab.k_PrefabOccurrenceMax);

            editor.serializedObject.ApplyModifiedProperties();
        }
Пример #3
0
        internal static bool AssetPreviewButton(Rect rect, Object obj, bool selected)
        {
            bool clicked = false;
            Rect r       = rect;
            Rect border  = new Rect(r.x + 2, r.y + 6, r.width - 4, r.height - 4);

            EditorGUI.DrawRect(border, texture_button_border);

            border.x      += 2;
            border.y      += 2;
            border.width  -= 4;
            border.height -= 4;

            Texture2D preview = PreviewsDatabase.GetAssetPreview(obj);

            if (preview != null)
            {
                EditorGUI.DrawPreviewTexture(border, preview, null, ScaleMode.ScaleToFit, 0f);
            }
            else
            {
                string text = obj != null ? obj.name : "null";
                EditorGUI.DrawRect(border, texture_button_fill);
                GUI.Label(border, text, PolyGUI.CenteredStyle);
            }

            if (selected)
            {
                r.y     += r.height + 4;
                r.x     += 2;
                r.width -= 5;
                r.height = 6;

                EditorGUI.DrawRect(r, Color.green);
            }

            clicked = GUI.Button(border, "", GUIStyle.none);

            return(clicked);
        }
Пример #4
0
        /// <summary>
        /// Draws previews for a prefab in the palette.
        /// </summary>
        /// <param name="prefab">Prefab being previewed</param>
        /// <param name="index">index of the prefab in `prefabs`</param>
        /// <param name="thumbSize">Size of the preview texture</param>
        private void DrawPrefabPreview(SerializedProperty prefab, int index, int thumbSize, float x, float y)
        {
            Rect r = new Rect(x, y, thumbSize, thumbSize);
            Rect rightClickZone = new Rect(r);

            // Texture Preview
            UnityEngine.Object o = prefab.FindPropertyRelative("gameObject").objectReferenceValue;

            Texture2D preview = PreviewsDatabase.GetAssetPreview(o);

            if (selected.Contains(index))
            {
                Rect r2 = new Rect(r);
                r2.x      -= 1;
                r2.y      -= 1;
                r2.width  += 2;
                r2.height += 2;
                EditorGUI.DrawRect(r2, Color.blue);
            }

            EditorGUI.DrawPreviewTexture(r, preview);

            // Those numbers were obtained by empirical experimentation
            r.x     += thumbSize - 17;
            r.y     += thumbSize - 17;
            r.width  = 17;
            r.height = 17;
            LoadoutInfo li         = new LoadoutInfo(target as PrefabPalette, index);
            bool        isLoaded   = loadoutEditor.ContainsPrefab(li);
            Event       e          = Event.current;
            bool        rightClick = (e.type == EventType.MouseDown || e.type == EventType.ContextClick) && rightClickZone.Contains(e.mousePosition) && e.button == 1;
            bool        b1         = GUI.Toggle(r, isLoaded, "");
            // Reducing the width by 1 to ensure the button is not larger than the thumbnail.
            // Otherwise button is slightly too large and horizontal scrollbar may appear.
            bool b2 = GUILayout.Button("", GUIStyle.none, GUILayout.Width(thumbSize - 1), GUILayout.Height(thumbSize));

            // Set the focus to nothing in case the user want to press delete or backspace key
            // I dont know why but If we don't do that the Textfield with the name of prefab settings never looses focus
            if (b2 || rightClick)
            {
                GUI.FocusControl(null);
                e.Use();
            }
            if (rightClick)
            {
                rightClickTime        = redrawCounter;
                shouldopencontextmenu = true;
                idx = index;
                if (!selected.Contains(index))
                {
                    selected.Clear();
                    selected.Add(index);
                }
                return;
            }
            else if (shouldopencontextmenu && redrawCounter > rightClickTime)
            {
                loadoutEditor.OpenCopyPasteMenu(new LoadoutInfo(target as PrefabPalette, idx), selected);
                shouldopencontextmenu = false;
                idx = -1;
                // reset  the redraw counter to avoid overflow
                redrawCounter = 0;
            }

            if (b1 && !isLoaded)
            {
                loadoutEditor.AddPrefabInLoadout(li);
                //loadoutEditor.loadouts.Add(li);
            }
            else if (!b1 && isLoaded)
            {
                loadoutEditor.RemovePrefabFromLoadout(li);
                //loadoutEditor.loadouts.Remove(li);
            }
            else if (b2)
            {
                if (Event.current.shift || Event.current.control)
                {
                    if (!selected.Add(index))
                    {
                        selected.Remove(index);
                    }
                }
                else
                {
                    if (selected.Count == 1 && selected.Contains(index))
                    {
                        selected.Remove(index);
                    }
                    else
                    {
                        selected.Clear();
                        selected.Add(index);
                    }
                }

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

                GUI.changed = true;
            }
        }