2
0
Эх сурвалжийг харах

Merge pull request #1823 from 1vanK/master

GetDerivedComponent for Physics2D to allow using custom PhysicsWorld2D
Lasse Öörni 8 жил өмнө
parent
commit
5d19f3d0f4

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

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

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

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