/// <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() { VerifyLoadedBrushAssetsIntegrity(); if (brushSettings == null) { if (brushSettingsAsset == null) { brushSettingsAsset = BrushSettingsEditor.LoadBrushSettingsAssets(EditorPrefs.GetString(k_BrushSettingsAssetPref, "")); } if (EditorPrefs.HasKey(k_BrushSettingsPref) && brushSettingsAsset != null) { 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>()); } } }
void PopulateAvailableBrushList() { 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> /// Updates the current available brushes to update the dropdown list. /// </summary> void RefreshAvailableBrushList() { m_AvailableBrushes = BrushSettingsEditor.GetAvailableBrushes(); m_AvailableBrushesStrings = m_AvailableBrushes.Select(x => x.name).ToArray(); var brushSettingsName = brushSettings != null ? brushSettings.name : (EditorPrefs.HasKey(k_BrushSettingsName) ? EditorPrefs.GetString(k_BrushSettingsName) : String.Empty); m_CurrentBrushIndex = System.Math.Max(Array.FindIndex <string>(m_AvailableBrushesStrings, x => x == brushSettingsName), 0); ArrayUtility.Add <string>(ref m_AvailableBrushesStrings, string.Empty); ArrayUtility.Add <string>(ref m_AvailableBrushesStrings, "Add Brush..."); }
/// <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 VerifyLoadedBrushAssetsIntegrity() { if (m_AvailableBrushes != null && m_AvailableBrushes.Length > 0 && !System.Array.TrueForAll(m_AvailableBrushes, x => x != null)) { RefreshAvailableBrushList(); m_CurrentBrushIndex = 0; if (m_AvailableBrushes.Length > 0) { SetBrushSettings(m_AvailableBrushes[m_CurrentBrushIndex]); } else { SetBrushSettings(BrushSettingsEditor.AddNew(brushSettings)); } } }
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(); } }