diff --git a/Source/Engine/Scripting/ScriptingObject.cpp b/Source/Engine/Scripting/ScriptingObject.cpp index e00694ee4..7766e0492 100644 --- a/Source/Engine/Scripting/ScriptingObject.cpp +++ b/Source/Engine/Scripting/ScriptingObject.cpp @@ -517,7 +517,7 @@ public: obj->RegisterObject(); } - static void Destroy(ManagedScriptingObject* obj, float timeLeft) + static void Destroy(ScriptingObject* obj, float timeLeft) { // Use scaled game time for removing actors/scripts by the user (maybe expose it to the api?) const bool useGameTime = timeLeft > ZeroTolerance; @@ -526,7 +526,7 @@ public: obj->DeleteObject(timeLeft, useGameTime); } - static MonoString* GetTypeName(ManagedScriptingObject* obj) + static MonoString* GetTypeName(ScriptingObject* obj) { INTERNAL_CALL_CHECK_RETURN(obj, nullptr); return MUtils::ToString(obj->GetType().Fullname); @@ -569,7 +569,7 @@ public: return obj ? obj->GetOrCreateManagedInstance() : nullptr; } - static void ChangeID(ManagedScriptingObject* obj, Guid* id) + static void ChangeID(ScriptingObject* obj, Guid* id) { INTERNAL_CALL_CHECK(obj); obj->ChangeID(*id); @@ -586,7 +586,11 @@ public: ADD_INTERNAL_CALL("FlaxEngine.Object::Internal_FindObject", &FindObject); ADD_INTERNAL_CALL("FlaxEngine.Object::Internal_TryFindObject", &TryFindObject); ADD_INTERNAL_CALL("FlaxEngine.Object::Internal_ChangeID", &ChangeID); + + static ScriptingObject* Spawn(const ScriptingObjectSpawnParams& params) + { + return New(params); } }; -IMPLEMENT_SCRIPTING_TYPE_NO_SPAWN(ScriptingObject, FlaxEngine, "FlaxEngine.Object", nullptr, nullptr); +ScriptingTypeInitializer ScriptingObject::TypeInitializer(GetBinaryModuleFlaxEngine(), StringAnsiView("FlaxEngine.Object", ARRAY_COUNT("FlaxEngine.Object") - 1), sizeof(ScriptingObject), &ScriptingObjectInternal::InitRuntime, &ScriptingObjectInternal::Spawn); diff --git a/Source/Engine/Scripting/ScriptingObjectReference.h b/Source/Engine/Scripting/ScriptingObjectReference.h index fd132d308..937e92ce1 100644 --- a/Source/Engine/Scripting/ScriptingObjectReference.h +++ b/Source/Engine/Scripting/ScriptingObjectReference.h @@ -10,6 +10,7 @@ extern FLAXENGINE_API ScriptingObject* FindObject(const Guid& id, MClass* type); /// /// The scripting object reference. /// +/// The type of the scripting object. class FLAXENGINE_API ScriptingObjectReferenceBase { public: @@ -59,7 +60,6 @@ public: /// /// Gets the object ID. /// - /// The object ID or Guid::Empty if nothing assigned. FORCE_INLINE Guid GetID() const { return _object ? _object->GetID() : Guid::Empty; @@ -68,7 +68,6 @@ public: /// /// Gets managed instance object (or null if no object linked). /// - /// The managed object instance. FORCE_INLINE MonoObject* GetManagedInstance() const { return _object ? _object->GetOrCreateManagedInstance() : nullptr; @@ -77,7 +76,6 @@ public: /// /// Determines whether object is assigned and managed instance of the object is alive. /// - /// True if managed object has been created and exists, otherwise false. FORCE_INLINE bool HasManagedInstance() const { return _object && _object->HasManagedInstance(); @@ -86,7 +84,6 @@ public: /// /// Gets the managed instance object or creates it if missing or null if not assigned. /// - /// The Mono managed object. FORCE_INLINE MonoObject* GetOrCreateManagedInstance() const { return _object ? _object->GetOrCreateManagedInstance() : nullptr; @@ -167,95 +164,42 @@ public: public: - /// - /// Compares the property value with the given object. - /// - /// The other. - /// True if property object equals the given value. FORCE_INLINE bool operator==(T* other) { return _object == other; } - - /// - /// Compares the property value with the other property value. - /// - /// The other property. - /// True if properties are equal. - FORCE_INLINE bool operator==(const ScriptingObjectReference& other) - { - return _object == other._object; - } - - /// - /// Compares the property value with the given object. - /// - /// The other. - /// True if property object not equals the given value. FORCE_INLINE bool operator!=(T* other) { return _object != other; } - - /// - /// Compares the property value with the other property value. - /// - /// The other property. - /// True if properties are not equal. + FORCE_INLINE bool operator==(const ScriptingObjectReference& other) + { + return _object == other._object; + } FORCE_INLINE bool operator!=(const ScriptingObjectReference& other) { return _object != other._object; } - /// - /// Sets the property to the given property value. - /// - /// The other property. - /// The reference to this property. - ScriptingObjectReference& operator=(const ScriptingObjectReference& other) - { - if (this != &other) - OnSet(other.Get()); - return *this; - } - - /// - /// Sets the property to the given value. - /// - /// The object. - /// The reference to this property. - FORCE_INLINE ScriptingObjectReference& operator=(const T& other) - { - OnSet(&other); - return *this; - } - - /// - /// Sets the property to the given value. - /// - /// The object. - /// The reference to this property. FORCE_INLINE ScriptingObjectReference& operator=(T* other) { OnSet(other); return *this; } - - /// - /// Sets the property to the object of the given ID. - /// - /// The object ID. - /// The reference to this property. + ScriptingObjectReference& operator=(const ScriptingObjectReference& other) + { + OnSet(other.Get()); + return *this; + } FORCE_INLINE ScriptingObjectReference& operator=(const Guid& id) { - Set(id); + OnSet(static_cast(FindObject(id, T::GetStaticClass()))); return *this; } /// /// Implicit conversion to the object. /// - /// The object reference. FORCE_INLINE operator T*() const { return (T*)_object; @@ -264,7 +208,6 @@ public: /// /// Implicit conversion to boolean value. /// - /// True if object has been assigned, otherwise false FORCE_INLINE operator bool() const { return _object != nullptr; @@ -273,7 +216,6 @@ public: /// /// Object accessor. /// - /// The object reference. FORCE_INLINE T* operator->() const { return (T*)_object; @@ -282,7 +224,6 @@ public: /// /// Gets the object pointer. /// - /// The object reference. FORCE_INLINE T* Get() const { return (T*)_object; @@ -291,32 +232,11 @@ public: /// /// Gets the object as a given type (static cast). /// - /// Asset template FORCE_INLINE U* As() const { return static_cast(_object); } - -public: - - /// - /// Sets the object. - /// - /// The object ID. Uses Scripting to find the registered object of the given ID. - FORCE_INLINE void Set(const Guid& id) - { - Set(static_cast(FindObject(id, T::GetStaticClass()))); - } - - /// - /// Sets the object. - /// - /// The object. - FORCE_INLINE void Set(T* object) - { - OnSet(object); - } }; template