Skip to content

Commit 5a34268

Browse files
committed
Fixed GetNodeViewTypeFromType not supporting inheritance
1 parent 9a01c6f commit 5a34268

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

Assets/com.alelievr.NodeGraphProcessor/Editor/Utils/NodeProvider.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,28 @@ static MonoScript FindScriptFromClassName(string className)
254254

255255
public static Type GetNodeViewTypeFromType(Type nodeType)
256256
{
257-
Type view;
257+
Type view;
258258

259-
if (nodeViewPerType.TryGetValue(nodeType, out view))
260-
return view;
259+
if (nodeViewPerType.TryGetValue(nodeType, out view))
260+
return view;
261261

262-
// Allow for inheritance in node views: multiple C# node using the same view
263-
foreach (var type in nodeViewPerType)
264-
{
265-
if (nodeType.IsSubclassOf(type.Key))
266-
return type.Value;
267-
}
262+
Type baseType = null;
268263

269-
return view;
270-
}
264+
// Allow for inheritance in node views: multiple C# node using the same view
265+
foreach (var type in nodeViewPerType)
266+
{
267+
// Find a view (not first fitted view) of nodeType
268+
if (nodeType.IsSubclassOf(type.Key) && (baseType == null || type.Value.IsSubclassOf(baseType)))
269+
baseType = type.Value;
270+
}
271+
272+
if (baseType != null)
273+
return baseType;
274+
275+
return view;
276+
}
271277

272-
public static IEnumerable<(string path, Type type)> GetNodeMenuEntries(BaseGraph graph = null)
278+
public static IEnumerable<(string path, Type type)> GetNodeMenuEntries(BaseGraph graph = null)
273279
{
274280
foreach (var node in genericNodes.nodePerMenuTitle)
275281
yield return (node.Key, node.Value);

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
- Renamable nodes
1111
- Added an API in the toolbar view to add separators and custom UI fields.
1212

13+
### Fixed
14+
- Fixed GetNodeViewTypeFromType not supporting inheritance.
15+
1316
## [1.1.2]
1417

1518
### Fixed

0 commit comments

Comments
 (0)