/// <summary> /// 写Lua的点击方法 /// </summary> /// <returns></returns> private StringBuilder WriteLuaMethod() { List <UICompleteEnum> listUI = GenUIUtils.UIComponentList(this.BuildSelectUIList()); StringBuilder methodBuilder = new StringBuilder(); for (int i = 0; i < listUI.Count; i++) { string name = this.variableNameList[i]; switch (listUI[i]) { case UICompleteEnum.Button: methodBuilder.AppendFormat(UICodeConfig.luaClickEvent, this.className, name); break; case UICompleteEnum.Toggle: case UICompleteEnum.Slider: case UICompleteEnum.Scrollbar: case UICompleteEnum.InputField: case UICompleteEnum.ScrollRect: case UICompleteEnum.Dropdown: methodBuilder.AppendFormat(UICodeConfig.luaValueChangedEvent, this.className, name); break; default: break; } } methodBuilder.Append(UICodeConfig.classEnd); return(methodBuilder); }
/// <summary> /// 写变量的查找赋值 /// </summary> private StringBuilder WriteVariableValueCode() { Dictionary <Transform, string> dic = GenUIUtils.GetChildrenPaths(this.selectedObj.gameObject); List <UICompleteEnum> listUI = GenUIUtils.UIComponentList(this.BuildSelectUIList()); StringBuilder pathBuilder = new StringBuilder(); List <UIBehaviour> list = GenUIUtils.SelectAllUIComponent(this.BuildSelectUIList()); string temp = string.Empty; if (this.isCSCode) { pathBuilder.Append(UICodeConfig.ActionMgrStr); pathBuilder.Append(UICodeConfig.startName); temp = UICodeConfig.uiPath; } else { pathBuilder.AppendFormat(UICodeConfig.luaClassName, this.className); temp = UICodeConfig.luaVariable; } for (int i = 0; i < list.Count; i++) { string name = this.variableNameList[i]; pathBuilder.AppendFormat(temp, name, dic[list[i].transform], UICodeConfig.uiComponentName[(int)listUI[i]]); } if (this.isCSCode) { pathBuilder.Append(UICodeConfig.addEventMethod); pathBuilder.Append(UICodeConfig.end); } else { pathBuilder.Append(UICodeConfig.luaAddEventMethod); pathBuilder.Append(UICodeConfig.luaEnd); } if (this.isCSCode) { pathBuilder.Append(UICodeConfig.InitName); pathBuilder.Append(UICodeConfig.ShowName); pathBuilder.Append(UICodeConfig.HideName); } if (this.isCSCode) { pathBuilder.Append(UICodeConfig.OnAnyBtnClickName); } return(pathBuilder); }
/// <summary> /// 写事件的注册 /// </summary> private StringBuilder WriteAddMethodListenerCode() { StringBuilder methodListenerdBuilder = new StringBuilder(); List <UICompleteEnum> listUI = GenUIUtils.UIComponentList(this.BuildSelectUIList()); string temp1 = string.Empty; string temp2 = string.Empty; if (this.isCSCode) { methodListenerdBuilder.Append(UICodeConfig.addEventName); temp1 = UICodeConfig.btnListenerName; temp2 = UICodeConfig.valueChangedName; } else { methodListenerdBuilder.AppendFormat(UICodeConfig.luaAddEvent, this.className); temp1 = UICodeConfig.luaEventAdd; temp2 = UICodeConfig.luaEventChanged; } for (int i = 0; i < listUI.Count; i++) { string name = this.variableNameList[i]; switch (listUI[i]) { case UICompleteEnum.Button: methodListenerdBuilder.AppendFormat(temp1, name, name); break; case UICompleteEnum.Toggle: case UICompleteEnum.Slider: case UICompleteEnum.Scrollbar: case UICompleteEnum.InputField: methodListenerdBuilder.AppendFormat(temp2, name, name); break; default: break; } } if (this.isCSCode) { methodListenerdBuilder.Append(UICodeConfig.methodEnd); } else { methodListenerdBuilder.Append(UICodeConfig.luaEnd); } return(methodListenerdBuilder); }
private void AddChildItem() { List <TreeViewItem> rows = new List <TreeViewItem>(); if (this.parentTransform != null) { GameObject[] transforms = GenUIUtils.GetAllUIChild(this.parentTransform.gameObject); for (int i = 0; i < transforms.Length; i++) { PrefabsTreeItem item = this.CreateItem(transforms[i].transform, i); rows.Add(item); this.SetExpanded(i, true); } } this.listItem = rows; }
/// <summary> /// 写点击的方法 /// </summary> private StringBuilder WriteCSMethodCode() { List <UICompleteEnum> listUI = GenUIUtils.UIComponentList(this.BuildSelectUIList()); StringBuilder methodBuilder = new StringBuilder(); for (int i = 0; i < listUI.Count; i++) { string name = this.variableNameList[i]; switch (listUI[i]) { case UICompleteEnum.Button: methodBuilder.AppendFormat(UICodeConfig.onBtnClickName, name, name); break; case UICompleteEnum.Toggle: methodBuilder.AppendFormat(UICodeConfig.onValueChangedName, name, "bool"); break; case UICompleteEnum.Slider: case UICompleteEnum.Scrollbar: methodBuilder.AppendFormat(UICodeConfig.onValueChangedName, name, "float"); break; case UICompleteEnum.InputField: methodBuilder.AppendFormat(UICodeConfig.onValueChangedName, name, "string"); break; case UICompleteEnum.ScrollRect: methodBuilder.AppendFormat(UICodeConfig.onValueChangedName, name, "Vector2"); break; case UICompleteEnum.Dropdown: methodBuilder.AppendFormat(UICodeConfig.onValueChangedName, name, "int"); break; default: break; } } methodBuilder.Append(UICodeConfig.classEnd); methodBuilder.Append(UICodeConfig.namespaceRegionEnd); return(methodBuilder); }
/// <summary> /// 绘制预设包含的UI组件 /// </summary> private void DrawUIEles() { if (this.selectedObj != null) { GameObject[] rects = GenUIUtils.GetAllUIChild(this.selectedObj.gameObject); if (treeViews == null) { treeViews = new PrefabsTreeViews(treeViewState); if (this.uiCompleteList == null) { this.uiCompleteList = new List <GameObject>(); } } this.treeViews.ParentTransform = this.selectedObj; this.treeViews.Reload(); this.treeViews.OnGUI(new Rect(0, 50, 300, 500)); this.UpdateUIDict(rects); } }
/// <summary> /// 写C#的变量命名 /// </summary> /// <param name="list"></param> private StringBuilder WriteVariableCode(List <UICompleteEnum> list) { StringBuilder variableBuilder = new StringBuilder(); if (list != null) { if (this.variableNameList == null) { this.variableNameList = new List <string>(); } this.variableNameList.Clear(); this.variableNameList = GenUIUtils.UINameList(GenUIUtils.SelectAllUIComponent(this.BuildSelectUIList())); for (int i = 0; i < list.Count; i++) { string name = this.variableNameList[i] + "_" + UICodeConfig.uiVariableName[(int)list[i]]; this.variableNameList[i] = name; variableBuilder.AppendFormat(UICodeConfig.variable, UICodeConfig.uiComponentName[(int)list[i]], name); } } return(variableBuilder); }