This is an old revision of the document!
Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorAttachSlot
Behavior element behavior adding support to attach other behavior elements.
Provides an attachment slot where one ECBehaviorAttachable supporting element can be attached to. The slot behavior is responsible to persist the UniqueID of the attachable. Attachable is added to game world during addToGameWorld() if not in the game world already. Attachable is remove from game world during removeFromGameWorld() if in the game world. If attachable is present while behavior instance is disposed then attachable will be safely disposed using Element.safeDispose() .
Behavior supports using ECBehaviorVRHand instead of ECBehaviorCollider to add attachment slot to VR hands.
This behavior can be used multiple times on an element to add multiple attach slots. Use the behavior identifier to tell them apart.
Element class properties have the prefix attachSlot.
or attachSlot({id}).
if id is not empty.
Set bone to attach to or empty string to attach to collider.
attachSlot.bone
or attachSlot({id}).bone
<string name='attachSlot.bone'>value</string>
Set position in meters to attach to.
attachSlot.position
or attachSlot({id}).position
<vector name='attachSlot.position' x='0' y='0' z='0.2'/>
Set orientation in degrees to attach to.
attachSlot.orientation
or attachSlot({id}).orientation
<vector name='attachSlot.orientation' x='90' y='0' z='0'/>
This behavior has these events:
Attachable has been attached to slot.
Attachable has been removed from slot.
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace attachSlot
with attachSlot(id)
.
Detach attachable if one is present.
Parameter | Value | Description |
---|---|---|
dispose | Dispose of attachable after detaching it |
This is an example of using this action:
<action name='attachSlot.detach'> <parameter name='dispose'/> </action>
Check one or more attach slot parameters. Action succeeds if all parameter value matches their respective attach slot parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a attach slot parameter matches (or not).
Parameter | Value | Description |
---|---|---|
empty | true , false | Attach slot is empty or not |
This is an example of using this action:
<sequence> <action name='attachSlot.check'> <parameter name='empty'>false</parameter> </action> <!-- actions here run only if attach slot is not empty, hence an attachable is present --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace attachSlot
with attachSlot(id)
.
Check one or more attach slot parameters. Conditions returns true if all parameter value match their respective attach slot parameter. This condition is typically used to run an action or sequence of actions as long as attach slot conditions are true.
Parameter | Value | Description |
---|---|---|
attachSlot.empty | true , false | Attach slot is empty or not |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='attachSlot.empty'>false</parameter> <condition>attachSlot.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events. If behavior has non-empty identifier replace attachSlot
with attachSlot(id)
.
Attachable has been attached to slot
Attachable has been removed from slot.
This behavior requires no other behaviors.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which contains an attachment slot.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorAttachSlot attachSlot func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) attachSlot = ECBehaviorAttachSlot.new(this, collider) end end
Using element class supporting adding behaviors the behavior can be added like this:
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <behavior type='ECBehaviorComponent'/> <behavior type='ECBehaviorCollider'/> <behavior type='ECBehaviorAttachSlot'> <!-- optional: use vrhand behavior with id. if not set ECBehaviorCollider is used --> <string name='vrHand'>right</string> <!-- optional: use behavior tree with id instead of empty string --> <string name='behaviorTree'>second</string> <!-- optional: use state machine with id instead of empty string --> <string name='stateMachine'>second</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.bone'>hand.attach.l</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorAttachSlot' id='second'/> </elementClass>