Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 29565e9

Browse files
Implemnted more robust way of looking for PropertyDrawers
1 parent 650c66f commit 29565e9

1 file changed

Lines changed: 54 additions & 16 deletions

File tree

Assets/SO Architecture/Editor/SOArchitecture_EditorUtility.cs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System.IO;
2+
using System.Reflection;
23
using System.Collections.Generic;
34
using UnityEngine;
45
using UnityEditor;
@@ -11,9 +12,6 @@ public static class SOArchitecture_EditorUtility
1112
{
1213
static SOArchitecture_EditorUtility()
1314
{
14-
//We use this as a default since it'll be Assembly-CSharp-Editor
15-
_defaultTargetType = typeof(SOArchitecture_EditorUtility).Assembly;
16-
1715
CreateDebugStyle();
1816
}
1917

@@ -22,11 +20,60 @@ static SOArchitecture_EditorUtility()
2220
/// </summary>
2321
public static GUIStyle DebugStyle { get; private set; }
2422
private const float DebugStyleBackgroundAlpha = 0.33f;
25-
23+
2624
private static PropertyDrawerGraph _propertyDrawerGraph;
27-
private static Assembly _defaultTargetType;
2825
private static BindingFlags _fieldBindingsFlag = BindingFlags.Instance | BindingFlags.NonPublic;
26+
27+
private class AssemblyDefinitionSurrogate
28+
{
29+
public string name = "";
30+
}
31+
32+
private static void CreatePropertyDrawerGraph()
33+
{
34+
_propertyDrawerGraph = new PropertyDrawerGraph();
35+
HashSet<string> assemblyNamesToCheck = new HashSet<string>()
36+
{
37+
"Assembly-CSharp-Editor",
38+
};
39+
40+
GetAllAssetDefintionNames(assemblyNamesToCheck);
41+
42+
string dataPath = Application.dataPath;
43+
string libraryPath = dataPath.Substring(0, dataPath.LastIndexOf('/')) + "/Library/ScriptAssemblies";
44+
45+
foreach (string file in Directory.GetFiles(libraryPath))
46+
{
47+
if(assemblyNamesToCheck.Contains(Path.GetFileNameWithoutExtension(file)) && Path.GetExtension(file) == ".dll")
48+
{
49+
Assembly assembly = Assembly.LoadFrom(file);
50+
_propertyDrawerGraph.CreateGraph(assembly);
51+
}
52+
}
53+
}
54+
private static void GetAllAssetDefintionNames(HashSet<string> targetList)
55+
{
56+
string[] assemblyDefinitionGUIDs = AssetDatabase.FindAssets("t:asmdef");
57+
58+
foreach (string guid in assemblyDefinitionGUIDs)
59+
{
60+
string path = AssetDatabase.GUIDToAssetPath(guid);
61+
62+
if (path.StartsWith("Assets/"))
63+
{
64+
string fullPath = Application.dataPath + path.Remove(0, path.IndexOf('/'));
65+
66+
targetList.Add(GetNameValueFromAssemblyDefinition(fullPath));
67+
}
68+
}
69+
}
70+
private static string GetNameValueFromAssemblyDefinition(string fullpath)
71+
{
72+
string allText = File.ReadAllText(fullpath);
73+
AssemblyDefinitionSurrogate surrogate = JsonUtility.FromJson<AssemblyDefinitionSurrogate>(allText);
2974

75+
return surrogate.name;
76+
}
3077
private static void CreateDebugStyle()
3178
{
3279
DebugStyle = new GUIStyle();
@@ -53,17 +100,8 @@ public static bool SupportsMultiLine(Type type)
53100
}
54101
public static bool HasPropertyDrawer(Type type)
55102
{
56-
return HasPropertyDrawer(type, _defaultTargetType);
57-
}
58-
public static bool HasPropertyDrawer(Type type, Assembly assembly)
59-
{
60-
if (HasBuiltinPropertyDrawer(type))
61-
return true;
62-
63103
if (_propertyDrawerGraph == null)
64-
_propertyDrawerGraph = new PropertyDrawerGraph();
65-
66-
_propertyDrawerGraph.CreateGraph(assembly);
104+
CreatePropertyDrawerGraph();
67105

68106
return _propertyDrawerGraph.HasPropertyDrawer(type);
69107
}

0 commit comments

Comments
 (0)