Kaynağa Gözat

Convenience method Context::CreateObject<T>() for creating objects akin to Node::CreateComponent<T>(...)

bit 9 yıl önce
ebeveyn
işleme
d503a84e81
1 değiştirilmiş dosya ile 5 ekleme ve 0 silme
  1. 5 0
      Source/Urho3D/Core/Context.h

+ 5 - 0
Source/Urho3D/Core/Context.h

@@ -40,6 +40,11 @@ public:
     /// Destruct.
     /// Destruct.
     ~Context();
     ~Context();
 
 
+    /// Create an object by type. Return pointer to it or null if no factory found.
+    template <class T> inline SharedPtr<T> CreateObject()
+    {
+        return StaticCast<T>(CreateObject(T::GetTypeStatic()));
+    }
     /// Create an object by type hash. Return pointer to it or null if no factory found.
     /// Create an object by type hash. Return pointer to it or null if no factory found.
     SharedPtr<Object> CreateObject(StringHash objectType);
     SharedPtr<Object> CreateObject(StringHash objectType);
     /// Register a factory for an object type.
     /// Register a factory for an object type.