主题
TriggerEncapsulation.Commands
BoundCommandContext 双端
命名空间 TriggerEncapsulation.Commands
csharp
public class BoundCommandContext绑定到特定实体的命令上下文
备注
这个类将CommandContext绑定到特定的Entity,使得可以直接调用Execute方法 而不需要每次都指定目标实体
方法
CastAbility 双端
csharp
public CmdResult CastAbility(IGameLink<GameDataAbility> abilityLink, ICommandTarget? target = null)在绑定实体上施放技能
abilityLink— 技能链接target— 技能目标
返回: 命令执行结果
MoveInDirection 双端
csharp
public CmdResult MoveInDirection(Angle angle)让绑定实体向指定角度移动
angle— 移动角度
返回: 命令执行结果
MoveInDirection 双端
csharp
public CmdResult MoveInDirection(float degrees)让绑定实体向指定角度移动(以度为单位)
degrees— 移动角度(度)
返回: 命令执行结果
MoveTo 双端
csharp
public CmdResult MoveTo(ScenePoint position)让绑定实体移动到指定位置
position— 目标位置
返回: 命令执行结果
AttackTarget 双端
csharp
public CmdResult AttackTarget(Unit target)让绑定实体攻击目标
target— 攻击目标
返回: 命令执行结果
StopMovement 双端
csharp
public CmdResult StopMovement()让绑定实体停止移动
返回: 命令执行结果
Stop 双端
csharp
public CmdResult Stop()让绑定实体停止所有动作
返回: 命令执行结果
CommandBuilder 双端
命名空间 TriggerEncapsulation.Commands
csharp
public class CommandBuilderCommand构建器,提供流式API来简化Command的创建和配置
备注
这个构建器解决了Command系统中常见的问题:
- 重复的构建代码
- 容易出错的参数组合
- Index和Type的不匹配
- Flag和Player的错误设置
方法
Create 双端
csharp
public static CommandBuilder Create()创建新的Command构建器
返回: 新的CommandBuilder实例
WithIndex 双端
csharp
public CommandBuilder WithIndex(CommandIndex index)设置命令索引
index— 命令索引
返回: CommandBuilder实例,支持链式调用
WithType 双端
csharp
public CommandBuilder WithType(ComponentTag type)设置组件类型
type— 组件类型
返回: CommandBuilder实例,支持链式调用
WithFlag 双端
csharp
public CommandBuilder WithFlag(CommandFlag flag)设置命令标志
flag— 命令标志
返回: CommandBuilder实例,支持链式调用
WithPlayer 双端
csharp
public CommandBuilder WithPlayer(Player? player)设置玩家
player— 玩家实例
返回: CommandBuilder实例,支持链式调用
WithTarget 双端
csharp
public CommandBuilder WithTarget(ICommandTarget? target)设置目标
target— 目标
返回: CommandBuilder实例,支持链式调用
WithAbility 双端
csharp
public CommandBuilder WithAbility(IGameLink<GameDataAbility>? abilityLink)设置技能链接
abilityLink— 技能链接
返回: CommandBuilder实例,支持链式调用
WithItem 双端
csharp
public CommandBuilder WithItem(Item? item)设置物品
item— 物品实例
返回: CommandBuilder实例,支持链式调用
WithToggle 双端
csharp
public CommandBuilder WithToggle(IGameLink<GameDataAbility> abilityLink)设置技能切换命令(智能切换)
abilityLink— 技能链接
返回: CommandBuilder实例,支持链式调用
WithTurnOn 双端
csharp
public CommandBuilder WithTurnOn(IGameLink<GameDataAbility> abilityLink)设置技能开启命令
abilityLink— 技能链接
返回: CommandBuilder实例,支持链式调用
WithTurnOff 双端
csharp
public CommandBuilder WithTurnOff(IGameLink<GameDataAbility> abilityLink)设置技能关闭命令
abilityLink— 技能链接
返回: CommandBuilder实例,支持链式调用
WithPickUp 双端
csharp
public CommandBuilder WithPickUp(IPickUpItem item)设置物品拾取命令
item— 要拾取的物品
返回: CommandBuilder实例,支持链式调用
WithDrop 双端
csharp
public CommandBuilder WithDrop(ItemPickable item)设置物品丢弃命令
item— 要丢弃的物品
返回: CommandBuilder实例,支持链式调用
WithUse 双端
csharp
public CommandBuilder WithUse(Item item)设置物品使用命令
item— 要使用的物品
返回: CommandBuilder实例,支持链式调用
AsUser 双端
csharp
public CommandBuilder AsUser(Player? player = null)配置为用户命令(客户端玩家操作)
player— 玩家,如果为null则使用Player.LocalPlayer
返回: CommandBuilder实例,支持链式调用
AsAI 双端
csharp
public CommandBuilder AsAI(Player player)配置为AI命令(服务端AI操作)
player— AI控制的玩家
返回: CommandBuilder实例,支持链式调用
AsSystem 双端
csharp
public CommandBuilder AsSystem()配置为系统命令(服务端系统操作,无权限限制)
返回: CommandBuilder实例,支持链式调用
ToAngle 双端
csharp
public CommandBuilder ToAngle(Angle angle)设置角度目标
angle— 角度
返回: CommandBuilder实例,支持链式调用
ToAngle 双端
csharp
public CommandBuilder ToAngle(float degrees)设置角度目标(以度为单位)
degrees— 角度(度)
返回: CommandBuilder实例,支持链式调用
ToUnit 双端
csharp
public CommandBuilder ToUnit(Unit unit)设置单位目标
unit— 目标单位
返回: CommandBuilder实例,支持链式调用
ToPosition 双端
csharp
public CommandBuilder ToPosition(ScenePoint position)设置位置目标
position— 目标位置
返回: CommandBuilder实例,支持链式调用
Build 双端
csharp
public Command Build()构建Command对象
返回: 配置好的Command实例
Execute 双端
csharp
public CmdResult Execute(Entity unit, bool testOnly = false)构建并立即对指定单位执行命令
unit— 执行命令的单位testOnly— 是否仅测试而不实际执行
返回: 命令执行结果
Validate 双端
csharp
public (bool IsValid, string? ErrorMessage) Validate()验证当前配置的Command是否有效
返回: 验证结果和错误信息
implicit operator 双端
csharp
public static Command implicit operator(CommandBuilder builder)隐式转换为Command
builder— CommandBuilder实例
WithAbility 仅服务端
csharp
public CommandBuilder WithAbility(Ability ability)设置技能实例(服务端专用)
ability— 技能实例
返回: CommandBuilder实例,支持链式调用
备注
此方法仅在服务端可用,允许直接使用Ability实例而不是AbilityLink。 在执行时会自动使用AbilityManager.CreateOrder方法以获得更好的性能。
WithToggle 仅服务端
csharp
public CommandBuilder WithToggle(Ability ability)设置技能切换命令(智能切换)- 服务端专用
ability— 技能实例
返回: CommandBuilder实例,支持链式调用
WithTurnOn 仅服务端
csharp
public CommandBuilder WithTurnOn(Ability ability)设置技能开启命令 - 服务端专用
ability— 技能实例
返回: CommandBuilder实例,支持链式调用
WithTurnOff 仅服务端
csharp
public CommandBuilder WithTurnOff(Ability ability)设置技能关闭命令 - 服务端专用
ability— 技能实例
返回: CommandBuilder实例,支持链式调用
CommandContext 双端
命名空间 TriggerEncapsulation.Commands
csharp
public abstract class CommandContext命令上下文,提供特定环境下的命令创建便利方法
备注
CommandContext封装了特定场景下的Player和Flag设置,使得在特定上下文中 创建命令时不需要重复设置这些参数。支持以下场景:
- 用户操作上下文(客户端)
- AI操作上下文(服务端)
- 系统操作上下文(服务端)
构造函数
CommandContext 双端
csharp
protected CommandContext()方法
ApplyContext 双端
csharp
protected abstract CommandBuilder ApplyContext(CommandBuilder builder)应用上下文设置到CommandBuilder
builder— CommandBuilder实例
返回: 应用了上下文设置的CommandBuilder
CastAbility 双端
csharp
public CommandBuilder CastAbility(IGameLink<GameDataAbility> abilityLink, ICommandTarget? target = null)在当前上下文中创建技能释放命令
abilityLink— 技能链接target— 技能目标
返回: 配置好的CommandBuilder
MoveInDirection 双端
csharp
public CommandBuilder MoveInDirection(Angle angle)在当前上下文中创建向量移动命令
angle— 移动角度
返回: 配置好的CommandBuilder
MoveInDirection 双端
csharp
public CommandBuilder MoveInDirection(float degrees)在当前上下文中创建向量移动命令(以度为单位)
degrees— 移动角度(度)
返回: 配置好的CommandBuilder
MoveTo 双端
csharp
public CommandBuilder MoveTo(ScenePoint position)在当前上下文中创建位置移动命令
position— 目标位置
返回: 配置好的CommandBuilder
AttackTarget 双端
csharp
public CommandBuilder AttackTarget(Unit target)在当前上下文中创建攻击命令
target— 攻击目标
返回: 配置好的CommandBuilder
StopMovement 双端
csharp
public CommandBuilder StopMovement()在当前上下文中创建停止移动命令
返回: 配置好的CommandBuilder
Stop 双端
csharp
public CommandBuilder Stop()在当前上下文中创建停止所有动作命令
返回: 配置好的CommandBuilder
ForUser 双端
csharp
public static CommandContext ForUser(Player? player = null)创建用户操作上下文(客户端)
player— 玩家,如果为null则使用Player.LocalPlayer
返回: 用户命令上下文
ForAI 双端
csharp
public static CommandContext ForAI(Player player)创建AI操作上下文(服务端)
player— AI控制的玩家
返回: AI命令上下文
ForSystem 双端
csharp
public static CommandContext ForSystem()创建系统操作上下文(服务端,无权限限制)
返回: 系统命令上下文
CommandContextExtensions 双端
命名空间 TriggerEncapsulation.Commands
csharp
public static class CommandContextExtensions命令上下文的便利扩展方法
方法
AsUser 双端
csharp
public static BoundCommandContext AsUser(this Entity entity, Player? player = null)为Entity创建用户命令上下文
entity— 实体(通常是Unit)player— 玩家,如果为null则使用entity的Owner
返回: 绑定到实体的用户命令上下文
AsAI 双端
csharp
public static BoundCommandContext AsAI(this Entity entity, Player? player = null)为Entity创建AI命令上下文
entity— 实体(通常是Unit)player— AI控制的玩家,如果为null则使用entity的Owner
返回: 绑定到实体的AI命令上下文
AsSystem 双端
csharp
public static BoundCommandContext AsSystem(this Entity entity)为Entity创建系统命令上下文
entity— 实体
返回: 绑定到实体的系统命令上下文
CommandExtensions 双端
命名空间 TriggerEncapsulation.Commands
csharp
public static class CommandExtensionsCommand系统的扩展方法,提供常见命令的快捷创建方式
备注
这些扩展方法封装了最常用的命令模式,包括:
- 技能释放
- 单位移动
- 攻击指令
- 停止指令 每个方法都会自动设置正确的Index、Type等参数组合
方法
CastAbility 双端
csharp
public static CmdResult CastAbility(this Entity unit, IGameLink<GameDataAbility> abilityLink, ICommandTarget? target = null, bool asUser = true, Player? player = null)对单位下达技能释放命令
unit— 执行技能的单位abilityLink— 技能链接target— 技能目标(可以是单位、位置、角度等)asUser— 是否作为用户命令执行player— 命令的玩家(如果为null且asUser为true,则使用LocalPlayer)
返回: 命令执行结果
ToggleAbility 双端
csharp
public static CmdResult ToggleAbility(this Entity unit, IGameLink<GameDataAbility> abilityLink, bool asUser = true, Player? player = null)对单位下达技能切换命令(智能切换)
unit— 执行切换的单位abilityLink— 技能链接asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
TurnOnAbility 双端
csharp
public static CmdResult TurnOnAbility(this Entity unit, IGameLink<GameDataAbility> abilityLink, bool asUser = true, Player? player = null)对单位下达技能开启命令
unit— 执行开启的单位abilityLink— 技能链接asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
TurnOffAbility 双端
csharp
public static CmdResult TurnOffAbility(this Entity unit, IGameLink<GameDataAbility> abilityLink, bool asUser = true, Player? player = null)对单位下达技能关闭命令
unit— 执行关闭的单位abilityLink— 技能链接asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
MoveInDirection 双端
csharp
public static CmdResult MoveInDirection(this Entity unit, Angle angle, bool asUser = true, Player? player = null)对单位下达水平摇杆移动命令。普通 2.5D 单位和 3D 地面单位都使用这个入口; 3D 场景中的上坡、下坡和屋顶等可走面高度由 Nav3D 根据当前场景导航面处理, 调用方只需要提供水平朝向。
unit— 移动的单位angle— 水平移动角度。asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
MoveInDirection 双端
csharp
public static CmdResult MoveInDirection(this Entity unit, float degrees, bool asUser = true, Player? player = null)对单位下达水平摇杆移动命令(以度为单位)。普通 3D 地面移动不需要预估坡面 Z。
unit— 移动的单位degrees— 水平移动角度(度)。asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
MoveTo 双端
csharp
public static CmdResult MoveTo(this Entity unit, ScenePoint position, bool asUser = true, Player? player = null)对单位下达移动到指定位置的命令
unit— 移动的单位position— 目标位置asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
StopMovement 双端
csharp
public static CmdResult StopMovement(this Entity unit, bool asUser = true, Player? player = null)对单位下达停止移动命令
unit— 停止的单位asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
AttackTarget 双端
csharp
public static CmdResult AttackTarget(this Entity unit, Unit target, bool asUser = true, Player? player = null)对单位下达攻击目标命令
unit— 攻击的单位target— 攻击目标asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
Stop 双端
csharp
public static CmdResult Stop(this Entity unit, bool asUser = true, Player? player = null)对单位下达停止所有动作的命令
unit— 停止的单位asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
PickUpItem 双端
csharp
public static CmdResult PickUpItem(this Entity unit, IPickUpItem item, bool asUser = true, Player? player = null)对单位下达拾取物品命令
unit— 执行拾取的单位item— 要拾取的物品asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
DropItem 双端
csharp
public static CmdResult DropItem(this Entity unit, ItemPickable item, bool asUser = true, Player? player = null)对单位下达丢弃物品命令
unit— 执行丢弃的单位item— 要丢弃的物品asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
UseItem 双端
csharp
public static CmdResult UseItem(this Entity unit, Item item, bool asUser = true, Player? player = null)对单位下达使用物品命令
unit— 执行使用的单位item— 要使用的物品asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
CastAbilityWithMainUnit 双端
csharp
public static CmdResult CastAbilityWithMainUnit(this Player player, IGameLink<GameDataAbility> abilityLink, ICommandTarget? target = null, bool asUser = true)让玩家的主控单位施放技能
player— 玩家abilityLink— 技能链接target— 技能目标asUser— 是否作为用户命令执行
返回: 命令执行结果,如果玩家没有主控单位则返回错误
MoveMainUnitInDirection 双端
csharp
public static CmdResult MoveMainUnitInDirection(this Player player, Angle angle, bool asUser = true)让玩家的主控单位移动
player— 玩家angle— 移动角度asUser— 是否作为用户命令执行
返回: 命令执行结果
MoveMainUnitTo 双端
csharp
public static CmdResult MoveMainUnitTo(this Player player, ScenePoint position, bool asUser = true)让玩家的主控单位移动到指定位置
player— 玩家position— 目标位置asUser— 是否作为用户命令执行
返回: 命令执行结果
StopMainUnit 双端
csharp
public static CmdResult StopMainUnit(this Player player, bool asUser = true)让玩家的主控单位停止移动
player— 玩家asUser— 是否作为用户命令执行
返回: 命令执行结果
CastAbility 双端
csharp
public static CommandBuilder CastAbility(IGameLink<GameDataAbility> abilityLink)创建技能释放命令构建器的快捷方法
abilityLink— 技能链接
返回: 预配置的CommandBuilder
MoveInDirection 双端
csharp
public static CommandBuilder MoveInDirection(Angle angle)创建向量移动命令构建器的快捷方法
angle— 移动角度
返回: 预配置的CommandBuilder
MoveTo 双端
csharp
public static CommandBuilder MoveTo(ScenePoint position)创建位置移动命令构建器的快捷方法
position— 目标位置
返回: 预配置的CommandBuilder
AttackTarget 双端
csharp
public static CommandBuilder AttackTarget(Unit target)创建攻击命令构建器的快捷方法
target— 攻击目标
返回: 预配置的CommandBuilder
StopMovement 双端
csharp
public static CommandBuilder StopMovement()创建停止移动命令构建器的快捷方法
返回: 预配置的CommandBuilder
Stop 双端
csharp
public static CommandBuilder Stop()创建停止所有动作命令构建器的快捷方法
返回: 预配置的CommandBuilder
CastAbility 仅服务端
csharp
public static CmdResult CastAbility(this Entity unit, Ability ability, ICommandTarget? target = null, bool asUser = true, Player? player = null)对单位下达技能释放命令(服务端专用,使用技能实例)
unit— 执行技能的单位ability— 技能实例target— 技能目标(可以是单位、位置、角度等)asUser— 是否作为用户命令执行player— 命令的玩家(如果为null且asUser为true,则使用LocalPlayer)
返回: 命令执行结果
备注
此重载方法仅在服务端可用,直接使用Ability实例而不是AbilityLink, 避免了Link查找过程,提供更好的性能。
ToggleAbility 仅服务端
csharp
public static CmdResult ToggleAbility(this Entity unit, Ability ability, bool asUser = true, Player? player = null)对单位下达技能切换命令(智能切换)- 服务端专用
unit— 执行切换的单位ability— 技能实例asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
TurnOnAbility 仅服务端
csharp
public static CmdResult TurnOnAbility(this Entity unit, Ability ability, bool asUser = true, Player? player = null)对单位下达技能开启命令 - 服务端专用
unit— 执行开启的单位ability— 技能实例asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
TurnOffAbility 仅服务端
csharp
public static CmdResult TurnOffAbility(this Entity unit, Ability ability, bool asUser = true, Player? player = null)对单位下达技能关闭命令 - 服务端专用
unit— 执行关闭的单位ability— 技能实例asUser— 是否作为用户命令执行player— 命令的玩家
返回: 命令执行结果
CastAbilityWithMainUnit 仅服务端
csharp
public static CmdResult CastAbilityWithMainUnit(this Player player, Ability ability, ICommandTarget? target = null, bool asUser = true)让玩家的主控单位施放技能(服务端专用,使用技能实例)
player— 玩家ability— 技能实例target— 技能目标asUser— 是否作为用户命令执行
返回: 命令执行结果,如果玩家没有主控单位则返回错误
备注
此重载方法仅在服务端可用,直接使用Ability实例而不是AbilityLink。
CastAbility 仅服务端
csharp
public static CommandBuilder CastAbility(Ability ability)创建技能释放命令构建器的快捷方法(服务端专用,使用技能实例)
ability— 技能实例
返回: 预配置的CommandBuilder
备注
此重载方法仅在服务端可用,直接使用Ability实例而不是AbilityLink。