Prechádzať zdrojové kódy

Bugfix: Drag and dropping components onto game object GUI fields now works properly

BearishSun 7 rokov pred
rodič
commit
f2bec8c6da

+ 23 - 3
Source/Scripting/SBansheeEditor/BsGUIGameObjectField.cpp

@@ -46,6 +46,7 @@ namespace bs
 
 		mDropButton->onDataDropped.connect(std::bind(&GUIGameObjectField::dataDropped, this, _1));
 		mDropButton->onClick.connect(std::bind(&GUIGameObjectField::onDropButtonClicked, this));
+		mDropButton->setContent(GUIContent(HString("None (" + mType + ")")));
 	}
 
 	GUIGameObjectField::~GUIGameObjectField()
@@ -184,7 +185,14 @@ namespace bs
 				return;
 
 			mInstanceId = value->getInstanceId();
-			mDropButton->setContent(GUIContent(HString(value->getName() + " (" + mType + ")")));
+
+			if(rtti_is_of_type<SceneObject>(value.get()))
+				mDropButton->setContent(GUIContent(HString(value->getName() + " (" + mType + ")")));
+			else
+			{
+				HComponent component = static_object_cast<Component>(value);
+				mDropButton->setContent(GUIContent(HString(component->SO()->getName() + " (" + mType + ")")));
+			}
 		}
 		else
 		{
@@ -257,6 +265,10 @@ namespace bs
 		}
 		else // A component
 		{
+			MonoClass* acceptedClass = MonoManager::instance().findClass(mNamespace, mType);
+
+			ScriptAssemblyManager& sam = ScriptAssemblyManager::instance();
+
 			for (UINT32 i = 0; i < draggedSceneObjects->numObjects; i++)
 			{
 				HSceneObject so = draggedSceneObjects->objects[i];
@@ -264,11 +276,10 @@ namespace bs
 				const Vector<HComponent>& components = so->getComponents();
 				for (auto& component : components)
 				{
-					if (component->getTypeId() == TID_ManagedComponent) // We only care about managed components
+					if (component->getTypeId() == TID_ManagedComponent)
 					{
 						HManagedComponent managedComponent = static_object_cast<ManagedComponent>(component);
 
-						MonoClass* acceptedClass = MonoManager::instance().findClass(mNamespace, mType);
 						MonoClass* providedClass = MonoManager::instance().findClass(managedComponent->getManagedNamespace(), managedComponent->getManagedTypeName());
 
 						if (acceptedClass != nullptr && providedClass != nullptr)
@@ -279,6 +290,15 @@ namespace bs
 							}
 						}
 					}
+					else
+					{
+						BuiltinComponentInfo* info = sam.getBuiltinComponentInfo(component->getRTTI()->getRTTIId());
+						if (info == nullptr)
+							continue;
+
+						if (info->monoClass->isSubClassOf(acceptedClass))
+							setValue(component, true);
+					}
 				}
 			}
 		}

+ 1 - 1
Source/Scripting/SBansheeEditor/BsGUIGameObjectField.h

@@ -170,7 +170,7 @@ namespace bs
 		 */
 
 		/** @copydoc GUIElement::setTint */
-		virtual void setTint(const Color& color) override;
+		void setTint(const Color& color) override;
 
 		/** @copydoc GUIElement::_updateLayoutInternal */
 		void _updateLayoutInternal(const GUILayoutData& data) override;

+ 19 - 3
Source/Scripting/SBansheeEditor/Wrappers/GUI/BsScriptGUIGameObjectField.cpp

@@ -10,7 +10,13 @@
 #include "GUI/BsGUIContent.h"
 #include "Wrappers/GUI/BsScriptGUIContent.h"
 #include "Wrappers/BsScriptGameObject.h"
+#include "Wrappers/BsScriptSceneObject.h"
+#include "Wrappers/BsScriptComponent.h"
+#include "Wrappers/BsScriptManagedComponent.h"
+#include "Scene/BsComponent.h"
+#include "Scene/BsSceneObject.h"
 #include "BsScriptGameObjectManager.h"
+#include "Reflection/BsRTTIType.h"
 
 using namespace std::placeholders;
 
@@ -103,12 +109,22 @@ namespace bs
 	MonoObject* ScriptGUIGameObjectField::nativeToManagedGO(const HGameObject& instance)
 	{
 		if (instance == nullptr)
-		{
 			return nullptr;
-		}
 		else
 		{
-			ScriptGameObjectBase* scriptGO = ScriptGameObjectManager::instance().getScriptGameObject(instance->getInstanceId());
+			ScriptGameObjectManager& sgom = ScriptGameObjectManager::instance();
+			ScriptGameObjectBase* scriptGO = nullptr;
+			if(rtti_is_of_type<SceneObject>(instance.get()))
+				scriptGO = sgom.getOrCreateScriptSceneObject(static_object_cast<SceneObject>(instance));
+			else // Component
+			{
+				HComponent component = static_object_cast<Component>(instance);
+				if (component->getTypeId() == TID_ManagedComponent)
+					scriptGO = sgom.getManagedScriptComponent(static_object_cast<ManagedComponent>(component));
+				else
+					scriptGO = sgom.getBuiltinScriptComponent(component);
+			}
+
 			if (scriptGO == nullptr)
 				return nullptr;
 			else