1
1
using System ;
2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
+ using System . Linq ;
4
5
using UnityEditor ;
5
6
using UnityEngine ;
6
7
using XNode ;
@@ -16,19 +17,21 @@ public class MovesetGraphEditor : NodeGraphEditor
16
17
private GUIStyle titleStyle ;
17
18
private Rect titleRect ;
18
19
private int windowPadding = 20 ;
19
-
20
+
20
21
public override string GetNodeMenuName ( System . Type type )
21
22
{
22
23
if ( type . Namespace != null && type . Namespace . StartsWith ( "NASB_Moveset_Editor" ) )
23
24
{
25
+ if ( Consts . NodesToIgnore . Contains ( type . Name ) ) return null ;
26
+
24
27
string nodeMenuName = base . GetNodeMenuName ( type ) . Replace ( "NASB_Moveset_Editor/" , "" ) ;
25
28
26
29
// Organize State Action nodes
27
30
if ( nodeMenuName . Contains ( "State Actions/" ) )
28
- {
31
+ {
29
32
string nodeName = nodeMenuName . Substring ( "State Actions/" . Length ) ;
30
33
if ( nodeName . StartsWith ( "SA" ) )
31
- {
34
+ {
32
35
string nameWithoutSA = nodeName . Substring ( "SA" . Length ) . Trim ( ) ;
33
36
int alphaComp = string . Compare ( nameWithoutSA , "N" ) ;
34
37
if ( alphaComp < 1 )
@@ -43,9 +46,9 @@ public override string GetNodeMenuName(System.Type type)
43
46
else return null ;
44
47
}
45
48
46
- public override void OnCreate ( )
47
- {
48
- base . OnCreate ( ) ;
49
+ public override void OnCreate ( )
50
+ {
51
+ base . OnCreate ( ) ;
49
52
window . titleContent = new GUIContent ( Consts . PROJECT_NAME ) ;
50
53
51
54
titleStyle = new GUIStyle ( ) ;
@@ -55,9 +58,9 @@ public override void OnCreate()
55
58
titleRect = new Rect ( windowPadding , windowPadding , window . position . width - windowPadding , window . position . height - windowPadding ) ;
56
59
}
57
60
58
- public override void OnOpen ( )
59
- {
60
- base . OnOpen ( ) ;
61
+ public override void OnOpen ( )
62
+ {
63
+ base . OnOpen ( ) ;
61
64
62
65
SetupInsetGraphName ( ) ;
63
66
}
@@ -70,15 +73,15 @@ public override void OnWindowFocus()
70
73
}
71
74
72
75
public override void OnGUI ( )
73
- {
74
- base . OnGUI ( ) ;
76
+ {
77
+ base . OnGUI ( ) ;
75
78
76
79
GUILayout . BeginArea ( titleRect ) ;
77
80
EditorGUILayout . LabelField ( graphParentName , titleStyle ) ;
78
81
EditorGUILayout . Space ( windowPadding * 0.66f ) ;
79
82
EditorGUILayout . LabelField ( graphSubName , titleStyle ) ;
80
83
GUILayout . EndArea ( ) ;
81
- }
84
+ }
82
85
83
86
public override NodeEditorPreferences . Settings GetDefaultPreferences ( )
84
87
{
@@ -92,24 +95,70 @@ public override NodeEditorPreferences.Settings GetDefaultPreferences()
92
95
}
93
96
94
97
private void SetupInsetGraphName ( )
95
- {
98
+ {
96
99
string graphPath = AssetDatabase . GetAssetPath ( base . serializedObject . targetObject ) ;
97
100
98
101
try
99
- {
102
+ {
100
103
graphPath = graphPath . Substring ( graphPath . IndexOf ( $ "{ Consts . GRAPH_FOLDER_NAME } ") + Consts . GRAPH_FOLDER_NAME . Length + 1 ) ;
101
104
graphPath = graphPath . Substring ( 0 , graphPath . Length - ".asset" . Length ) ;
102
105
graphParentName = graphPath . Substring ( 0 , graphPath . IndexOf ( "/" ) ) ;
103
106
graphSubName = graphPath . Substring ( graphParentName . Length + 1 ) ;
104
107
} catch
105
- {
108
+ {
106
109
graphParentName = graphPath ;
107
110
}
108
111
}
109
112
110
113
public override void AddContextMenuItems ( GenericMenu menu , Type compatibleType = null , NodePort . IO direction = NodePort . IO . Input )
111
114
{
112
- base . AddContextMenuItems ( menu , compatibleType , direction ) ;
115
+ Vector2 pos = NodeEditorWindow . current . WindowToGridPosition ( Event . current . mousePosition ) ;
116
+
117
+ if ( compatibleType != null )
118
+ {
119
+ Type [ ] nodeTypes ;
120
+
121
+ // If this is a list, get the type of the item in the list, then find nodes that have inputs for that type
122
+ if ( typeof ( IEnumerable ) . IsAssignableFrom ( compatibleType ) && compatibleType != typeof ( string ) )
123
+ {
124
+ Type subType = Type . GetType ( compatibleType . GenericTypeArguments [ 0 ] . AssemblyQualifiedName ) ;
125
+ nodeTypes = NodeEditorUtilities . GetCompatibleNodesTypes ( NodeEditorReflection . nodeTypes , subType , direction ) . OrderBy ( GetNodeMenuOrder ) . ToArray ( ) ;
126
+ }
127
+ else if ( NodeEditorPreferences . GetSettings ( ) . createFilter )
128
+ {
129
+ nodeTypes = NodeEditorUtilities . GetCompatibleNodesTypes ( NodeEditorReflection . nodeTypes , compatibleType , direction ) . OrderBy ( GetNodeMenuOrder ) . ToArray ( ) ;
130
+ }
131
+ else
132
+ {
133
+ nodeTypes = NodeEditorReflection . nodeTypes . OrderBy ( GetNodeMenuOrder ) . ToArray ( ) ;
134
+ }
135
+
136
+ for ( int i = 0 ; i < nodeTypes . Length ; i ++ )
137
+ {
138
+ Type type = nodeTypes [ i ] ;
139
+
140
+ //Get node context menu path
141
+ string path = GetNodeMenuName ( type ) ;
142
+ if ( string . IsNullOrEmpty ( path ) ) continue ;
143
+
144
+ // Check if user is allowed to add more of given node type
145
+ XNode . Node . DisallowMultipleNodesAttribute disallowAttrib ;
146
+ bool disallowed = false ;
147
+ if ( NodeEditorUtilities . GetAttrib ( type , out disallowAttrib ) )
148
+ {
149
+ int typeCount = target . nodes . Count ( x => x . GetType ( ) == type ) ;
150
+ if ( typeCount >= disallowAttrib . max ) disallowed = true ;
151
+ }
152
+
153
+ // Add node entry to context menu
154
+ if ( disallowed ) menu . AddItem ( new GUIContent ( path ) , false , null ) ;
155
+ else menu . AddItem ( new GUIContent ( path ) , false , ( ) => {
156
+ XNode . Node node = CreateNode ( type , pos ) ;
157
+ NodeEditorWindow . current . AutoConnect ( node ) ;
158
+ } ) ;
159
+ }
160
+ }
161
+ base . AddContextMenuItems ( menu , compatibleType , direction ) ;
113
162
menu . AddSeparator ( "" ) ;
114
163
menu . AddItem ( new GUIContent ( "Organize Graph" ) , false , ( ) => GraphHandler . CheckOrganizeGraph ( ) ) ;
115
164
}
0 commit comments