MassBattleAssemblyState.h
Source/MassBattleEditor/Public/UnitAssembly/MassBattleAssemblyState.h
概述Overview
Assembly 窗口的工作状态:工具窗口 编辑的全部内容都活在这个对象里——部件类别与版本、当前的预览选择、组合的工作副本、预览 Actor,以及存/取模板所需的身份信息。它不是资产:窗口打开时创建,关掉窗口(或编辑器会话结束)即消失。真正的持久化孪生是所绑定的 assembly 模板蓝图——按下 Save 时,本对象的配置被映射成模板的 Parts / Combinations / Skeleton 并写进蓝图类默认值。
The Assembly window's working state: everything the tool window edits lives in this object — part categories and versions, the current preview selection, the working copy of the combinations, the preview actor, and the identity needed to save/load a template. It is not an asset: it is created when the window opens and disappears when the window closes (or the editor session ends). The real persistent twin is the bound assembly template Blueprint — on Save, this object's configuration is mapped onto the template's Parts / Combinations / Skeleton and written into the Blueprint's class defaults.
两个 Ed(editor)结构体是模板结构体的可编辑镜像,但并不是逐字段照抄:镜像里混入了仅存在于 UI 的临时字段(折叠态、强调色槽位、分隔比例),也混入了几个“被持久化、但字段本身标 Transient”的镜像字段(部件占位符变换、版本变换、当前选中版本)——它们靠面板在同步时机收采进模板定义,而不是靠 UPROPERTY 序列化。
The two Ed (editor) structs are editable mirrors of the template structs, but not field-for-field copies: they carry fields that exist only for the UI (fold state, accent slot, split fraction) as well as a few mirror fields that are persisted yet are themselves marked Transient (the part placeholder transform, the version transform, the current selection) — those travel into the template definitions when the panel harvests them at its sync moments, not through UPROPERTY serialization.
继承Inheritance
结构体Structs
面板里一个版本行。与 FAssemblyVersionDef 对应,另外携带一个纯 UI 的分隔比例。骨骼网格与静态网格仍是恰设其一;静态网格用于无动画的挂件版本。
One version row in the panel. It corresponds to FAssemblyVersionDef and additionally carries a UI-only split fraction. Skeletal and static mesh remain mutually exclusive; a static mesh serves non-animated attachment versions.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
VersionName | FString | "Version" | 版本显示名,随模板保存。Version display name; saved with the template. |
NameWidthFraction | float | 0.35f | 仅 UI(标 Transient):本行“名字 / 网格选择器”的宽度占比,即拖动分隔手柄的结果。因为行在每次编辑后重建,比例记在这里才不会复位;绝不随模板持久化。UI only (marked Transient): this row's name-vs-picker width fraction, i.e. the result of dragging the divider. Rows rebuild on every edit, so remembering it here keeps it from resetting; it is never persisted with the template. |
SkeletalMesh | TObjectPtr<USkeletalMesh> | nullptr | 该版本的骨骼网格源。Skeletal source mesh of this version. |
StaticMesh | TObjectPtr<UStaticMesh> | nullptr | 该版本的静态网格源(挂件用,无动画)。Static source mesh of this version (attachments; no animation). |
VersionTransform | FTransform | FTransform::Identity | 模板 VersionTransform 的镜像(标 Transient):版本相对部件占位符的变换。面板在同步时从预览 Actor 或模板的组件节点收采,再随 Save 写入模板。Mirror of the template's VersionTransform (marked Transient): the version's transform relative to the part placeholder. The panel harvests it from the preview actor or the template's component nodes and writes it into the template on Save. |
面板里一个部件类别(一张部件卡)。对应 FAssemblyPartDef,另带四个面板专属字段:当前预览选中项、强调色槽位、折叠态与占位符变换镜像。字段语义与模板结构体一致——名字即引用键(父子、socket 挂接都按名字走),BakeGroupName 则只是一项被保存下来的标注,既不改变挂接、也不影响预览。
One part category (one part card) in the panel. It corresponds to FAssemblyPartDef and adds four panel-only fields: the current preview selection, the accent slot, the fold state and the placeholder-transform mirror. Field semantics match the template struct — the name is the reference key (parenting and socket mounting are name-based), while BakeGroupName is merely a saved annotation that changes neither mounts nor the preview.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
CategoryName | FString | "Category" | 部件名,落盘时写入模板的 PartName。同一窗口内必须唯一(面板拒绝空名与重名),改名会同步改写所有指向它的子件父名。Part name, written to the template's PartName on save. Must be unique within the window (the panel refuses empty and duplicate names); renaming re-points every child that referenced it. |
Versions | TArray<FAssemblyVersionEd> | 空empty | 版本列表,顺序即网格元素顺序。Version list; its order is the mesh-element order. |
PartType | EAssemblyPartType | Body | Body 或 Attachment。只有 Body 能作为父件,这正是“最多两层”的实现方式。Body or Attachment. Only a Body may act as a parent, which is exactly how the two-level cap is enforced. |
ParentPartName | FString | 空empty | 仅挂件:父部件名。可以留空(未选父件),校验会提示。Attachments only: parent part name. It may stay empty (no parent picked); validation reports it. |
AttachSocket | FName | NAME_None | 仅挂件:父件选中版本网格上的 socket;未选时为 NAME_None。Attachments only: a socket on the parent's selected-version mesh; NAME_None when unpicked. |
BakeGroupName | FString | 空empty | 组标签,随 Save 写入模板;空 = 未打组。它只是一项被保存下来的标注,不影响预览,也不改变生成的资产。A group tag, written to the template on Save; empty = ungrouped. It is a saved annotation only — it affects neither the preview nor the generated asset. |
PartTransform | FTransform | FTransform::Identity | 模板 PartTransform 的镜像(标 Transient):Body 相对 Actor 根、挂件相对所挂 socket。在面板的同步时机从预览 Actor 收采,Save 时落盘;缩放请保持 1。Mirror of the template's PartTransform (marked Transient): actor-relative for bodies, socket-relative for attachments. Harvested from the preview actor at the panel's sync moments and saved on Save; keep scale at 1. |
SelectedVersion | int32 | INDEX_NONE | 预览 Actor 上当前显示的版本(标 Transient)。INDEX_NONE = 该部件隐藏,属合法状态;应用组合时它被整体改写,Save 时写入模板的 SelectedVersion。The version shown on the preview actor right now (marked Transient). INDEX_NONE hides the part and is a legal state; applying a combination rewrites it wholesale, and Save writes it to the template's SelectedVersion. |
AccentColorIndex | int32 | INDEX_NONE | 仅 UI(标 Transient):本部件固定的调色板槽位——强调色跟随“部件”而不是它的数组位置,因此重排、连线翻转、强制层级排序都不会给部件换色。由下一次列表重建分配最小空闲槽;不持久化,重新载入按数组序重新播种。UI only (marked Transient): this part's fixed palette slot — the accent colour follows the part, not its array position, so reorders, link flips and the forced hierarchy order never repaint it. The next list rebuild assigns the smallest free slot; it is not persisted, and a fresh load re-seeds by array order. |
bCollapsed | bool | false | 仅 UI(标 Transient):版本体是否收起(标题条三角)。切换只翻标志、不重建控件。UI only (marked Transient): whether the versions body is collapsed (the header triangle). Toggling only flips the flag — no widget rebuild. |
成员变量Members
除 Categories 外,本对象的字段全部标 Transient——它们描述的是“这一次窗口会话正在看什么、绑了什么”,而不是资产内容。真正会把内容留在磁盘上的,只有 Save 写进模板蓝图的那一份。
Apart from Categories, every field here is marked Transient — they describe what this window session is looking at and bound to, not asset content. The only copy that reaches disk is what Save writes into the template Blueprint.
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
Categories | TArray<FAssemblyCategoryEd> | 空empty | 部件类别的编辑主表:面板的所有部件操作都在改它,Save 时整表映射成模板的 Parts。列表顺序即组件排列顺序,也决定最终产物里各部件的先后。The editable master list of part categories: every panel part operation edits it, and Save maps the whole list onto the template's Parts. Its order is the component ordering and also decides the order of parts in the produced result. |
Combinations | TArray<FAssemblyCombinationDef> | 空empty | 模板具名组合的工作副本(标 Transient),与 Categories 走同一条存/取管线。录制、改写、删除、随机卡掷样都在这里发生,Save 时整体写回模板。Working copy of the template's named combinations (marked Transient), travelling through the same save/load pipeline as Categories. Capturing, overwriting, removing and rolling random cards all happen here, and Save writes the whole array back to the template. |
PreviewActor | TObjectPtr<AMassBattleAssemblyTemplate> | nullptr | 关卡视口里的瞬态预览 Actor(对象标签 “MB Assembly Preview”)。它是 模板类 的一个瞬态实例,由面板生成并持有;不是用户放置的 Actor,也不进关卡存档。切换关卡时引用被主动断开,新编辑器世界就绪后惰性重建。The transient preview actor in the level viewport (actor label “MB Assembly Preview”). It is a transient instance of the template class, spawned and owned by the panel; it is not a user-placed actor and is not part of the saved level. The reference is dropped on a level switch and rebuilt lazily once the new editor world is up. |
PreviewAnim | TObjectPtr<UAnimSequence> | nullptr | 面板级预览动画(标 Transient):由 Body Parts 工具行上唯一的 Anim 控件持有,在所有骨架兼容且当前可见的 Body 部件上循环播放;挂件保持刚体。绝不随模板保存。The panel-level preview animation (marked Transient): owned by the single Anim control on the Body Parts toolbar row, looping on every visible Body part whose skeleton accepts it; attachments stay rigid. It is never saved with the template. |
AssetName | FString | "BP_Assembly" | 保存/新建所用的模板资产名(标 Transient)。绑定蓝图时由窗口把资产名播种进来;Save 时按它定位或新建资产。Template asset name used by Save and New (marked Transient). Binding a Blueprint seeds it from the actual asset, and Save uses it to locate or create the asset. |
OutputPath | FString | "/Game" | 模板资产的内容输出路径(标 Transient)。与 AssetName 一起决定保存目标;两者都会在保存前做路径净化与合法性校验,非法则拒绝保存并写日志。Content output path of the template asset (marked Transient). Together with AssetName it decides the save target; both are path-sanitized and validated before saving, and an invalid pair aborts the save with a log line. |
Skeleton | TObjectPtr<USkeleton> | nullptr | 模板权威骨架的面板侧镜像(标 Transient):Load 自资产回填、New 依已配置部件版本识别、Save 写回类默认值、模板区 Clear 一并清空。可在模板区手填;留空 = 自动识别(首个 Body 件的首个骨骼版本)。改动只让面板变脏,不会自动保存。The panel-side mirror of the template's authoritative skeleton (marked Transient): Load back-fills it from the asset, New detects it from the configured versions, Save writes it back to the class defaults, and the template section's Clear wipes it. Hand-editable in the template section; empty = auto-detect (the first Body part's first skeletal version). A change only marks the panel dirty — nothing auto-saves. |
TemplateClass | TSubclassOf<AMassBattleAssemblyTemplate> | nullptr | 绑定的模板类——即保存目标与载入来源,UI 只暴露这个句柄(场景里的预览实例由面板内部持有)。必须是一个派生蓝图;原生类或 None 视为“未绑定”,此时 Save 会按名称/路径找既有蓝图,找不到就新建。The bound template class — the save target and load source; this handle is the only thing the UI exposes (the scene preview instance is kept internally by the panel). It must be a derived Blueprint; the native class or None counts as “unbound”, in which case Save looks for an existing Blueprint at the name/path and creates one only when absent. |
Log | TArray<FString> | 空empty | 窗口日志(标 Transient):每个动作追加一行,损坏的挂接、被拒的连线、校验告警都记在这里。面板显示最新若干行并支持向上回看;同一批文字也发到引擎输出日志,标签为 [MassBattleAssembly]。The window log (marked Transient): one line per action; broken mounts, refused links and validation warnings all land here. The panel shows the newest lines with scrollback, and the same text is mirrored to the engine output log under [MassBattleAssembly]. |
管线角色Pipeline Role
本对象只被 SMassBattleAssemblyPanel 使用:窗口构造时创建(瞬态、被强引用持根),此后所有读写都经面板的 W 别名。数据流是单向往返——面板编辑 → 本对象 → Save 映射成模板定义并写进蓝图类默认值 → 下次 Load 从类默认值读回本对象 → 面板重建界面。预览 Actor 也由同一份状态驱动:每次编辑把 BuildPartDefs() 写进预览实例的 Parts 再让它对账组件,因此“你在 UI 里看到的”和“存进模板的”永远来自同一个来源。组合数组同时是复合烘焙的输入——模板被保存后,烘焙会从模板类默认值读取部件与组合。
This object is used only by SMassBattleAssemblyPanel: it is created when the window is constructed (transient, rooted by a strong reference), and every access afterwards goes through the panel's W alias. The data flow is a one-way round trip — panel edits → this object → Save maps it onto the template definitions and writes the Blueprint class defaults → the next Load reads the class defaults back into this object → the panel rebuilds its UI. The preview actor is driven from the same state: each edit writes BuildPartDefs() into the preview instance's Parts and lets it reconcile its components, so “what you see in the UI” and “what gets saved into the template” always come from one source. The combinations array is also the input to the composite bake: once the template is saved, the bake reads parts and combinations from the template class defaults.
补充说明Notes
① 本对象不是资产,也没有磁盘表示——想留下配置,必须绑定并保存一个模板蓝图。② UI 专用字段(NameWidthFraction、AccentColorIndex、bCollapsed)从不进入模板;重新载入后强调色按数组序重播、折叠状态回到统一收起、分隔比例回到默认。③ 标 Transient 的镜像字段(PartTransform、VersionTransform、SelectedVersion)虽然不随 UPROPERTY 序列化,但会随 Save 进入模板定义,因此它们既不是“可丢弃的 UI 状态”,也不该手改。④ 一个窗口会话对应一个状态对象;关闭标签页即丢弃它,未保存的改动只能通过关闭前的保存确认挽回。
① This object is not an asset and has no on-disk form — to keep a configuration you must bind and save a template Blueprint. ② UI-only fields (NameWidthFraction, AccentColorIndex, bCollapsed) never enter the template; after a reload accent colours are re-seeded by array order, folds return to the uniformly collapsed state and split fractions return to their defaults. ③ The mirror fields marked Transient (PartTransform, VersionTransform, SelectedVersion) skip UPROPERTY serialization but do reach the template definitions on Save — they are neither disposable UI state nor something to hand-edit. ④ One window session owns one state object; closing the tab discards it, and unsaved work can only be recovered through the save prompt shown before closing.
UMassBattleAssemblyTemplateFields class
区的 DetailsView 桥接对象(用户 2026-11-05:面板必须用**真正的** DetailsView 显示模板与骨架,所以这两个值要是某个对象上的反射属性)。面板让它与 UMassBattleAssemblyState 双向同步,行为(换模板即自动载入、脏签名、日志)仍归状态对象。
DetailsView bridge for the Agent Template section (user 2026-11-05: the panel must show the template and skeleton through a REAL DetailsView, so the two values have to be reflected properties on an object). The panel keeps this object in sync with UMassBattleAssemblyState, which stays the owner of the behaviour — auto-load on template change, dirty signature, logs.
成员变量Members
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
Template | TObjectPtr<class UBlueprint> | nullptr | Agent Template · 本窗口编辑与保存的 assembly 模板蓝图(必须派生自 AMassBattleAssemblyTemplate)。Assembly template blueprint this window edits and saves (must derive from AMassBattleAssemblyTemplate). |
Skeleton | TObjectPtr<class USkeleton> | nullptr | Agent Template · 本 unit 的权威骨架。留空 = 自动识别(首个 Body 件的首个骨骼版本)。Authoritative skeleton for this unit. Empty = auto-detect (first Body part's first skeletal version). |
bSkeletonUsed | bool | true | 面板 sprite-only 标志的实时镜像(在 SyncTemplateFields 里用驱动部件模块文案的同一次扫描 写入):为 FALSE 时 Skeleton 行**惰性**——变暗且不可编辑——因为所有版本都是 sprite 的单位 没有骨架可选。它是 UI 状态,绝不是作者数据——上面的 Skeleton 值不会因此被清空,加入一个 网格版本后该行恢复可编辑。Live mirror of the panel's sprite-only flag (written in SyncTemplateFields from the same single scan that drives the parts-module wording): FALSE makes the Skeleton row INERT, dimmed and non-editable, because a unit whose every version is a sprite has no skeleton to choose. It is UI state, never author data — the Skeleton value above is not cleared by this, and a mesh version makes the row editable again. |