Class Ability
Represents an ability in the ability system. Allows multiple instances to be defined. Can be customized via AbilityData inspector.
Inherited Members
Namespace: LobsterFramework.AbilitySystem
Assembly: LobsterFramework.dll
Syntax
public abstract class Ability : ScriptableObject
Fields
| Improve this Doc View SourceDefaultAbilityInstance
Declaration
public const string DefaultAbilityInstance = "default"
Field Value
Type | Description |
---|---|
string |
Properties
| Improve this Doc View SourceAbilityManager
Declaration
protected AbilityManager AbilityManager { get; }
Property Value
Type | Description |
---|---|
AbilityManager |
Channel
The communication channel with client code of the currently executing ability instance
Declaration
protected AbilityChannel Channel { get; }
Property Value
Type | Description |
---|---|
AbilityChannel |
Config
The configuration of the currently executing ability instance
Declaration
protected AbilityConfig Config { get; }
Property Value
Type | Description |
---|---|
AbilityConfig |
Context
The runtime context object of the currently executing ability instance
Declaration
protected AbilityContext Context { get; }
Property Value
Type | Description |
---|---|
AbilityContext |
ExecutionPriority
The priority in which this ability will be executed. Higher number means earlier execution in relation to other abilities.
Declaration
public int ExecutionPriority { get; }
Property Value
Type | Description |
---|---|
int |
Instance
The name of the currently running ability instance
Declaration
protected string Instance { get; }
Property Value
Type | Description |
---|---|
string |
Methods
| Improve this Doc View SourceAction()
Called every frame while the ability instance remains in the execution queue.
Declaration
protected abstract bool Action()
Returns
Type | Description |
---|---|
bool | false if the ability has finished and should not execute further, otherwise true |
ConditionSatisfied()
Used for doing additional requirement check for running the ability.
Declaration
protected virtual bool ConditionSatisfied()
Returns
Type | Description |
---|---|
bool | true if the condition for this ability has been satisfied, otherwise false |
FinalizeContext()
Called to finialize the ability context and channels
Declaration
protected virtual void FinalizeContext()
FinalizeSharedReferences()
Called to finialize the references shared by all ability instances
Declaration
protected virtual void FinalizeSharedReferences()
GetAbilityComponent<T>()
Attempts to get the reference of the specified AbilityComponent stored in the same AbilityData
Declaration
protected T GetAbilityComponent<T>() where T : AbilityComponent
Returns
Type | Description |
---|---|
T | The reference to the AbilityComponent if exists |
Type Parameters
Name | Description |
---|---|
T | The type of the AbilityComponent being asked for |
Remarks
This is a shorthand call for GetAbilityComponent<T>() via AbilityManager
GetComponentReference<T>(int)
Attempts to get the reference of the specified component type from AbilityManager. The type of the reference should be one of the required types applied via RequireComponentReferenceAttribute on this ability class.
Declaration
protected T GetComponentReference<T>(int index = 0) where T : Component
Parameters
Type | Name | Description |
---|---|---|
int | index | The index to the list of components of the type specified. Use of type safe enum is strongly recommended. |
Returns
Type | Description |
---|---|
T | The component reference stored in AbilityManager if it exists, otherwise null |
Type Parameters
Name | Description |
---|---|
T | The type of the component looking for |
Remarks
This is a shorthand call for GetComponentReference<T>(Type, int) via AbilityManager
HasInstance(string)
Check if the ability has specified configuration
Declaration
public bool HasInstance(string instance)
Parameters
Type | Name | Description |
---|---|---|
string | instance | Name of the ability instance being queried |
Returns
Type | Description |
---|---|
bool | true if exists, false otherwise |
InitializeContext()
Called to initialize ability context and channels
Declaration
protected virtual void InitializeContext()
InitializeSharedReferences()
Called to initialize the references shared by all ability instances
Declaration
protected virtual void InitializeSharedReferences()
IsReady(string)
Check if the speficied ability instance is ready
Declaration
public bool IsReady(string instance)
Parameters
Type | Name | Description |
---|---|---|
string | instance | The name of the instance of the ability instance |
Returns
Type | Description |
---|---|
bool | true if config with specified name exists and is ready, false otherwise |
IsRunning(string)
Check if the ability instance is executing, this method will return false if the instance is not present
Declaration
public bool IsRunning(string instance)
Parameters
Type | Name | Description |
---|---|---|
string | instance | The name of the instance to be examined |
Returns
Type | Description |
---|---|
bool | true if the specified instance is executing, otherwise false |
JoinAsSecondary(Type, string)
Attempt to join the current running ability with another ability that is running. On success, the current running ability will terminate no later than the joined ability.
Declaration
protected bool JoinAsSecondary(Type abilityType, string instance)
Parameters
Type | Name | Description |
---|---|---|
Type | abilityType | The type of the ability to be joined with |
string | instance | The name of the instance of the ability to be joined |
Returns
Type | Description |
---|---|
bool | Return true on success, otherwise false |
JoinAsSecondary<T>(string)
Attempt to join the current running ability with another ability that is running. On success, the current running ability will terminate no later than the joined ability.
Declaration
protected bool JoinAsSecondary<T>(string instance) where T : Ability
Parameters
Type | Name | Description |
---|---|---|
string | instance | The name of the instance of the running ability to be joined |
Returns
Type | Description |
---|---|
bool | Return true on success, otherwise false |
Type Parameters
Name | Description |
---|---|
T | The type of the ability to be joined with |
OnAbilityEnqueue()
Called when the ability is added to the queue for execution
Declaration
protected virtual void OnAbilityEnqueue()
OnAbilityFinish()
Called when the ability is finished or halted.
Declaration
protected virtual void OnAbilityFinish()
OnAnimationInterrupt(AnimancerState)
Called when the animation of the ability is interrupted by other abilities. Useful when abilities relies on animation events. Default implementation suspends the ability.
Declaration
protected virtual void OnAnimationInterrupt(AnimancerState state)
Parameters
Type | Name | Description |
---|---|---|
AnimancerState | state |
OnSignaled()
Signal handler for user event.
Declaration
protected virtual void OnSignaled()
OnSignaled(AnimationEvent)
Signal handler for animation event.
Declaration
protected virtual void OnSignaled(AnimationEvent animationEvent)
Parameters
Type | Name | Description |
---|---|---|
AnimationEvent | animationEvent |
StartAnimation(AnimationClip, float)
Declaration
protected AnimancerState StartAnimation(AnimationClip animation, float speed = 1)
Parameters
Type | Name | Description |
---|---|---|
AnimationClip | animation | |
float | speed |
Returns
Type | Description |
---|---|
AnimancerState |
SuspendAll()
Suspend the execution of all running instances of this ability
Declaration
protected void SuspendAll()
SuspendInstance(string)
Suspend the execution of the specified ability instance and causing it to finish during the next suspension event.
Declaration
protected bool SuspendInstance(string instance)
Parameters
Type | Name | Description |
---|---|---|
string | instance | Name of the configuration of the ability instance to terminate |
Returns
Type | Description |
---|---|
bool | true if the configuration exists and is not running or suspended, otherwise false |