private void Create_SOContainer(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeNamespaceImport[] arrDefaultUsing, CodeTypeDeclaration pType, CodeTypeDeclaration[] arrEnumType, TypeData pSaveData) { Create_SOContainer(pNameSpace, arrDefaultUsing, pType, arrEnumType, out var pContainerType, out var pInitMethod); IEnumerable <FieldTypeData> listKeyField = pSaveData.listFieldData.Where(p => p.bIsKeyField); foreach (var pFieldData in listKeyField) { string strFieldName = ""; string strMemberType = ""; if (pFieldData.bIsOverlapKey) { strFieldName = $"mapData_Key_Is_{pFieldData.strFieldName}"; strMemberType = $"Dictionary<{pFieldData.strFieldType}, List<{pType.Name}>>"; } else { strFieldName = $"mapData_Key_Is_{pFieldData.strFieldName}"; strMemberType = $"Dictionary<{pFieldData.strFieldType}, {pType.Name}>"; } pContainerType.AddField(new FieldTypeData(strFieldName, strMemberType)); Generate_CacheMethod(pContainerType, pInitMethod, const_strListData, strFieldName, pFieldData.strFieldName, pFieldData.bIsOverlapKey); } pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pContainerType.Name}"); }
private void Create_SO(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeTypeDeclaration pType, TypeData pSaveData) { pType.AddBaseClass("UnityEngine.ScriptableObject"); pNameSpace.Types.Clear(); pNameSpace.Types.Add(pType); var listVirtualFieldOption = pSaveData.listFieldData.Where(pExportOption => pExportOption.bDeleteThisField_InCode == false && pExportOption.bIsVirtualField); foreach (var pVirtualField in listVirtualFieldOption) { pType.AddField(pVirtualField); } pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pType.Name}"); }
private void Create_GlobalSOContainer(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeNamespaceImport[] arrDefaultUsing, CodeTypeDeclaration pType, CodeTypeDeclaration[] arrEnumType, TypeData pSaveData) { Create_SOContainer(pNameSpace, arrDefaultUsing, pType, arrEnumType, out var pContainerType, out var pInitMethod); CodeTypeDeclaration pEnumHelperClass = GenerateEnumHelperClass(pNameSpace, pContainerType); IEnumerable <FieldTypeData> listKeyField = pSaveData.listFieldData.Where(p => p.bIsKeyField); string strValueFieldName = ""; IEnumerable <FieldTypeData> listRealField = pSaveData.listFieldData.Where(p => p.bIsKeyField == false); foreach (var pRealField in listRealField) { if (pRealField.strFieldName.ToLower().Contains(nameof(EGlobalColumnType.Value).ToLower())) { strValueFieldName = pRealField.strFieldName; break; } } HashSet <string> setAlreadyExecute = new HashSet <string>(); foreach (var pFieldData in listKeyField) { if (setAlreadyExecute.Contains(pFieldData.strFieldType)) { continue; } setAlreadyExecute.Add(pFieldData.strFieldType); string strFieldName = $"mapData_Type_Is_{pFieldData.strFieldType}"; string strMemberType = $"Dictionary<{const_GlobalKey_EnumName + "_" + pFieldData.strFieldType}, {pFieldData.strFieldType}>"; pContainerType.AddField(new FieldTypeData(strFieldName, strMemberType)); Generate_CacheMethod_Global(pContainerType, pInitMethod, const_strFieldName_ListData, strFieldName, pFieldData.strFieldName, pFieldData.strFieldType, strValueFieldName); Generate_ExtensionMethod_ByEnumKey(pEnumHelperClass, pContainerType, strFieldName, const_GlobalKey_EnumName + "_" + pFieldData.strFieldType, pFieldData.strFieldType, false); } pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pContainerType.Name}"); }
private void Create_SOContainer(CodeFileBuilder pCodeFileBuilder, CodeNamespace pNameSpace, CodeNamespaceImport[] arrDefaultUsing, CodeTypeDeclaration pType, CodeTypeDeclaration[] arrEnumType, TypeData pSaveData) { Create_SOContainer(pNameSpace, arrDefaultUsing, pType, arrEnumType, out var pContainerType, out var pInitMethod); var arrKeyField = pSaveData.listFieldData.Where(p => p.bIsKeyField).ToArray(); CodeTypeDeclaration pEnumHelperClass = arrKeyField.Length > 0 ? GenerateEnumHelperClass(pNameSpace, pContainerType) : null; foreach (var pFieldData in arrKeyField) { string strFieldName = $"mapData_Key_Is_{pFieldData.strFieldName}"; string strMemberType = pFieldData.bIsOverlapKey ? $"Dictionary<{pFieldData.strFieldType}, List<{pType.Name}>>" : $"Dictionary<{pFieldData.strFieldType}, {pType.Name}>"; pContainerType.AddField(new FieldTypeData(strFieldName, strMemberType)); Generate_CacheMethod(pContainerType, pInitMethod, const_strFieldName_ListData, strFieldName, pFieldData.strFieldName, pFieldData.bIsOverlapKey); if (pEnumHelperClass != null) { Generate_ExtensionMethod_ByEnumKey(pEnumHelperClass, pContainerType, strFieldName, pFieldData.strFieldType, pType.Name, pFieldData.bIsOverlapKey); } } pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/{pContainerType.Name}"); }
public override Task DoWork(CodeFileBuilder pCodeFileBuilder, ISheetConnector pConnector, TypeData[] arrSheetData, Action <string> OnPrintWorkState) { CodeNamespace pNameSpace = new CodeNamespace(); List <CodeNamespaceImport> listDefaultUsing = new List <CodeNamespaceImport>(); listDefaultUsing.Add(new CodeNamespaceImport("UnityEngine")); List <CommandLineArg> listCommandLine = Parsing_CommandLine(strCommandLine, null); for (int i = 0; i < listCommandLine.Count; i++) { ECommandLine eCommandLine = (ECommandLine)Enum.Parse(typeof(ECommandLine), listCommandLine[i].strArgName); switch (eCommandLine) { case ECommandLine.addusing: listDefaultUsing.Add(new CodeNamespaceImport(listCommandLine[i].strArgValue)); break; case ECommandLine.useusing: pNameSpace.Name = listCommandLine[i].strArgValue; break; } } CodeNamespaceImport[] arrDefaultUsing = listDefaultUsing.ToArray(); pNameSpace.Imports.AddRange(arrDefaultUsing); CodeTypeDeclarationCollection arrTypes = pCodeFileBuilder.GetCodeTypeDeclarationCollection(); List <CodeTypeDeclaration> listType = new List <CodeTypeDeclaration>(); foreach (CodeTypeDeclaration pType in arrTypes) { listType.Add(pType); } HashSet <CodeTypeDeclaration> setExecutedType = new HashSet <CodeTypeDeclaration>(); IEnumerable <CodeTypeDeclaration> listUnitySO = listType.Where(p => string.IsNullOrEmpty(p.Name) == false && p.IsClass); foreach (CodeTypeDeclaration pType in listUnitySO) { TypeData pSaveData = arrSheetData.FirstOrDefault((pSaveDataSheet) => pSaveDataSheet.strFileName == pType.Name); if (pSaveData == null) { continue; } Create_SO(pCodeFileBuilder, pNameSpace, pType, pSaveData); CodeTypeDeclaration[] arrEnumTypes = listType.Where(p => pSaveData.listEnumName.Contains(p.Name)).ToArray(); foreach (var pEnumType in arrEnumTypes) { setExecutedType.Add(pEnumType); } if (pSaveData.eType == ESheetType.Global) { Create_GlobalSOContainer(pCodeFileBuilder, pNameSpace, arrDefaultUsing, pType, arrEnumTypes, pSaveData); } else { Create_SOContainer(pCodeFileBuilder, pNameSpace, arrDefaultUsing, pType, arrEnumTypes, pSaveData); } OnPrintWorkState?.Invoke($"UnitySO - Working SO {pType.Name}"); setExecutedType.Add(pType); } // Others pNameSpace.Types.Clear(); IEnumerable <CodeTypeDeclaration> listOthers = listType.Where(p => string.IsNullOrEmpty(p.Name) == false && setExecutedType.Contains(p) == false); foreach (CodeTypeDeclaration pType in listOthers) { OnPrintWorkState?.Invoke($"UnitySO - Working Others {pType.Name}"); pNameSpace.Types.Add(pType); setExecutedType.Add(pType); } if (pNameSpace.Types.Count != 0) { pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/Others"); } return(Task.CompletedTask); }
public override Task DoWork(CodeFileBuilder pCodeFileBuilder, ISheetConnector pConnector, TypeData[] arrSheetData, Action <string> OnPrintWorkProcess) { return(Task.Run(() => pCodeFileBuilder.Generate_CSharpCode($"{GetRelative_To_AbsolutePath(strPath)}/{strFileName}"))); }