Skip to content

Commit 704f3bd

Browse files
committed
fix(UGUICodeGenerator): 添加视图初始化标志防止重复初始化
在InitView方法中添加_isInitView标志位检查,避免UI视图被多次初始化导致潜在问题 #2
1 parent f6ed49c commit 704f3bd

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Editor/UGUICodeGenerator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,16 @@ private static string GenerateCode(GameObject selectedObject, string assetPath)
193193
PropertyCodeHandler(codeBuilder, nodeInfos);
194194

195195
// 生成初始化方法
196+
codeBuilder.AppendLine("\t\tprivate bool _isInitView = false;");
197+
codeBuilder.AppendLine();
196198
codeBuilder.AppendLine("\t\tprotected override void InitView()");
197199
codeBuilder.AppendLine("\t\t{");
200+
codeBuilder.AppendLine("\t\t\tif (_isInitView)");
201+
codeBuilder.AppendLine("\t\t\t{");
202+
codeBuilder.AppendLine("\t\t\t\treturn;");
203+
codeBuilder.AppendLine("\t\t\t}");
204+
codeBuilder.AppendLine();
205+
codeBuilder.AppendLine("\t\t\t_isInitView = true;");
198206
codeBuilder.AppendLine("\t\t\tthis.self = this.gameObject;");
199207
PropertyInitCodeHandler(codeBuilder, nodeInfos);
200208
codeBuilder.AppendLine("\t\t}");

0 commit comments

Comments
 (0)