1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Physics/BsCharacterController.h" |
7 | #include "Scene/BsComponent.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @addtogroup Components-Core |
12 | * @{ |
13 | */ |
14 | |
15 | /** |
16 | * @copydoc CharacterController |
17 | * |
18 | * @note Wraps CharacterController as a Component. |
19 | */ |
20 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Physics,n:CharacterController) CCharacterController : public Component |
21 | { |
22 | public: |
23 | CCharacterController(const HSceneObject& parent); |
24 | |
25 | /** @copydoc CharacterController::move */ |
26 | BS_SCRIPT_EXPORT(n:Move) |
27 | CharacterCollisionFlags move(const Vector3& displacement); |
28 | |
29 | /** @copydoc CharacterController::getFootPosition */ |
30 | BS_SCRIPT_EXPORT(n:FootPosition,pr:getter,hide) |
31 | Vector3 () const; |
32 | |
33 | /** @copydoc CharacterController::setFootPosition */ |
34 | BS_SCRIPT_EXPORT(n:FootPosition,pr:setter,hide) |
35 | void (const Vector3& position); |
36 | |
37 | /** @copydoc CharacterController::getRadius */ |
38 | BS_SCRIPT_EXPORT(n:Radius,pr:getter) |
39 | float getRadius() const { return mDesc.radius; } |
40 | |
41 | /** @copydoc CharacterController::setRadius */ |
42 | BS_SCRIPT_EXPORT(n:Radius,pr:setter) |
43 | void setRadius(float radius); |
44 | |
45 | /** @copydoc CharacterController::getHeight */ |
46 | BS_SCRIPT_EXPORT(n:Height,pr:getter) |
47 | float getHeight() const { return mDesc.height; } |
48 | |
49 | /** @copydoc CharacterController::setHeight */ |
50 | BS_SCRIPT_EXPORT(n:Height,pr:setter) |
51 | void setHeight(float height); |
52 | |
53 | /** @copydoc CharacterController::getUp */ |
54 | BS_SCRIPT_EXPORT(n:Up,pr:getter) |
55 | Vector3 getUp() const { return mDesc.up; } |
56 | |
57 | /** @copydoc CharacterController::setUp */ |
58 | BS_SCRIPT_EXPORT(n:Up,pr:setter) |
59 | void setUp(const Vector3& up); |
60 | |
61 | /** @copydoc CharacterController::getClimbingMode */ |
62 | BS_SCRIPT_EXPORT(n:ClimbingMode,pr:getter) |
63 | CharacterClimbingMode getClimbingMode() const { return mDesc.climbingMode; } |
64 | |
65 | /** @copydoc CharacterController::setClimbingMode */ |
66 | BS_SCRIPT_EXPORT(n:ClimbingMode,pr:setter) |
67 | void setClimbingMode(CharacterClimbingMode mode); |
68 | |
69 | /** @copydoc CharacterController::getNonWalkableMode */ |
70 | BS_SCRIPT_EXPORT(n:NonWalkableMode,pr:getter) |
71 | CharacterNonWalkableMode getNonWalkableMode() const { return mDesc.nonWalkableMode; } |
72 | |
73 | /** @copydoc CharacterController::setNonWalkableMode */ |
74 | BS_SCRIPT_EXPORT(n:NonWalkableMode,pr:setter) |
75 | void setNonWalkableMode(CharacterNonWalkableMode mode); |
76 | |
77 | /** @copydoc CharacterController::getMinMoveDistance */ |
78 | BS_SCRIPT_EXPORT(n:MinMoveDistance,pr:getter) |
79 | float getMinMoveDistance() const { return mDesc.minMoveDistance; } |
80 | |
81 | /** @copydoc CharacterController::setMinMoveDistance */ |
82 | BS_SCRIPT_EXPORT(n:MinMoveDistance,pr:setter) |
83 | void setMinMoveDistance(float value); |
84 | |
85 | /** @copydoc CharacterController::getContactOffset */ |
86 | BS_SCRIPT_EXPORT(n:ContactOffset,pr:getter) |
87 | float getContactOffset() const { return mDesc.contactOffset; } |
88 | |
89 | /** @copydoc CharacterController::setContactOffset */ |
90 | BS_SCRIPT_EXPORT(n:ContactOffset,pr:setter) |
91 | void setContactOffset(float value); |
92 | |
93 | /** @copydoc CharacterController::getStepOffset */ |
94 | BS_SCRIPT_EXPORT(n:StepOffset,pr:getter) |
95 | float getStepOffset() const { return mDesc.stepOffset; } |
96 | |
97 | /** @copydoc CharacterController::setStepOffset */ |
98 | BS_SCRIPT_EXPORT(n:StepOffset,pr:setter) |
99 | void setStepOffset(float value); |
100 | |
101 | /** @copydoc CharacterController::getSlopeLimit */ |
102 | BS_SCRIPT_EXPORT(n:SlopeLimit,pr:getter,range:[0,180],slider) |
103 | Radian getSlopeLimit() const { return mDesc.slopeLimit; } |
104 | |
105 | /** @copydoc CharacterController::setSlopeLimit */ |
106 | BS_SCRIPT_EXPORT(n:SlopeLimit,pr:setter,range:[0,180],slider) |
107 | void setSlopeLimit(Radian value); |
108 | |
109 | /** @copydoc CharacterController::getLayer */ |
110 | BS_SCRIPT_EXPORT(n:Layer,pr:getter,layerMask) |
111 | UINT64 getLayer() const { return mLayer; } |
112 | |
113 | /** @copydoc CharacterController::setLayer */ |
114 | BS_SCRIPT_EXPORT(n:Layer,pr:setter,layerMask) |
115 | void setLayer(UINT64 layer); |
116 | |
117 | /** @copydoc CharacterController::onColliderHit */ |
118 | BS_SCRIPT_EXPORT(n:OnColliderHit) |
119 | Event<void(const ControllerColliderCollision&)> onColliderHit; |
120 | |
121 | /** @copydoc CharacterController::onControllerHit */ |
122 | BS_SCRIPT_EXPORT(n:OnControllerHit) |
123 | Event<void(const ControllerControllerCollision&)> onControllerHit; |
124 | |
125 | /** @name Internal |
126 | * @{ |
127 | */ |
128 | |
129 | /** Returns the character controller that this component wraps. */ |
130 | CharacterController* _getInternal() const { return static_cast<CharacterController*>(mInternal.get()); } |
131 | |
132 | /** @} */ |
133 | |
134 | /************************************************************************/ |
135 | /* COMPONENT OVERRIDES */ |
136 | /************************************************************************/ |
137 | protected: |
138 | friend class SceneObject; |
139 | using Component::destroyInternal; |
140 | |
141 | /** @copydoc Component::onInitialized() */ |
142 | void onInitialized() override; |
143 | |
144 | /** @copydoc Component::onDestroyed() */ |
145 | void onDestroyed() override; |
146 | |
147 | /** @copydoc Component::onDisabled() */ |
148 | void onDisabled() override; |
149 | |
150 | /** @copydoc Component::onEnabled() */ |
151 | void onEnabled() override; |
152 | |
153 | /** @copydoc Component::onTransformChanged() */ |
154 | void onTransformChanged(TransformChangedFlags flags) override; |
155 | |
156 | /** Updates the position by copying it from the controller to the component's scene object. */ |
157 | void updatePositionFromController(); |
158 | |
159 | /** Updates the dimensions of the controller by taking account scale of the parent scene object. */ |
160 | void updateDimensions(); |
161 | |
162 | /** Destroys the internal character controller representation. */ |
163 | void destroyInternal(); |
164 | |
165 | /** Triggered when the internal controller hits a collider. */ |
166 | void triggerOnColliderHit(const ControllerColliderCollision& value); |
167 | |
168 | /** Triggered when the internal controller hits another controller. */ |
169 | void triggerOnControllerHit(const ControllerControllerCollision& value); |
170 | |
171 | SPtr<CharacterController> mInternal; |
172 | CHAR_CONTROLLER_DESC mDesc; |
173 | UINT64 mLayer = 1; |
174 | |
175 | /************************************************************************/ |
176 | /* RTTI */ |
177 | /************************************************************************/ |
178 | public: |
179 | friend class CCharacterControllerRTTI; |
180 | static RTTITypeBase* getRTTIStatic(); |
181 | RTTITypeBase* getRTTI() const override; |
182 | |
183 | protected: |
184 | CCharacterController(); // Serialization only |
185 | }; |
186 | |
187 | /** @} */ |
188 | } |