mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Added support for usage from a DLL #23
This commit is contained in:
parent
aa04de9870
commit
6d6a6abd9e
@ -11,9 +11,11 @@ namespace XNodeEditor {
|
|||||||
public partial class NodeEditorWindow {
|
public partial class NodeEditorWindow {
|
||||||
/// <summary> Custom node tint colors defined with [NodeColor(r, g, b)] </summary>
|
/// <summary> Custom node tint colors defined with [NodeColor(r, g, b)] </summary>
|
||||||
public static Dictionary<Type, Color> nodeTint { get { return _nodeTint != null ? _nodeTint : _nodeTint = GetNodeTint(); } }
|
public static Dictionary<Type, Color> nodeTint { get { return _nodeTint != null ? _nodeTint : _nodeTint = GetNodeTint(); } }
|
||||||
|
|
||||||
[NonSerialized] private static Dictionary<Type, Color> _nodeTint;
|
[NonSerialized] private static Dictionary<Type, Color> _nodeTint;
|
||||||
/// <summary> All available node types </summary>
|
/// <summary> All available node types </summary>
|
||||||
public static Type[] nodeTypes { get { return _nodeTypes != null ? _nodeTypes : _nodeTypes = GetNodeTypes(); } }
|
public static Type[] nodeTypes { get { return _nodeTypes != null ? _nodeTypes : _nodeTypes = GetNodeTypes(); } }
|
||||||
|
|
||||||
[NonSerialized] private static Type[] _nodeTypes = null;
|
[NonSerialized] private static Type[] _nodeTypes = null;
|
||||||
|
|
||||||
public static Type[] GetNodeTypes() {
|
public static Type[] GetNodeTypes() {
|
||||||
@ -32,13 +34,14 @@ namespace XNodeEditor {
|
|||||||
return tints;
|
return tints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Get all classes deriving from baseType via reflection </summary>
|
||||||
public static Type[] GetDerivedTypes(Type baseType) {
|
public static Type[] GetDerivedTypes(Type baseType) {
|
||||||
//Get all classes deriving from baseType via reflection
|
List<System.Type> types = new List<System.Type>();
|
||||||
Assembly assembly = Assembly.GetAssembly(baseType);
|
System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
|
||||||
return assembly.GetTypes().Where(t =>
|
foreach (Assembly assembly in assemblies) {
|
||||||
!t.IsAbstract &&
|
types.AddRange(assembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)).ToArray());
|
||||||
baseType.IsAssignableFrom(t)
|
}
|
||||||
).ToArray();
|
return types.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static object ObjectFromType(Type type) {
|
public static object ObjectFromType(Type type) {
|
||||||
@ -71,10 +74,10 @@ namespace XNodeEditor {
|
|||||||
kvp.Add(new KeyValuePair<ContextMenu, MethodInfo>(attribs[k], methods[i]));
|
kvp.Add(new KeyValuePair<ContextMenu, MethodInfo>(attribs[k], methods[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if UNITY_5_5_OR_NEWER
|
#if UNITY_5_5_OR_NEWER
|
||||||
//Sort menu items
|
//Sort menu items
|
||||||
kvp.Sort((x, y) => x.Key.priority.CompareTo(y.Key.priority));
|
kvp.Sort((x, y) => x.Key.priority.CompareTo(y.Key.priority));
|
||||||
#endif
|
#endif
|
||||||
return kvp.ToArray();
|
return kvp.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,13 +46,19 @@ namespace XNode {
|
|||||||
private static void BuildCache() {
|
private static void BuildCache() {
|
||||||
portDataCache = new PortDataCache();
|
portDataCache = new PortDataCache();
|
||||||
System.Type baseType = typeof(Node);
|
System.Type baseType = typeof(Node);
|
||||||
Assembly assembly = Assembly.GetAssembly(baseType);
|
List<System.Type> nodeTypes = new List<System.Type>();
|
||||||
System.Type[] nodeTypes = assembly.GetTypes().Where(t =>
|
System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
|
||||||
!t.IsAbstract &&
|
Assembly selfAssembly = Assembly.GetAssembly(baseType);
|
||||||
baseType.IsAssignableFrom(t)
|
if (selfAssembly.FullName.StartsWith("Assembly-CSharp")) {
|
||||||
).ToArray();
|
// If xNode is not used as a DLL, check only CSharp (fast)
|
||||||
|
nodeTypes.AddRange(selfAssembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)));
|
||||||
for (int i = 0; i < nodeTypes.Length; i++) {
|
} else {
|
||||||
|
// Else, check all DDLs (slow)
|
||||||
|
foreach (Assembly assembly in assemblies) {
|
||||||
|
nodeTypes.AddRange(assembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)).ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < nodeTypes.Count; i++) {
|
||||||
CachePorts(nodeTypes[i]);
|
CachePorts(nodeTypes[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user