Skip to content

Commit e711ab4

Browse files
committed
CreateInWizard attribute that allows to filter out valid ScriptableObjects in the ScriptableObjectCreationWizard; minor improvements and refactor changes
1 parent db1b172 commit e711ab4

File tree

179 files changed

+169
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+169
-10
lines changed

Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Toolbox.Editor
99
{
10-
using Toolbox.Attributes;
10+
using Toolbox.Attributes.Property;
1111
using Toolbox.Editor.Drawers;
1212

1313
/// <summary>
@@ -90,7 +90,6 @@ internal class ToolboxPropertyHandler
9090
/// </summary>
9191
private ILabelProcessorAttribute labelProcessorAttribute;
9292

93-
9493
/// <summary>
9594
/// Constructor prepares all property-related data for custom drawing.
9695
/// </summary>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using UnityEditor;
5+
6+
namespace Toolbox.Editor
7+
{
8+
[InitializeOnLoad]
9+
public static class AssemblyUtilities
10+
{
11+
private static readonly HashSet<string> projectAssemblyNames = new HashSet<string>();
12+
private static readonly HashSet<string> internalAssemblyNames = new HashSet<string>()
13+
{
14+
"Bee.BeeDriver",
15+
"ExCSS.Unity",
16+
"Mono.Security",
17+
"mscorlib",
18+
"netstandard",
19+
"Newtonsoft.Json",
20+
"nunit.framework",
21+
"ReportGeneratorMerged",
22+
"Unrelated",
23+
"SyntaxTree.VisualStudio.Unity.Bridge",
24+
"SyntaxTree.VisualStudio.Unity.Messaging",
25+
};
26+
27+
private static bool isCached;
28+
29+
static AssemblyUtilities()
30+
{
31+
isCached = false;
32+
}
33+
34+
private static void CacheProjectAssemblies()
35+
{
36+
projectAssemblyNames.Clear();
37+
var appDomain = AppDomain.CurrentDomain;
38+
foreach (var assembly in appDomain.GetAssemblies())
39+
{
40+
if (assembly.IsDynamic)
41+
{
42+
continue;
43+
}
44+
45+
var assemblyName = assembly.GetName().Name;
46+
if (assemblyName.StartsWith("System") ||
47+
assemblyName.StartsWith("Unity") ||
48+
assemblyName.StartsWith("UnityEditor") ||
49+
assemblyName.StartsWith("UnityEngine") ||
50+
internalAssemblyNames.Contains(assemblyName))
51+
{
52+
continue;
53+
}
54+
55+
projectAssemblyNames.Add(assembly.FullName);
56+
}
57+
}
58+
59+
public static bool IsProjectAssembly(Assembly assembly)
60+
{
61+
if (assembly == null)
62+
{
63+
return false;
64+
}
65+
66+
return IsProjectAssembly(assembly.FullName);
67+
}
68+
69+
public static bool IsProjectAssembly(string assemblyName)
70+
{
71+
return ProjectAssemblyNames.Contains(assemblyName);
72+
}
73+
74+
public static HashSet<string> ProjectAssemblyNames
75+
{
76+
get
77+
{
78+
if (!isCached)
79+
{
80+
CacheProjectAssemblies();
81+
isCached = true;
82+
}
83+
84+
return projectAssemblyNames;
85+
}
86+
}
87+
}
88+
}

Assets/Editor Toolbox/Editor/Utilities/AssemblyUtilities.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.

Assets/Editor Toolbox/Editor/Utilities/TypeUtilities.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ public static class TypeUtilities
1515
internal static readonly Dictionary<int, TypesEditorCollection> editorCollections = new Dictionary<int, TypesEditorCollection>();
1616
internal static readonly Dictionary<string, Type> referenceTypesByNames = new Dictionary<string, Type>();
1717

18-
1918
internal static void ClearCache()
2019
{
2120
cachedCollections.Clear();
2221
editorCollections.Clear();
2322
referenceTypesByNames.Clear();
2423
}
2524

26-
2725
public static TypesCachedCollection GetCollection(Type parentType)
2826
{
2927
return GetCollection(new TypeConstraintContext(parentType));

Assets/Editor Toolbox/Editor/Wizards/ScriptableObjectCreationWizard.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace Toolbox.Editor.Wizards
1010
{
11+
using Toolbox.Attributes;
1112
using Toolbox.Editor.Internal;
13+
1214
using Editor = UnityEditor.Editor;
1315

1416
/// <summary>
@@ -26,7 +28,9 @@ public TypeConstraintScriptableObject() : base(typeof(ScriptableObject), TypeSet
2628

2729
public override bool IsSatisfied(Type type)
2830
{
29-
return Attribute.IsDefined(type, typeof(CreateAssetMenuAttribute)) && base.IsSatisfied(type);
31+
return AssemblyUtilities.IsProjectAssembly(type.Assembly) &&
32+
(Attribute.IsDefined(type, typeof(CreateInWizardAttribute)) || Attribute.IsDefined(type, typeof(CreateAssetMenuAttribute))) &&
33+
base.IsSatisfied(type);
3034
}
3135
}
3236

Assets/Editor Toolbox/README.md

Lines changed: 2 additions & 0 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace Toolbox.Attributes
5+
{
6+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
7+
[Conditional("UNITY_EDITOR")]
8+
public class CreateInWizardAttribute : Attribute
9+
{ }
10+
}

Assets/Editor Toolbox/Runtime/Attributes/CreateInWizardAttribute.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.

Assets/Editor Toolbox/Runtime/Attributes/Property.meta

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

Assets/Editor Toolbox/Runtime/Attributes/ILabelProcessorAttribute.cs renamed to Assets/Editor Toolbox/Runtime/Attributes/Property/ILabelProcessorAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Toolbox.Attributes
1+
namespace Toolbox.Attributes.Property
22
{
33
/// <summary>
44
/// Temporary interface used to wrap all attributes used to override property labels.

0 commit comments

Comments
 (0)