/// <summary> /// 基于导出的自定义组件信息,转换为自定义组件运行时信息 /// </summary> /// <param name="updatableComponentInfos_Editor">自定义组件信息</param> /// <returns>运行时信息</returns> public static UpdatableComponentInfo[] FromInfoToRuntimeInfo(UpdatableComponentInfo_Editor[] updatableComponentInfos_Editor) { if (updatableComponentInfos_Editor is null) { throw new ArgumentNullException(nameof(updatableComponentInfos_Editor)); } List <UpdatableComponentInfo> updatableComponentInfos = new List <UpdatableComponentInfo>(); foreach (UpdatableComponentInfo_Editor updatableComponentInfo_Editor in updatableComponentInfos_Editor) { UpdatableComponentInfo updatableComponentInfo = new UpdatableComponentInfo() { BindingComponentName = updatableComponentInfo_Editor.BindingComponentName, TypeFullName = updatableComponentInfo_Editor.TypeFullName, }; var serializeItemName = from serializeItem in updatableComponentInfo_Editor.SerializeItems where serializeItem.UseJsonSerialize || serializeItem.UseUnitySerialize select serializeItem.Name; updatableComponentInfo.SerializeItems = new HashSet <string>(serializeItemName); var markingMethodName = from markingMethod in updatableComponentInfo_Editor.MarkingMethods where markingMethod.IsRuntimeAction select markingMethod.Name; updatableComponentInfo.MarkingMethods = new HashSet <string>(markingMethodName); updatableComponentInfos.Add(updatableComponentInfo); } return(updatableComponentInfos.ToArray()); }
private static void Main(string[] args) { if (args.Length > 0) { UpdatableComponentsInfoFilePath = args[0]; } UpdatableComponentsInfoFilePath = UpdatableComponentsInfoFilePath ?? "../../BMPFont/Assets/UpdatableLogic/Hotfix/UpdatableComponentInfo.txt"; if (args.Length > 1) { UpdatableComponentsInfoEditorFilePath = args[1]; } UpdatableComponentsInfoEditorFilePath = UpdatableComponentsInfoEditorFilePath ?? "../../BMPFont/Assets/UpdatableLogic/Editor/UpdatableComponentInfo_Editor.json"; var customComponentTypes = ExportUpdatableComponentFunction.GetAllUpdatableComponentTypes(); UpdatableComponentInfo_Editor[] editorInfos = ExportUpdatableComponentFunction.FromTypeToInfo(customComponentTypes); string editorInfo = JsonConvert.SerializeObject(editorInfos, Formatting.Indented); File.WriteAllText(UpdatableComponentsInfoEditorFilePath, editorInfo); Console.WriteLine($"Write Updatable Component Info(Editor) at {UpdatableComponentsInfoEditorFilePath}"); UpdatableComponentInfo[] runtimeInfos = ExportUpdatableComponentFunction.FromInfoToRuntimeInfo(editorInfos); StringBuilder stringBuilder = new StringBuilder().AppendLine("["); for (int index = 0; index < runtimeInfos.Length; index++) { UpdatableComponentInfo customComponentInfo = runtimeInfos[index]; stringBuilder.Append(JsonConvert.SerializeObject(customComponentInfo, Formatting.None)); if (index < runtimeInfos.Length - 1) { stringBuilder.AppendLine(","); } } stringBuilder.AppendLine().AppendLine("]"); File.WriteAllText(UpdatableComponentsInfoFilePath, stringBuilder.ToString()); Console.WriteLine($"Write Updatable Component Info at {UpdatableComponentsInfoFilePath}"); if (args.Length == 0) { Console.WriteLine("Finish"); Console.ReadLine(); } }