1- using ImGuiNET ;
2- using System . Linq ;
1+ using System . Linq ;
32using System . Reflection ;
43
54namespace Staple . Editor ;
@@ -29,41 +28,38 @@ public override bool RenderField(FieldInfo field)
2928
3029 EditorGUI . Label ( field . Name . ExpandCamelCaseName ( ) ) ;
3130
32- if ( ImGui . TreeNodeEx ( "Parameters" , ImGuiTreeNodeFlags . OpenOnDoubleClick ) )
31+ EditorGUI . TreeNode ( "Parameters" , false , ( ) =>
3332 {
3433 EditorGUI . SameLine ( ) ;
3534
36- if ( EditorGUI . Button ( $ "+## { stateMachine . GetHashCode ( ) + 1 } ") )
35+ if ( EditorGUI . Button ( "+ ") )
3736 {
3837 stateMachine . parameters . Add ( new ( ) ) ;
3938 }
4039
41- ImGui . BeginGroup ( ) ;
42-
43- for ( var i = 0 ; i < stateMachine . parameters . Count ; i ++ )
40+ EditorGUI . Group ( ( ) =>
4441 {
45- var parameter = stateMachine . parameters [ i ] ;
46-
47- parameter . name = EditorGUI . TextField ( $ "Name##{ parameter . GetHashCode ( ) } ", parameter . name ) ;
48-
49- EditorGUI . SameLine ( ) ;
50-
51- if ( EditorGUI . Button ( $ "-##{ parameter . GetHashCode ( ) } ") )
42+ for ( var i = 0 ; i < stateMachine . parameters . Count ; i ++ )
5243 {
53- stateMachine . parameters . RemoveAt ( i ) ;
44+ var parameter = stateMachine . parameters [ i ] ;
5445
55- break ;
56- }
46+ parameter . name = EditorGUI . TextField ( "Name" , parameter . name ) ;
5747
58- parameter . parameterType = EditorGUI . EnumDropdown ( $ "Type##{ parameter . GetHashCode ( ) } ", parameter . parameterType ) ;
59- }
48+ EditorGUI . SameLine ( ) ;
6049
61- ImGui . EndGroup ( ) ;
50+ if ( EditorGUI . Button ( "-" ) )
51+ {
52+ stateMachine . parameters . RemoveAt ( i ) ;
6253
63- ImGui . TreePop ( ) ;
64- }
54+ break ;
55+ }
6556
66- if ( ImGui . TreeNodeEx ( "States" , ImGuiTreeNodeFlags . OpenOnDoubleClick ) )
57+ parameter . parameterType = EditorGUI . EnumDropdown ( "Type" , parameter . parameterType ) ;
58+ }
59+ } ) ;
60+ } ) ;
61+
62+ EditorGUI . TreeNode ( "States" , false , ( ) =>
6763 {
6864 EditorGUI . SameLine ( ) ;
6965
@@ -77,132 +73,124 @@ public override bool RenderField(FieldInfo field)
7773 . Where ( x => x != null )
7874 . ToList ( ) ;
7975
80- ImGui . BeginGroup ( ) ;
81-
82- for ( var i = 0 ; i < stateMachine . states . Count ; i ++ )
76+ EditorGUI . Group ( ( ) =>
8377 {
84- var state = stateMachine . states [ i ] ;
85-
86- var allAvailableStates = stateMachine . states
87- . Select ( x => x . name )
88- . Where ( x => x != null && x != state . name )
89- . ToList ( ) ;
90-
91- state . name = EditorGUI . TextField ( $ "Name##{ state . GetHashCode ( ) } ", state . name ) ;
92-
93- EditorGUI . SameLine ( ) ;
94-
95- if ( EditorGUI . Button ( $ "-##{ state . GetHashCode ( ) } ") )
78+ for ( var i = 0 ; i < stateMachine . states . Count ; i ++ )
9679 {
97- stateMachine . states . RemoveAt ( i ) ;
98-
99- break ;
100- }
80+ var state = stateMachine . states [ i ] ;
10181
102- var currentAnimationIndex = allAnimations . IndexOf ( state . animation ) ;
82+ var allAvailableStates = stateMachine . states
83+ . Select ( x => x . name )
84+ . Where ( x => x != null && x != state . name )
85+ . ToList ( ) ;
10386
104- var newAnimationIndex = EditorGUI . Dropdown ( $ "Animation## { state . GetHashCode ( ) } ", allAnimations . ToArray ( ) , currentAnimationIndex ) ;
87+ state . name = EditorGUI . TextField ( "Name ", state . name ) ;
10588
106- if ( newAnimationIndex != currentAnimationIndex && newAnimationIndex >= 0 )
107- {
108- state . animation = allAnimations [ newAnimationIndex ] ;
109- }
110-
111- state . repeat = EditorGUI . Toggle ( $ "Repeat##{ state . GetHashCode ( ) } ", state . repeat ) ;
112-
113- if ( ImGui . TreeNodeEx ( $ "Connections##{ state . GetHashCode ( ) } ", ImGuiTreeNodeFlags . OpenOnDoubleClick ) )
114- {
11589 EditorGUI . SameLine ( ) ;
11690
117- if ( EditorGUI . Button ( $ "+## { state . GetHashCode ( ) + 1 } ") )
91+ if ( EditorGUI . Button ( $ "- ") )
11892 {
119- state . connections . Add ( new ( ) ) ;
93+ stateMachine . states . RemoveAt ( i ) ;
94+
95+ break ;
12096 }
12197
122- ImGui . BeginGroup ( ) ;
98+ var currentAnimationIndex = allAnimations . IndexOf ( state . animation ) ;
12399
124- for ( var j = 0 ; j < state . connections . Count ; j ++ )
100+ var newAnimationIndex = EditorGUI . Dropdown ( "Animation" , allAnimations . ToArray ( ) , currentAnimationIndex ) ;
101+
102+ if ( newAnimationIndex != currentAnimationIndex && newAnimationIndex >= 0 )
125103 {
126- var connection = state . connections [ j ] ;
104+ state . animation = allAnimations [ newAnimationIndex ] ;
105+ }
127106
128- var currentStateIndex = allAvailableStates . IndexOf ( connection . name ) ;
107+ state . repeat = EditorGUI . Toggle ( "Repeat" , state . repeat ) ;
129108
130- var newStateIndex = EditorGUI . Dropdown ( $ "Transition to##{ connection . GetHashCode ( ) } ", allAvailableStates . ToArray ( ) , currentStateIndex ) ;
109+ EditorGUI . TreeNode ( "Connections" , false , ( ) =>
110+ {
111+ EditorGUI . SameLine ( ) ;
131112
132- if ( newStateIndex != currentStateIndex && newStateIndex >= 0 && newStateIndex < allAvailableStates . Count )
113+ if ( EditorGUI . Button ( "+" ) )
133114 {
134- connection . name = allAvailableStates [ newStateIndex ] ;
115+ state . connections . Add ( new ( ) ) ;
135116 }
136117
137- connection . any = EditorGUI . Toggle ( $ "Trigger on any##{ connection . GetHashCode ( ) } ", connection . any ) ;
138-
139- connection . onFinish = EditorGUI . Toggle ( $ "Trigger on finish##{ connection . GetHashCode ( ) } ", connection . onFinish ) ;
140-
141- if ( ImGui . TreeNodeEx ( $ "Conditions##{ connection . GetHashCode ( ) } ", ImGuiTreeNodeFlags . OpenOnDoubleClick ) )
118+ EditorGUI . Group ( ( ) =>
142119 {
143- EditorGUI . SameLine ( ) ;
144-
145- if ( EditorGUI . Button ( $ "+##{ connection . GetHashCode ( ) } ") )
120+ for ( var j = 0 ; j < state . connections . Count ; j ++ )
146121 {
147- connection . parameters . Add ( new ( ) ) ;
148- }
122+ var connection = state . connections [ j ] ;
149123
150- for ( var k = 0 ; k < connection . parameters . Count ; k ++ )
151- {
152- var parameter = connection . parameters [ k ] ;
153-
154- var currentNameIndex = allAvailableParameters . IndexOf ( parameter . name ) ;
124+ var currentStateIndex = allAvailableStates . IndexOf ( connection . name ) ;
155125
156- var newNameIndex = EditorGUI . Dropdown ( $ "Name## { parameter . GetHashCode ( ) } ", allAvailableParameters . ToArray ( ) , currentNameIndex ) ;
126+ var newStateIndex = EditorGUI . Dropdown ( "Transition to ", allAvailableStates . ToArray ( ) , currentStateIndex ) ;
157127
158- if ( newNameIndex != currentNameIndex && newNameIndex >= 0 && newNameIndex < allAvailableParameters . Count )
128+ if ( newStateIndex != currentStateIndex && newStateIndex >= 0 && newStateIndex < allAvailableStates . Count )
159129 {
160- parameter . name = allAvailableParameters [ newNameIndex ] ;
130+ connection . name = allAvailableStates [ newStateIndex ] ;
161131 }
162132
163- parameter . condition = EditorGUI . EnumDropdown ( $ "Condition## { parameter . GetHashCode ( ) } ", parameter . condition ) ;
133+ connection . any = EditorGUI . Toggle ( "Trigger on any ", connection . any ) ;
164134
165- var existingParameter = stateMachine . parameters . FirstOrDefault ( x => x . name == parameter . name ) ;
135+ connection . onFinish = EditorGUI . Toggle ( "Trigger on finish" , connection . onFinish ) ;
166136
167- if ( existingParameter != null )
137+ EditorGUI . TreeNode ( "Conditions" , false , ( ) =>
168138 {
169- switch ( existingParameter . parameterType )
139+ EditorGUI . SameLine ( ) ;
140+
141+ if ( EditorGUI . Button ( "+" ) )
170142 {
171- case SkinnedAnimationStateMachine . AnimationParameterType . Bool :
143+ connection . parameters . Add ( new ( ) ) ;
144+ }
172145
173- parameter . boolValue = EditorGUI . Toggle ( $ "Value##{ parameter . GetHashCode ( ) } ", parameter . boolValue ) ;
146+ for ( var k = 0 ; k < connection . parameters . Count ; k ++ )
147+ {
148+ var parameter = connection . parameters [ k ] ;
174149
175- break ;
150+ var currentNameIndex = allAvailableParameters . IndexOf ( parameter . name ) ;
176151
177- case SkinnedAnimationStateMachine . AnimationParameterType . Float :
152+ var newNameIndex = EditorGUI . Dropdown ( "Name" , allAvailableParameters . ToArray ( ) , currentNameIndex ) ;
178153
179- parameter . floatValue = EditorGUI . FloatField ( $ "Value##{ parameter . GetHashCode ( ) } ", parameter . floatValue ) ;
154+ if ( newNameIndex != currentNameIndex && newNameIndex >= 0 && newNameIndex < allAvailableParameters . Count )
155+ {
156+ parameter . name = allAvailableParameters [ newNameIndex ] ;
157+ }
180158
181- break ;
159+ parameter . condition = EditorGUI . EnumDropdown ( "Condition" , parameter . condition ) ;
182160
183- case SkinnedAnimationStateMachine . AnimationParameterType . Int :
161+ var existingParameter = stateMachine . parameters . FirstOrDefault ( x => x . name == parameter . name ) ;
184162
185- parameter . intValue = EditorGUI . IntField ( $ "Value##{ parameter . GetHashCode ( ) } ", parameter . intValue ) ;
163+ if ( existingParameter != null )
164+ {
165+ switch ( existingParameter . parameterType )
166+ {
167+ case SkinnedAnimationStateMachine . AnimationParameterType . Bool :
186168
187- break ;
188- }
189- }
190- }
169+ parameter . boolValue = EditorGUI . Toggle ( "Value" , parameter . boolValue ) ;
191170
192- ImGui . TreePop ( ) ;
193- }
194- }
171+ break ;
195172
196- ImGui . EndGroup ( ) ;
173+ case SkinnedAnimationStateMachine . AnimationParameterType . Float :
197174
198- ImGui . TreePop ( ) ;
199- }
200- }
175+ parameter . floatValue = EditorGUI . FloatField ( "Value" , parameter . floatValue ) ;
201176
202- ImGui . EndGroup ( ) ;
177+ break ;
203178
204- ImGui . TreePop ( ) ;
205- }
179+ case SkinnedAnimationStateMachine . AnimationParameterType . Int :
180+
181+ parameter . intValue = EditorGUI . IntField ( "Value" , parameter . intValue ) ;
182+
183+ break ;
184+ }
185+ }
186+ }
187+ } ) ;
188+ }
189+ } ) ;
190+ } ) ;
191+ }
192+ } ) ;
193+ } ) ;
206194
207195 break ;
208196 }
0 commit comments