@@ -147,17 +147,15 @@ public static void UpdateScripts(GameObject go, List<ComponentItem> components,
147
147
{
148
148
if ( viewScript is PanelBase )
149
149
{
150
+ var viewScriptPath = AssetDatabase . GetAssetPath ( viewScript ) ;
151
+ //!!!ViewModelScript需要放置到ViewScript下
152
+ var vmScriptTempPath = viewScriptPath . Replace ( ".cs" , "_ViewModel.cs" ) ;
153
+ var viewModelScript = AssetDatabase . LoadAssetAtPath < MonoScript > ( vmScriptTempPath ) ;
154
+
150
155
var viewModel = ( viewScript as PanelBase ) . ViewModel ;
151
- if ( viewModel is Binding . ViewModelObject && viewModel . GetType ( ) != typeof ( Binding . ViewModelObject ) )
152
- {
153
- GenCodeUtil . UpdateViewModelScript ( viewModel as Binding . ViewModelObject , components ) ;
154
- }
155
- else if ( ( viewModel is Binding . ViewModelContainer ) )
156
+ if ( viewModelScript != null )
156
157
{
157
- var instence = ( viewModel as Binding . ViewModelContainer ) . instence ;
158
- if ( instence != null ) {
159
- GenCodeUtil . UpdateViewModelScript ( instence , components ) ;
160
- }
158
+ GenCodeUtil . UpdateViewModelScript ( viewModelScript , components ) ;
161
159
}
162
160
else
163
161
{
@@ -185,6 +183,7 @@ public static void UpdateScripts(GameObject go, List<ComponentItem> components,
185
183
public static void CompleteKeyField ( string bindingSource , TypeDeclaration classNode )
186
184
{
187
185
var fieldName = GetSourceKeyWord ( bindingSource ) ;
186
+
188
187
var field = classNode . Descendants . OfType < FieldDeclaration > ( ) . Where ( x => x . Variables . Where ( y => y . Name == fieldName ) . Count ( ) > 0 ) . FirstOrDefault ( ) ;
189
188
190
189
if ( field == null )
@@ -334,9 +333,8 @@ public static void CreateNewViewModelScript(string className, string scriptPath,
334
333
/// </summary>
335
334
/// <param name="viewModel"></param>
336
335
/// <param name="components"></param>
337
- public static void UpdateViewModelScript ( Binding . ViewModelObject viewModel , List < ComponentItem > components )
336
+ public static void UpdateViewModelScript ( MonoScript monoScript , List < ComponentItem > components )
338
337
{
339
- var monoScript = MonoScript . FromScriptableObject ( viewModel ) ;
340
338
var classType = monoScript . GetClass ( ) ;
341
339
var baseType = classType . BaseType ;
342
340
var className = classType . Name ;
@@ -360,8 +358,7 @@ private static string GenerateViewModelScript(string className, string oldScript
360
358
{
361
359
startRegion = new PreProcessorDirective ( PreProcessorDirectiveType . Region , "属性列表" ) ;
362
360
AstNode firstMember = classNode . GetChildByRole ( Roles . TypeMemberRole ) ;
363
- if ( firstMember == null )
364
- {
361
+ if ( firstMember == null ) {
365
362
firstMember = classNode . LastChild ;
366
363
}
367
364
classNode . InsertChildBefore < PreProcessorDirective > ( firstMember , startRegion , Roles . PreProcessorDirective ) ;
@@ -377,12 +374,16 @@ private static string GenerateViewModelScript(string className, string oldScript
377
374
#region 处理属性列表
378
375
foreach ( var component in components )
379
376
{
377
+ var flag = BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . GetProperty | BindingFlags . FlattenHierarchy ;
378
+
380
379
foreach ( var viewItem in component . viewItems )
381
380
{
382
381
//忽略已经存在于父级的属性
383
- if ( baseType . GetProperty ( viewItem . bindingSource , BindingFlags . Public | BindingFlags . Instance | BindingFlags . GetProperty | BindingFlags . FlattenHierarchy ) != null )
382
+ if ( baseType . GetProperty ( viewItem . bindingSource , flag ) != null )
384
383
continue ;
385
384
385
+ //Debug.Log(baseType);
386
+
386
387
CompleteKeyField ( viewItem . bindingSource , classNode ) ;
387
388
388
389
if ( viewItem . bindingTargetType . type != null )
@@ -399,7 +400,7 @@ private static string GenerateViewModelScript(string className, string oldScript
399
400
foreach ( var eventItem in component . eventItems )
400
401
{
401
402
//忽略已经存在于父级的属性
402
- if ( baseType . GetProperty ( eventItem . bindingSource , BindingFlags . Public | BindingFlags . Instance | BindingFlags . GetProperty | BindingFlags . FlattenHierarchy ) != null )
403
+ if ( baseType . GetProperty ( eventItem . bindingSource , flag ) != null )
403
404
continue ;
404
405
405
406
CompleteKeyField ( eventItem . bindingSource , classNode ) ;
0 commit comments