Browse Source

Merge pull request #1823 from 1vanK/master

GetDerivedComponent for Physics2D to allow using custom PhysicsWorld2D
Lasse Öörni 8 years ago
parent
commit
5d19f3d0f4
2 changed files with 8 additions and 2 deletions
  1. 5 1
      Source/Urho3D/Urho2D/Constraint2D.cpp
  2. 3 1
      Source/Urho3D/Urho2D/RigidBody2D.cpp

+ 5 - 1
Source/Urho3D/Urho2D/Constraint2D.cpp

@@ -145,7 +145,11 @@ void Constraint2D::OnNodeSet(Node* node)
 void Constraint2D::OnSceneSet(Scene* scene)
 void Constraint2D::OnSceneSet(Scene* scene)
 {
 {
     if (scene)
     if (scene)
-        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
+    {
+        physicsWorld_ = scene->GetDerivedComponent<PhysicsWorld2D>();
+        if (!physicsWorld_)
+            physicsWorld_ = scene->CreateComponent<PhysicsWorld2D>();
+    }
 }
 }
 
 
 void Constraint2D::InitializeJointDef(b2JointDef* jointDef)
 void Constraint2D::InitializeJointDef(b2JointDef* jointDef)

+ 3 - 1
Source/Urho3D/Urho2D/RigidBody2D.cpp

@@ -561,7 +561,9 @@ void RigidBody2D::OnSceneSet(Scene* scene)
 {
 {
     if (scene)
     if (scene)
     {
     {
-        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
+        physicsWorld_ = scene->GetDerivedComponent<PhysicsWorld2D>();
+        if (!physicsWorld_)
+            physicsWorld_ = scene->CreateComponent<PhysicsWorld2D>();
 
 
         CreateBody();
         CreateBody();
         physicsWorld_->AddRigidBody(this);
         physicsWorld_->AddRigidBody(this);