//得到当前Group的Code public static Dictionary <string, string> GetGroupCodes(MLuaUIGroup group, string keyHead, string valueHead) { Dictionary <string, string> codes = new Dictionary <string, string>(); Dictionary <string, string> comRefsCodes = GetComRefsCodes(group.ComRefs); foreach (var item in comRefsCodes) { string key = keyHead + item.Key; string value = null; if (!string.IsNullOrEmpty(item.Value)) { value = valueHead + item.Value; } codes[key] = value; } //当前Group中还有Groups时,得到Group中的Groups的Code if (group.Groups.Length > 0) { var groupsCodes = GetGroupsCodes(group.Groups, keyHead, valueHead); MDictionaryHelper.AddRange(codes, groupsCodes); } return(codes); }
//得到MLuaUIGroup相应的代码 //=前面的是keyHead,后面的是valueHead(包含=) public static Dictionary <string, string> GetGroupsCodes(IList <MLuaUIGroup> groups, string keyHead, string valueHead) { Dictionary <string, string> codes = new Dictionary <string, string>(); for (int i = 0; i < groups.Count; i++) { string currentKeyHead = keyHead + groups[i].Name; string currentValueHead = valueHead + $"Groups[{i}]"; //当需要在上级生成Group代码 if (groups[i].IsGenerateCodeInUpper) { codes[currentKeyHead] = " = {}"; codes[currentKeyHead + ".LuaUIGroup"] = currentValueHead; var groupCodes = GetGroupCodes(groups[i], currentKeyHead + ".", currentValueHead + "."); MDictionaryHelper.AddRange(codes, groupCodes); } else { //当不需要在上级生成Group代码时只生成一句调用组件的代码 codes[currentKeyHead] = currentValueHead; } } return(codes); }