|
|
@@ -41,7 +41,8 @@ extern const char* URHO2D_CATEGORY;
|
|
|
Constraint2D::Constraint2D(Context* context) :
|
|
|
Component(context),
|
|
|
joint_(0),
|
|
|
- collideConnected_(false)
|
|
|
+ collideConnected_(false),
|
|
|
+ otherBodyNodeIDDirty_(false)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
@@ -54,6 +55,31 @@ Constraint2D::~Constraint2D()
|
|
|
void Constraint2D::RegisterObject(Context* context)
|
|
|
{
|
|
|
URHO3D_ACCESSOR_ATTRIBUTE("Collide Connected", GetCollideConnected, SetCollideConnected, bool, false, AM_DEFAULT);
|
|
|
+ URHO3D_ATTRIBUTE("Other Body NodeID", unsigned, otherBodyNodeID_, 0, AM_DEFAULT | AM_NODEID);
|
|
|
+}
|
|
|
+
|
|
|
+void Constraint2D::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
|
|
|
+{
|
|
|
+ Serializable::OnSetAttribute(attr, src);
|
|
|
+
|
|
|
+ if (!attr.accessor_ && attr.offset_ == offsetof(Constraint2D, otherBodyNodeID_))
|
|
|
+ otherBodyNodeIDDirty_ = true;
|
|
|
+}
|
|
|
+
|
|
|
+void Constraint2D::ApplyAttributes()
|
|
|
+{
|
|
|
+ // If other body node ID dirty, try to find it now and apply
|
|
|
+ if (otherBodyNodeIDDirty_)
|
|
|
+ {
|
|
|
+ Scene* scene = GetScene();
|
|
|
+ if (scene)
|
|
|
+ {
|
|
|
+ Node* otherNode = scene->GetNode(otherBodyNodeID_);
|
|
|
+ if (otherNode)
|
|
|
+ SetOtherBody(otherNode->GetComponent<RigidBody2D>());
|
|
|
+ }
|
|
|
+ otherBodyNodeIDDirty_ = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Constraint2D::OnSetEnabled()
|
|
|
@@ -107,6 +133,9 @@ void Constraint2D::SetOtherBody(RigidBody2D* body)
|
|
|
|
|
|
otherBody_ = body;
|
|
|
|
|
|
+ Node* otherNode = body ? body->GetNode() : (Node*)0;
|
|
|
+ otherBodyNodeID_ = otherNode ? otherNode->GetID() : 0;
|
|
|
+
|
|
|
RecreateJoint();
|
|
|
MarkNetworkUpdate();
|
|
|
}
|