Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorComponent

ECBehaviorComponent

Behavior element behavior adding component support.

Components provide visual appearance to elements.

If the ECBehaviorCollider behavior is present in the behavior element before this behavior is added the component is statically attached. In this case the collider is a ColliderVolume and the rig assigned to the component is only used for animation purpose.

If the ECBehaviorCollider behavior is added after this behavior then a ColliderComponent is created. In this case the component is implicitly attached by ECBehaviorCollider and the component rig is used for collision detection. This is required if you intend to use per-bone collisions matching animation state or physical simulations like rag-dolls.

Hence these two use cases are possible depending on the order the behaviors are added: Shape Collision, Component Collision. See element_class_example.

See also:

Instance Counts

This behavior can be added multiple times to an element. Each instance creates one component which can be individually modified. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix component. or component({id}). if id is not empty.

model

Set path of model resource to use.

skin

Set path of skin resource to use.

rig

Set path of rig resource to use.

occlusionMesh

Set path of occlusion mesh resource to use.

audioModel

Set path of audio model resource to use.

renderEnvMap

Set if component is rendered in environment maps.

affectsAudio

Set if component is affecting audio.

hintMovement

Set movement hint.

enableGI

Set enable GI in graphic module if supported.

hintGIImportance

Set GI important hint. Value is in the range from 0 (very unimportant) to 4 (very important). This hint can be used by the graphic module to improve performance by excluding components with a GI important below a user chosen threashold.

textureReplacements

Set texture replacements.

Events

This behavior has no events.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does not require the element class to be persistable (setPersistable).

API Documentation

ECBehaviorComponent.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

Use Case 1: Shape Collision. Component is only visual. For collision only static collision shape is used. The component is attached statically to the collider and does not collide. If collider is dynamic physics simulation will be done using collision shape only.

class MyElementClass extends BehaviorElementClass
  public var ECBehaviorCollider collider
  public var ECBehaviorComponent component
  func new()
    collider = ECBehaviorCollider.new(this, null)
    // assign collision shape or collision rig to the collider
    component = ECBehaviorComponent.new(this, collider)
  end
end

Use Case 2: Component Collision. Component is used for collision detection. If collider is dynamic component bones will be updated by the collider automatically.

class MyElementClass extends BehaviorElementClass
  public var ECBehaviorCollider collider
  public var ECBehaviorComponent component
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

Use Case 1: Shape Collision

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorCollider'>
    <!-- no behavior has been added before so no component behavior will be used -->
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.physicsType'>dynamic</string>
  </behavior>
 
  <!-- adding the component will detect the previously added collider and use it -->
  <behavior type='ECBehaviorComponent'>
    <!-- optional: set layer mask as list of bits to set. default is '0' which means
                   BaseGameApp.WorldLayerBit.default -->
    <string name='layerMask'>0 1</string>
 
    <!-- optional: set render env map layer mask as list of bits to set. default is '1'
                   which means BaseGameApp.WorldLayerBit.envmap . if 'renderEnvMap' is
                   true this layer mask is OR combined with 'layerMask' -->
    <string name='layerMaskRenderEnvMap'>0 1</string>
 
    <!-- optional: set audio layer mask as list of bits to set. default is '2' which
                   means BaseGameApp.WorldLayerBit.audio . if 'affectsAudio' is
                   true this layer mask is OR combined with 'layerMask' -->
    <string name='layerMaskAffectsAudio'>0 1</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.model'>box.demodel</string>
  </behavior>
</elementClass>

Use Case 2: Component Collision.

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <!-- no collider is present yet so component will not use any collider -->
  <behavior type='ECBehaviorComponent'>
    ...
  </behavior>
 
  <behavior type='ECBehaviorCollider'>
    <!-- optional: by default the previously added component is detected and used.
                   to use a different component add one with a different id and
                   use the id here -->
    <string name='component'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.physicsType'>dynamic</string>
  </behavior>
</elementClass>

Live Examples