Skip to content

Commit 21b5441

Browse files
git-upm-publisherstarikcetin
authored andcommitted
UPM release 4.1.0
1 parent 7dbcaf0 commit 21b5441

22 files changed

+711
-10
lines changed

.assets/event_adapter.png

42.2 KB
Loading

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919

2020

2121

22+
## [4.1.0] - 2024-06-16
23+
24+
### Added
25+
- `SceneReferenceUnityEventAdapter` class: A utility `MonoBehaviour` that allows using statically provided `SceneReference`s as parameters to a `UnityEvent`.
26+
- Utility Ignores: A set of settings that allow ignoring certain scenes from having the inline utilities.
27+
28+
29+
2230
## [4.0.0] - 2024-01-23
2331
There are fundamental changes to the editor-time behaviour in this release. Please examine carefully before upgrading.
2432

Editor/IgnoreCheckers.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace Eflatun.SceneReference.Editor
4+
{
5+
internal static class IgnoreCheckers
6+
{
7+
public static IgnoreChecker Coloring = new IgnoreChecker(SettingsManager.UtilityIgnores.ColoringIgnoresPatterns.value);
8+
public static IgnoreChecker Toolbox = new IgnoreChecker(SettingsManager.UtilityIgnores.ToolboxIgnoresPatterns.value);
9+
10+
internal class IgnoreChecker
11+
{
12+
private static readonly string[] LineSeperators = new string[] { "\r\n", "\r", "\n" };
13+
14+
private Ignore.Ignore Checker;
15+
16+
public IgnoreChecker(string patterns)
17+
{
18+
SetPatterns(patterns);
19+
}
20+
21+
public void SetPatterns(string patterns)
22+
{
23+
Checker = new Ignore.Ignore();
24+
var split = patterns.Split(LineSeperators, StringSplitOptions.RemoveEmptyEntries);
25+
Checker.Add(split);
26+
}
27+
28+
public bool IsIgnored(string path)
29+
{
30+
return Checker.IsIgnored(path);
31+
}
32+
}
33+
}
34+
}

Editor/IgnoreCheckers.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/SceneReferencePropertyDrawer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
@@ -46,23 +46,26 @@ private enum SceneBundlingState
4646
private AddressableAssetEntry _addressableEntry;
4747
#endif // ESR_ADDRESSABLES
4848

49-
private bool ShouldColorSceneInBuild => _optionsAttribute.SceneInBuildColoring switch
49+
private bool IsColoringIgnored => SettingsManager.UtilityIgnores.IsIgnoredForColoring(_path, _guid);
50+
private bool IsToolboxIgnored => SettingsManager.UtilityIgnores.IsIgnoredForToolbox(_path, _guid);
51+
52+
private bool ShouldColorSceneInBuild => !IsColoringIgnored && _optionsAttribute.SceneInBuildColoring switch
5053
{
5154
ColoringBehaviour.Enabled => true,
5255
ColoringBehaviour.Disabled => false,
5356
ColoringBehaviour.DoNotOverride => SettingsManager.PropertyDrawer.ColorBasedOnSceneInBuildState.value,
5457
_ => throw new ArgumentOutOfRangeException(nameof(_optionsAttribute.SceneInBuildColoring), _optionsAttribute.SceneInBuildColoring, null)
5558
};
5659

57-
private bool ShouldColorAddressable => _optionsAttribute.AddressableColoring switch
60+
private bool ShouldColorAddressable => !IsColoringIgnored && _optionsAttribute.AddressableColoring switch
5861
{
5962
ColoringBehaviour.Enabled => true,
6063
ColoringBehaviour.Disabled => false,
6164
ColoringBehaviour.DoNotOverride => SettingsManager.AddressablesSupport.ColorAddressableScenes.value,
6265
_ => throw new ArgumentOutOfRangeException(nameof(_optionsAttribute.AddressableColoring), _optionsAttribute.AddressableColoring, null)
6366
};
6467

65-
private bool ShouldShowToolbox => _optionsAttribute.Toolbox switch
68+
private bool ShouldShowToolbox => !IsToolboxIgnored && _optionsAttribute.Toolbox switch
6669
{
6770
ToolboxBehaviour.Enabled => true,
6871
ToolboxBehaviour.Disabled => false,
@@ -212,7 +215,7 @@ private ToolboxPopupWindow CreateToolboxPopupWindow()
212215
}
213216

214217
#if ESR_ADDRESSABLES
215-
if(_bundlingState == SceneBundlingState.Nowhere || _bundlingState == SceneBundlingState.InBuildDisabled)
218+
if (_bundlingState == SceneBundlingState.Nowhere || _bundlingState == SceneBundlingState.InBuildDisabled)
216219
{
217220
tools.Add(new MakeAddressableTool(_path, _guid, _asset));
218221
}

Editor/SettingsManager.cs

Lines changed: 263 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using Eflatun.SceneReference.Utility;
33
using JetBrains.Annotations;
44
using Newtonsoft.Json;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
58
using System.Reflection;
69
using UnityEditor;
710
using UnityEditor.SettingsManagement;
@@ -13,7 +16,7 @@ namespace Eflatun.SceneReference.Editor
1316
/// Manages and contains settings for Scene Reference.
1417
/// </summary>
1518
/// <remarks>
16-
/// Changing the settings from code may have unintended consequences. Make sure you now what you are doing.
19+
/// Changing the settings from code may have unintended consequences. Make sure you know what you are doing.
1720
/// </remarks>
1821
[PublicAPI]
1922
public static class SettingsManager
@@ -206,5 +209,264 @@ public static class Logging
206209
public static ProjectSetting<LogLevel> EditorLogLevel { get; }
207210
= new ProjectSetting<LogLevel>("Logging.EditorLogLevel", LogLevel.Warning);
208211
}
212+
213+
/// <summary>
214+
/// Settings for preventing certain scenes from having inline utilities.
215+
/// </summary>
216+
/// <remarks>
217+
/// <inheritdoc cref="SettingsManager"/>
218+
/// </remarks>
219+
[PublicAPI]
220+
public static class UtilityIgnores
221+
{
222+
private const string CategoryName = "Utility Ignores";
223+
224+
/// <summary>
225+
/// The mode of operation for preventing certain scenes from having the inline coloring utility.
226+
/// <list type="bullet">
227+
/// <item>
228+
/// <term><see cref="UtilityIgnoreMode.Disabled"/></term>
229+
/// <description>Nothing will be ignored.</description>
230+
/// </item>
231+
/// <item>
232+
/// <term><see cref="UtilityIgnoreMode.List"/></term>
233+
/// <description>The scenes with GUIDs in <see cref="ColoringIgnoresList"/> will not be colored.</description>
234+
/// </item>
235+
/// <item>
236+
/// <term><see cref="UtilityIgnoreMode.Patterns"/></term>
237+
/// <description>The scenes with paths matching the patterns in <see cref="ColoringIgnoresPatterns"/> will not be colored.</description>
238+
/// </item>
239+
/// </list>
240+
/// </summary>
241+
/// <remarks>
242+
/// <inheritdoc cref="SettingsManager"/>
243+
/// </remarks>
244+
[field: UserSetting]
245+
public static ProjectSetting<UtilityIgnoreMode> ColoringIgnoreMode { get; }
246+
= new ProjectSetting<UtilityIgnoreMode>("UtilityIgnores.ColoringIgnoreMode", UtilityIgnoreMode.Disabled);
247+
248+
/// <summary>
249+
/// The mode of operation for preventing certain scenes from having the inline toolbox utility.
250+
/// <list type="bullet">
251+
/// <item>
252+
/// <term><see cref="UtilityIgnoreMode.Disabled"/></term>
253+
/// <description>Nothing will be ignored.</description>
254+
/// </item>
255+
/// <item>
256+
/// <term><see cref="UtilityIgnoreMode.List"/></term>
257+
/// <description>The scenes with GUIDs in <see cref="ToolboxIgnoresList"/> will not have toolboxes.</description>
258+
/// </item>
259+
/// <item>
260+
/// <term><see cref="UtilityIgnoreMode.Patterns"/></term>
261+
/// <description>The scenes with paths matching the patterns in <see cref="ToolboxIgnoresPatterns"/> will not have toolboxes.</description>
262+
/// </item>
263+
/// </list>
264+
/// </summary>
265+
/// <remarks>
266+
/// <inheritdoc cref="SettingsManager"/>
267+
/// </remarks>
268+
[field: UserSetting]
269+
public static ProjectSetting<UtilityIgnoreMode> ToolboxIgnoreMode { get; }
270+
= new ProjectSetting<UtilityIgnoreMode>("UtilityIgnores.ToolboxIgnoreMode", UtilityIgnoreMode.Disabled);
271+
272+
/// <summary>
273+
/// If the <see cref="ColoringIgnoreMode"/> is set to <see cref="UtilityIgnoreMode.List"/>, the scenes with GUIDs in this list will not be colored.
274+
/// </summary>
275+
/// <remarks>
276+
/// <inheritdoc cref="SettingsManager"/>
277+
/// </remarks>
278+
[field: UserSetting]
279+
public static ProjectSetting<List<string>> ColoringIgnoresList { get; }
280+
= new ProjectSetting<List<string>>("UtilityIgnores.ColoringIgnoresList", new List<string>());
281+
282+
/// <summary>
283+
/// If the <see cref="ToolboxIgnoreMode"/> is set to <see cref="UtilityIgnoreMode.List"/>, the scenes with GUIDs in this list will not have toolboxes.
284+
/// </summary>
285+
/// <remarks>
286+
/// <inheritdoc cref="SettingsManager"/>
287+
/// </remarks>
288+
[field: UserSetting]
289+
public static ProjectSetting<List<string>> ToolboxIgnoresList { get; }
290+
= new ProjectSetting<List<string>>("UtilityIgnores.ToolboxIgnoresList", new List<string>());
291+
292+
/// <summary>
293+
/// If the <see cref="ColoringIgnoreMode"/> is set to <see cref="UtilityIgnoreMode.Patterns"/>, the scenes with paths matching the patterns in this setting will not be colored.<p/>
294+
/// Make sure to call <see cref="ApplyColoringIgnoresPatterns"/> after modifying this setting via code.
295+
/// </summary>
296+
/// <remarks>
297+
/// The patterns are evaluated together, just like <c>.gitignore</c> files. Each line corresponds to one pattern. The following library is used for matching patterns: <see href="https://github.com/goelhardik/ignore"/><p/>
298+
/// <inheritdoc cref="SettingsManager"/>
299+
/// </remarks>
300+
[field: UserSetting]
301+
public static ProjectSetting<string> ColoringIgnoresPatterns { get; }
302+
= new ProjectSetting<string>("UtilityIgnores.ColoringIgnoresPatterns", string.Empty);
303+
304+
/// <summary>
305+
/// If the <see cref="ToolboxIgnoreMode"/> is set to <see cref="UtilityIgnoreMode.Patterns"/>, the scenes with paths matching the patterns in this setting will not have toolboxes.
306+
/// Make sure to call <see cref="ApplyToolboxIgnoresPatterns"/> after modifying this setting via code.
307+
/// </summary>
308+
/// <remarks>
309+
/// <inheritdoc cref="ColoringIgnoresPatterns"/>
310+
/// </remarks>
311+
[field: UserSetting]
312+
public static ProjectSetting<string> ToolboxIgnoresPatterns { get; }
313+
= new ProjectSetting<string>("UtilityIgnores.ToolboxIgnoresPatterns", string.Empty);
314+
315+
/// <summary>
316+
/// Call this after modifying <see cref="ColoringIgnoresPatterns"/> via code.
317+
/// </summary>
318+
/// <remarks>
319+
/// <inheritdoc cref="ColoringIgnoresPatterns"/>
320+
/// </remarks>
321+
public static void ApplyColoringIgnoresPatterns()
322+
{
323+
IgnoreCheckers.Coloring.SetPatterns(ColoringIgnoresPatterns.value);
324+
}
325+
326+
/// <summary>
327+
/// Call this after modifying <see cref="ToolboxIgnoresPatterns"/> via code.
328+
/// </summary>
329+
/// <remarks>
330+
/// <inheritdoc cref="ColoringIgnoresPatterns"/>
331+
/// </remarks>
332+
public static void ApplyToolboxIgnoresPatterns()
333+
{
334+
IgnoreCheckers.Toolbox.SetPatterns(ToolboxIgnoresPatterns.value);
335+
}
336+
337+
internal static bool IsIgnoredForToolbox(string path, string guid) => ToolboxIgnoreMode.value switch
338+
{
339+
UtilityIgnoreMode.Disabled => false,
340+
UtilityIgnoreMode.List => ToolboxIgnoresList.value.Contains(guid),
341+
UtilityIgnoreMode.Patterns => IgnoreCheckers.Toolbox.IsIgnored(path),
342+
_ => throw new ArgumentOutOfRangeException()
343+
};
344+
345+
internal static bool IsIgnoredForColoring(string path, string guid) => ColoringIgnoreMode.value switch
346+
{
347+
UtilityIgnoreMode.Disabled => false,
348+
UtilityIgnoreMode.List => ColoringIgnoresList.value.Contains(guid),
349+
UtilityIgnoreMode.Patterns => IgnoreCheckers.Coloring.IsIgnored(path),
350+
_ => throw new ArgumentOutOfRangeException()
351+
};
352+
353+
[UserSettingBlock(CategoryName)]
354+
private static void Draw(string searchContext)
355+
{
356+
var shouldSave = false;
357+
358+
EditorGUI.BeginChangeCheck();
359+
360+
const string patternsSharedTooltip = "The patterns are evaluated together, just like .gitignore files. Each line corresponds to one pattern.\n\nThe following library is used for matching patterns: https://github.com/goelhardik/ignore";
361+
362+
DrawUtilityIgnores(ColoringIgnoreMode, ColoringIgnoresList, ColoringIgnoresPatterns,
363+
title: "Coloring",
364+
modeTooltip: "The mode of operation for preventing certain scenes from having the inline coloring utility.\n\n• Disabled: Nothing will be ignored.\n\n• List: The scenes with GUIDs in the list will not be colored.\n\n• Patterns: The scenes with paths matching the patterns will not be colored.",
365+
listTooltip: "The scenes in this list will not be colored.",
366+
patternsTooltip: $"The scenes with paths matching the patterns in this setting will not be colored.\n\n{patternsSharedTooltip}"
367+
);
368+
369+
if (EditorGUI.EndChangeCheck())
370+
{
371+
ApplyColoringIgnoresPatterns();
372+
shouldSave = true;
373+
}
374+
375+
EditorGUI.BeginChangeCheck();
376+
377+
DrawUtilityIgnores(ToolboxIgnoreMode, ToolboxIgnoresList, ToolboxIgnoresPatterns,
378+
title: "Toolbox",
379+
modeTooltip: "The mode of operation for preventing certain scenes from having the inline toolbox utility.\n\n• Disabled: Nothing will be ignored.\n\n• List: The scenes with GUIDs in the list will not have toolboxes.\n\n• Patterns: The scenes with paths matching the patterns will not have toolboxes.",
380+
listTooltip: "The scenes in this list will not have toolboxes.",
381+
patternsTooltip: $"The scenes with paths matching the patterns in this setting will not have toolboxes.\n\n{patternsSharedTooltip}"
382+
);
383+
384+
if (EditorGUI.EndChangeCheck())
385+
{
386+
ApplyToolboxIgnoresPatterns();
387+
shouldSave = true;
388+
}
389+
390+
if (shouldSave)
391+
{
392+
Settings.Save();
393+
}
394+
}
395+
396+
private static void DrawUtilityIgnores(ProjectSetting<UtilityIgnoreMode> ignoreMode,
397+
ProjectSetting<List<string>> ignoresList,
398+
ProjectSetting<string> ignoresPatterns,
399+
string title,
400+
string modeTooltip,
401+
string listTooltip,
402+
string patternsTooltip)
403+
{
404+
ignoreMode.value = (UtilityIgnoreMode)EditorGUILayout.EnumPopup(new GUIContent($"{title} Ignore Mode", modeTooltip), ignoreMode.value);
405+
406+
switch (ignoreMode.value)
407+
{
408+
case UtilityIgnoreMode.Disabled:
409+
break;
410+
411+
case UtilityIgnoreMode.List:
412+
EditorGUI.BeginChangeCheck();
413+
414+
EditorGUILayout.BeginHorizontal();
415+
416+
EditorGUILayout.LabelField(new GUIContent($"{title} Ignored Scenes", listTooltip));
417+
418+
if (GUILayout.Button("Clear"))
419+
{
420+
ignoresList.value.Clear();
421+
}
422+
423+
if (GUILayout.Button("+"))
424+
{
425+
ignoresList.value.Add(string.Empty);
426+
}
427+
428+
EditorGUILayout.EndHorizontal();
429+
430+
for (var i = 0; i < ignoresList.value.Count; i++)
431+
{
432+
EditorGUILayout.BeginHorizontal();
433+
434+
EditorGUILayout.LabelField(i.ToString(), GUILayout.Width(20));
435+
436+
var guid = ignoresList.value[i];
437+
var obj = AssetDatabase.LoadAssetAtPath<SceneAsset>(AssetDatabase.GUIDToAssetPath(guid));
438+
var sceneAsset = EditorGUILayout.ObjectField(obj, typeof(SceneAsset), false) as SceneAsset;
439+
440+
ignoresList.value[i] = sceneAsset == null
441+
? string.Empty
442+
: AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sceneAsset));
443+
444+
if (GUILayout.Button("-", GUILayout.Width(20)))
445+
{
446+
ignoresList.value.RemoveAt(i);
447+
}
448+
449+
EditorGUILayout.EndHorizontal();
450+
}
451+
452+
if (EditorGUI.EndChangeCheck())
453+
{
454+
ignoresList.value = ignoresList.value.ToList();
455+
}
456+
457+
EditorGUILayout.Separator();
458+
break;
459+
460+
case UtilityIgnoreMode.Patterns:
461+
EditorGUILayout.LabelField(new GUIContent($"{title} Ignore Patterns", patternsTooltip));
462+
ignoresPatterns.value = EditorGUILayout.TextArea(ignoresPatterns.value);
463+
EditorGUILayout.Separator();
464+
break;
465+
466+
default:
467+
throw new ArgumentOutOfRangeException();
468+
}
469+
}
470+
}
209471
}
210472
}

0 commit comments

Comments
 (0)