static internal BrushSettings[] GetAvailableBrushes()
        {
            List <BrushSettings> brushes = PolyEditorUtility.GetAll <BrushSettings>();

            if (brushes.Count < 1)
            {
                brushes.Add(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            return(brushes.ToArray());
        }
        static internal IReadOnlyCollection <BrushSettings> GetAvailableBrushes()
        {
            List <BrushSettings> brushes = PolyEditorUtility.GetAll <BrushSettings>();

            if (brushes.Count < 1)
            {
                brushes.Add(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            return(brushes);
        }
Exemple #3
0
        void RefreshAvailablePalettes()
        {
            m_AvailablePalettes = PolyEditorUtility.GetAll <PrefabPalette>().ToArray();

            if (m_AvailablePalettes.Length < 1)
            {
                prefabPalette = PolyEditorUtility.GetFirstOrNew <PrefabPalette>();
            }

            m_AvailablePalettesAsStrings = m_AvailablePalettes.Select(x => x.name).ToArray();
            ArrayUtility.Add <string>(ref m_AvailablePalettesAsStrings, string.Empty);
            ArrayUtility.Add <string>(ref m_AvailablePalettesAsStrings, "Add Palette...");
            m_CurrentPaletteIndex = System.Array.IndexOf(m_AvailablePalettes, m_PrefabPalette);
        }
        /// <summary>
        /// Refresh the list of available BrushSettings
        /// </summary>
        internal void RefreshAvailableBrushes()
        {
            m_AvailableBrushes = PolyEditorUtility.GetAll <BrushSettings>();

            if (m_AvailableBrushes.Count < 1)
            {
                m_AvailableBrushes.Add(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            m_CurrentBrushIndex = System.Math.Max(m_AvailableBrushes.FindIndex(x => x.name.Equals(brushSettings.name)), 0);

            m_AvailableBrushesStrings = m_AvailableBrushes.Select(x => x.name).ToArray();

            ArrayUtility.Add <string>(ref m_AvailableBrushesStrings, string.Empty);
            ArrayUtility.Add <string>(ref m_AvailableBrushesStrings, "Add Brush...");
        }
        void OnSceneGUI(SceneView sceneView)
        {
            if (mode == null)
            {
                return;
            }

            Event e = Event.current;

            CheckForEscapeKey(e);

            if (Tools.current != Tool.None)
            {
                SetTool(BrushTool.None);
            }

            if (brushSettings == null)
            {
                SetBrushSettings(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            if (PolySceneUtility.SceneViewInUse(e) || tool == BrushTool.None)
            {
                // Force exit the current brush if user's mouse left
                // the SceneView while a brush was still in use.
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                }
                return;
            }

            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (Util.IsValid(brushTarget))
            {
                HandleUtility.AddDefaultControl(controlID);
            }

            switch (e.GetTypeForControl(controlID))
            {
            case EventType.MouseMove:
                // Handles:
                //		OnBrushEnter
                //		OnBrushExit
                //		OnBrushMove
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseDown:
            case EventType.MouseDrag:
                // Handles:
                //		OnBrushBeginApply
                //		OnBrushApply
                //		OnBrushFinishApply
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                    ApplyBrush(Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseUp:
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.ScrollWheel:
                ScrollBrushSettings(e);
                break;
            }

            if (Util.IsValid(brushTarget))
            {
                mode.DrawGizmos(brushTarget, brushSettings);
            }
        }
        void OnEnable()
        {
            if (!PrefUtility.VersionCheck())
            {
                PrefUtility.ClearPrefs();
            }

            PolyEditor.s_Instance = this;

            // Editor window setup
            titleContent   = new GUIContent("Polybrush");
            wantsMouseMove = true;
            minSize        = k_EditorWindowMinimumSize;

            m_BrushMirrorEditor = new MirrorSettingsEditor();

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

            m_GCToolmodeIcons = new GUIContent[]
            {
                EditorGUIUtility.TrIconContent(IconUtility.GetIcon("Toolbar/Sculpt"), "Sculpt on meshes"),
                EditorGUIUtility.TrIconContent(IconUtility.GetIcon("Toolbar/Smooth"), "Smooth mesh geometry"),
                EditorGUIUtility.TrIconContent(IconUtility.GetIcon("Toolbar/PaintVertexColors"), "Paint vertex colors on meshes"),
                EditorGUIUtility.TrIconContent(IconUtility.GetIcon("Toolbar/PaintPrefabs"), "Scatter Prefabs on meshes"),
                EditorGUIUtility.TrIconContent(IconUtility.GetIcon("Toolbar/PaintTextures"), "Paint textures on meshes"),
            };

#if UNITY_2019_1_OR_NEWER
            SceneView.duringSceneGui += OnSceneGUI;
#else
            SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
            Undo.undoRedoPerformed += UndoRedoPerformed;

            // force update the preview
            m_LastHoveredGameObject = null;

            if (brushSettings == null)
            {
                if (brushSettingsAsset == null)
                {
                    brushSettingsAsset = AssetDatabase.LoadAssetAtPath <BrushSettings>(AssetDatabase.GUIDToAssetPath(EditorPrefs.GetString(k_BrushSettingsAssetPref, "")));
                }

                if (EditorPrefs.HasKey(k_BrushSettingsPref))
                {
                    brushSettings = ScriptableObject.CreateInstance <BrushSettings>();
                    JsonUtility.FromJsonOverwrite(EditorPrefs.GetString(k_BrushSettingsPref), brushSettings);
                    if (EditorPrefs.HasKey(k_BrushSettingsName))
                    {
                        brushSettings.name = EditorPrefs.GetString(k_BrushSettingsName);
                    }
                }
                else
                {
                    SetBrushSettings(brushSettingsAsset != null ? brushSettingsAsset : PolyEditorUtility.GetFirstOrNew <BrushSettings>());
                }
            }

            RefreshAvailableBrushes();

            SetTool(BrushTool.RaiseLower, false);

            Selection.selectionChanged -= OnSelectionChanged;
            Selection.selectionChanged += OnSelectionChanged;
        }
Exemple #7
0
        void OnSceneGUI(SceneView sceneView)
        {
            if (mode == null)
            {
                return;
            }

            Event e = Event.current;

            CheckForEscapeKey(e);

            if (Tools.current != Tool.None)
            {
                SetTool(BrushTool.None);
            }

            if (brushSettings == null)
            {
                SetBrushSettings(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            if (PolySceneUtility.SceneViewInUse(e) || tool == BrushTool.None)
            {
                // Force exit the current brush if user's mouse left
                // the SceneView while a brush was still in use.
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                }
                return;
            }

            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (Util.IsValid(brushTarget))
            {
                HandleUtility.AddDefaultControl(controlID);
            }

            switch (e.GetTypeForControl(controlID))
            {
            case EventType.MouseMove:
                // Handles:
                //		OnBrushEnter
                //		OnBrushExit
                //		OnBrushMove
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseDown:
            case EventType.MouseDrag:
                // Handles:
                //		OnBrushBeginApply
                //		OnBrushApply
                //		OnBrushFinishApply
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                    ApplyBrush(Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseUp:
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.ScrollWheel:
                ScrollBrushSettings(e);
                break;

            case EventType.KeyDown:
                // Key down event continues as long as the key is held down. However, we only need to update the brush once while the key is down.
                // Check if the key has already been marked as pressed in the brush settings, and don't update if it is.
                if (((e.keyCode == KeyCode.LeftControl || e.keyCode == KeyCode.RightControl) && !brushSettings.isUserHoldingControl) ||
                    ((e.keyCode == KeyCode.LeftShift || e.keyCode == KeyCode.RightShift) && !brushSettings.isUserHoldingShift))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.KeyUp:
                // Key up only happens once, so don't need to check if we were already holding control/shift
                if ((e.keyCode == KeyCode.LeftControl || e.keyCode == KeyCode.RightControl) ||
                    (e.keyCode == KeyCode.LeftShift || e.keyCode == KeyCode.RightShift))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;
            }

            if (Util.IsValid(brushTarget))
            {
                mode.DrawGizmos(brushTarget, brushSettings);
            }
        }
Exemple #8
0
        /// <summary>
        /// Makes sure we always have a valid BrushSettings selected in Polybrush then refresh the available list for the EditorWindow.
        /// Will create a new file if it cannot find any.
        /// </summary>
        internal void EnsureBrushSettingsListIsValid()
        {
            if (brushSettings == null)
            {
                if (brushSettingsAsset == null)
                {
                    brushSettingsAsset = BrushSettingsEditor.LoadBrushSettingsAssets(EditorPrefs.GetString(k_BrushSettingsAssetPref, ""));
                }

                if (EditorPrefs.HasKey(k_BrushSettingsPref))
                {
                    brushSettings = ScriptableObject.CreateInstance <BrushSettings>();
                    JsonUtility.FromJsonOverwrite(EditorPrefs.GetString(k_BrushSettingsPref), brushSettings);
                    if (EditorPrefs.HasKey(k_BrushSettingsName))
                    {
                        brushSettings.name = EditorPrefs.GetString(k_BrushSettingsName);
                    }
                }
                else
                {
                    SetBrushSettings(brushSettingsAsset != null ? brushSettingsAsset : PolyEditorUtility.GetFirstOrNew <BrushSettings>());
                }
            }

            m_AvailableBrushes = BrushSettingsEditor.GetAvailableBrushes();

            m_AvailableBrushesStrings = m_AvailableBrushes.Select(x => x.name).ToArray();
            m_CurrentBrushIndex       = System.Math.Max(Array.FindIndex <string>(m_AvailableBrushesStrings, x => x == brushSettings.name), 0);

            ArrayUtility.Add <string>(ref m_AvailableBrushesStrings, string.Empty);
            ArrayUtility.Add <string>(ref m_AvailableBrushesStrings, "Add Brush...");
        }
        /// <summary>
        /// Makes sure we always have a valid BrushSettings selected in Polybrush then refresh the available list for the EditorWindow.
        /// Will create a new file if it cannot find any.
        /// </summary>
        internal void EnsureBrushSettingsListIsValid()
        {
            if (brushSettings == null)
            {
                if (brushSettingsAsset == null)
                {
                    brushSettingsAsset = BrushSettingsEditor.LoadBrushSettingsAssets(EditorPrefs.GetString(k_BrushSettingsAssetPref, ""));
                }

                if (EditorPrefs.HasKey(k_BrushSettingsPref))
                {
                    brushSettings = ScriptableObject.CreateInstance <BrushSettings>();
                    JsonUtility.FromJsonOverwrite(EditorPrefs.GetString(k_BrushSettingsPref), brushSettings);
                    if (EditorPrefs.HasKey(k_BrushSettingsName))
                    {
                        brushSettings.name = EditorPrefs.GetString(k_BrushSettingsName);
                    }
                }
                else
                {
                    SetBrushSettings(brushSettingsAsset != null ? brushSettingsAsset : PolyEditorUtility.GetFirstOrNew <BrushSettings>());
                }
            }
        }