Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorAttachToParent
Behavior element behavior adding attach to parent support.
Objects can be attached to parent objects in the IGDE World Editor. During enterFrame() BehaviorElement sets the target object as the parent object. The actual attaching needs knowledge about the target object. This is delegated to behavior instances knowing how to do the attaching.
This behavior knows how to attach to BehaviorElement instances. By default the element to attach to is expected to a BehaviorElement. The element will be casted to BehaviorElement and attachToBehaviorElement() called. Optionally an ElementVisitor can be set which disables the default behavior and visits the element instead. This is useful for complex situations where even non-BehaviorElement elements can be used.
If the stub property attachToParent.attachSlot
is used the element is attached to the named target ECBehaviorAttachSlot. This attach method can only be used if these requirements are fulfilled:
attachToParent.attachSlot
is presentIf any of these requirements are not fulfilled an exception will be thrown.
If target element contains ECBehaviorCollider regular attaching is used.
An optional bone
property is supported to allow attaching the element to a specific bone in the target object ECBehaviorCollider given the collider is a ColliderRig or ColliderComponent instance.
If no bone
property is used and both colliders are ColliderRig or ColliderComponent and both used rigs have bones then rig attachment is used. This is typically used to attach cloth to actors copying the actor bone states to the cloth bone states.
In all other cases static attaching is used.
This behavior can be used only once on an element.
Element class properties have the prefix attachToParent.
.
Set bone to attach to.
attachToParent.bone
<string name='attachToParent.bone'>hand.attach.l</string>
Set behavior identifier of attach slot to attach to.
attachToParent.attachSlot
<string name='attachToParent.attachSlot'>hand.l</string>
Set attach relative to world position or using explicit position.
attachToParent.relative
true
<boolean name='attachToParent.relative'>false</boolean>
Set attach using rig mode if supported by colliders.
attachToParent.rigMode
true
<boolean name='attachToParent.rigMode'>false</boolean>
Set explicit attach position.
attachToParent.position
<vector name='attachToParent.position' x='0' y='0' z='0.1'/>
Set explicit attach rotation to attach resource to collider in degrees.
attachToParent.orientation
<vector name='attachToParent.orientation' x='30' y='0' z='0'/>
This behavior has no events.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which can be attached to other elements.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorAttachable attachable public var ECBehaviorAttachToParent attachToParent func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) attachable = ECBehaviorAttachable.new(this, collider) attachToParent = ECBehaviorAttachToParent.new(this, collider, attachable) 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='ECBehaviorAttachable'/> <behavior type='ECBehaviorAttachToParent'> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.name'>value</string> </behavior> </elementClass>