Mass Battle Frameworkv1.20.0

UMassAPIEntityComponentBase

UCLASS Abstract DataSource Contract

Source/MassAPI/Public/MassAPIEntityComponentBase.h

概述Overview

MassAPI 智能节点的数据源契约。派生自本类的组件可以直接插进 MassAPI 节点的 DataSource 针:节点通过四个虚函数询问「数据现在住在哪」。核心规则只有一条——未初始化的组件回答自己的生成模板(编辑落在模板上),已初始化的组件回答现存实体句柄(编辑落在实体上)。契约放在通用 MassAPI 模块里,是因为 MassAPI 是独立插件,不能知道任何玩法模块的具体组件类;玩法模块继承本类,并用各自的存储实现这四个虚函数。

The datasource contract for MassAPI smart nodes. A component derived from this class can be plugged straight into a node's DataSource pin: the node asks the four virtuals where its data currently lives. One rule governs everything — an uninitialized component answers with its spawn template (edits land in the template), while an initialized one answers with its live entity handle (edits land in the entity). The contract lives in the generic MassAPI module because MassAPI is a standalone plugin and must not know any gameplay module's concrete component classes; gameplay modules derive from it and implement the four virtuals against their own storage.

继承Inheritance

USceneComponent → UMassAPIEntityComponentBase

继承场景组件,因此派生组件在关卡里自带变换、可挂到任意父组件下。类标记为 Abstract,不能直接实例化——具体组件类型由派生类提供(玩法模块的实体组件基类即是如此)。

Derives from a scene component, so derived components carry a transform in the level and can be attached under any parent. The class is marked Abstract and cannot be instantiated directly — the concrete component type is supplied by a derived class (as the gameplay module's entity component base does).

公开方法Public Methods

IsEntityInitialized virtual bool (BlueprintPure, BlueprintCallable)

节点的分流开关,蓝图显示名为 Is Entity Initialized。返回真表示组件已经拥有活实体,节点应当读写实体;返回假表示目前只有生成模板,节点应当编辑模板。节点应始终先调用它,再决定走哪条读写路径。

The node's routing switch, displayed as Is Entity Initialized. True means the component owns a live entity, so the node reads/writes the entity; false means only the spawn template exists, so the node edits the template. Nodes should always call it first and then pick the read/write path.

Input

无参数。

No parameters.

Output

返回组件是否已拥有实体(true = 已初始化,false = 只有生成模板)。具体判定由派生类实现。

Returns whether the component already owns an entity (true = initialized, false = spawn template only). The concrete test is provided by the derived implementation.

GetDataSourceEntity virtual FEntityHandle (BlueprintPure, BlueprintCallable)

返回节点在组件已初始化时应当读写的实体句柄,蓝图显示名为 Get DataSource Entity。节点只在 IsEntityInitialized 为真时使用这个结果;未初始化时应改走 GetDataSourceTemplate。

Returns the entity handle the nodes should read and write when the component is initialized, displayed as Get DataSource Entity. Nodes use this result only while IsEntityInitialized is true; otherwise they go through GetDataSourceTemplate.

Input

无参数。

No parameters.

Output

返回实体句柄;未初始化时的返回值由派生类实现决定(头文件未作规定),故调用方必须先以 IsEntityInitialized 分流。

Returns the entity handle; the value while uninitialized is up to the derived implementation (the header does not specify it), so callers must route through IsEntityInitialized first.

GetDataSourceTemplate virtual FEntityTemplateData (BlueprintPure, BlueprintCallable)

返回节点在组件未初始化时应当编辑的生成模板,蓝图显示名为 Get Data Source Template。刻意不声明为 const:实现可以在首次访问时才惰性构建模板。返回的是模板值,节点修改后必须经 SetDataSourceTemplate 存回组件,否则下一次生成读不到改动。

Returns the spawn template the nodes should edit while the component is not initialized, displayed as Get Data Source Template. Deliberately not const: an implementation may build the template lazily on first access. The return is a template value, so a node must store its edits back through SetDataSourceTemplate, otherwise the next spawn will not see them.

Input

无参数。

No parameters.

Output

返回生成模板的值拷贝。副作用:实现可能在此次调用中惰性构建模板。

Returns a value copy of the spawn template. Side effects: the implementation may build the template lazily during this call.

SetDataSourceTemplate virtual void (BlueprintCallable)

把编辑过的模板存回组件,让下一次生成消费它,蓝图显示名为 Set Data Source Template。它是 GetDataSourceTemplate 的配对写入口:取模板 → 改 → 存回,三步构成未初始化状态下的完整编辑回路。

Stores an edited template back on the component so the next spawn consumes it, displayed as Set Data Source Template. It is the paired writer for GetDataSourceTemplate: fetch → edit → store back is the complete editing loop while uninitialized.

Input
参数Param类型Type说明Description
InTemplateDataconst FEntityTemplateData&要存回的模板数据(通常来自 GetDataSourceTemplate 的返回副本)。Template data to store back (normally the copy returned by GetDataSourceTemplate).
Output

无返回值。副作用:组件保存该模板,后续生成使用新值。

No return value. Side effects: the component keeps the template and later spawns use the new value.

补充说明Notes

① 契约而非实现:本类只声明四个虚函数,存储(模板、实体句柄、初始化标志)完全由派生类负责;MassBattle 的实体组件基类即派生自本类。
② 读写方向随状态切换:同一份节点数据在不同时刻落在不同位置——未初始化时是模板,初始化后是实体。任何绕过 IsEntityInitialized 直接读写其中一侧的实现,都会在另一状态下改到错误的数据。
③ 蓝图可见性:四个函数全部标记 BlueprintCallable;三个读取函数额外标记 BlueprintPure,可在蓝图中作为纯节点使用。改动模板是显式写操作,因此 SetDataSourceTemplate 不是纯节点。

① Contract, not implementation: this class declares only the four virtuals; storage (template, entity handle, initialized flag) is entirely the derived class's responsibility. MassBattle's entity component base derives from it.
② Read/write target follows state: one node's data lives in different places at different times — the template while uninitialized, the entity once initialized. Any implementation that bypasses IsEntityInitialized and touches one side directly will write the wrong store in the other state.
③ Blueprint surface: all four functions are BlueprintCallable; the three getters are additionally BlueprintPure, so they can be used as pure nodes. Editing the template is an explicit write, which is why SetDataSourceTemplate is not pure.