Browse Source

Bugfix: Gizmo rendering for builtin components now works again

BearishSun 8 years ago
parent
commit
c175eaf2ce

+ 43 - 19
Source/SBansheeEditor/BsScriptGizmoManager.cpp

@@ -14,6 +14,8 @@
 #include "Scene/BsGizmoManager.h"
 #include "Scene/BsGizmoManager.h"
 #include "Scene/BsSelection.h"
 #include "Scene/BsSelection.h"
 #include "BsScriptObjectManager.h"
 #include "BsScriptObjectManager.h"
+#include "BsScriptGameObjectManager.h"
+#include "Wrappers/BsScriptComponent.h"
 
 
 using namespace std::placeholders;
 using namespace std::placeholders;
 
 
@@ -65,36 +67,58 @@ namespace bs
 			const Vector<HComponent>& components = curSO->getComponents();
 			const Vector<HComponent>& components = curSO->getComponents();
 			for (auto& component : components)
 			for (auto& component : components)
 			{
 			{
+				String componentName;
+				MonoObject* managedInstance = nullptr;
 				if (rtti_is_of_type<ManagedComponent>(component.get()))
 				if (rtti_is_of_type<ManagedComponent>(component.get()))
 				{
 				{
 					ManagedComponent* managedComponent = static_cast<ManagedComponent*>(component.get());
 					ManagedComponent* managedComponent = static_cast<ManagedComponent*>(component.get());
+					componentName = managedComponent->getManagedFullTypeName();
+					managedInstance = managedComponent->getManagedInstance();
+				}
+				else
+				{
+					ScriptGameObjectManager& sgoManager = ScriptGameObjectManager::instance();
+					ScriptComponentBase* scriptComponent = sgoManager.getBuiltinScriptComponent(component, false);
 
 
-					auto iterFind = mGizmoDrawers.find(managedComponent->getManagedFullTypeName());
-					if (iterFind != mGizmoDrawers.end())
+					if (scriptComponent)
 					{
 					{
-						UINT32 flags = iterFind->second.flags;
+						managedInstance = scriptComponent->getManagedInstance();
+
+						String ns, typeName;
+						MonoUtil::getClassName(managedInstance, ns, typeName);
+
+						componentName = ns + "." + typeName;
+					}
+				}
+
+				if (componentName.empty())
+					continue;
 
 
-						bool drawGizmo = false;
-						if (((flags & (UINT32)DrawGizmoFlags::Selected) != 0) && isSelected)
-							drawGizmo = true;
+				auto iterFind = mGizmoDrawers.find(componentName);
+				if (iterFind != mGizmoDrawers.end())
+				{
+					UINT32 flags = iterFind->second.flags;
 
 
-						if (((flags & (UINT32)DrawGizmoFlags::ParentSelected) != 0) && isParentSelected)
-							drawGizmo = true;
+					bool drawGizmo = false;
+					if (((flags & (UINT32)DrawGizmoFlags::Selected) != 0) && isSelected)
+						drawGizmo = true;
 
 
-						if (((flags & (UINT32)DrawGizmoFlags::NotSelected) != 0) && !isSelected && !isParentSelected)
-							drawGizmo = true;
+					if (((flags & (UINT32)DrawGizmoFlags::ParentSelected) != 0) && isParentSelected)
+						drawGizmo = true;
 
 
-						if (drawGizmo)
-						{
-							bool pickable = (flags & (UINT32)DrawGizmoFlags::Pickable) != 0;
-							GizmoManager::instance().startGizmo(curSO);
-							GizmoManager::instance().setPickable(pickable);
+					if (((flags & (UINT32)DrawGizmoFlags::NotSelected) != 0) && !isSelected && !isParentSelected)
+						drawGizmo = true;
+
+					if (drawGizmo)
+					{
+						bool pickable = (flags & (UINT32)DrawGizmoFlags::Pickable) != 0;
+						GizmoManager::instance().startGizmo(curSO);
+						GizmoManager::instance().setPickable(pickable);
 
 
-							void* params[1] = { managedComponent->getManagedInstance() };
-							iterFind->second.drawGizmosMethod->invoke(nullptr, params);
+						void* params[1] = { managedInstance };
+						iterFind->second.drawGizmosMethod->invoke(nullptr, params);
 
 
-							GizmoManager::instance().endGizmo();
-						}
+						GizmoManager::instance().endGizmo();
 					}
 					}
 				}
 				}
 			}
 			}

+ 5 - 2
Source/SBansheeEngine/BsScriptGameObjectManager.cpp

@@ -102,13 +102,16 @@ namespace bs
 		return nativeInstance;
 		return nativeInstance;
 	}
 	}
 
 
-	ScriptComponentBase* ScriptGameObjectManager::getBuiltinScriptComponent(const HComponent& component)
+	ScriptComponentBase* ScriptGameObjectManager::getBuiltinScriptComponent(const HComponent& component, bool createNonExisting)
 	{
 	{
 		ScriptComponentBase* scriptComponent = getScriptComponent(component.getInstanceId());
 		ScriptComponentBase* scriptComponent = getScriptComponent(component.getInstanceId());
 		if (scriptComponent != nullptr)
 		if (scriptComponent != nullptr)
 			return scriptComponent;
 			return scriptComponent;
 
 
-		return createBuiltinScriptComponent(component);
+		if(createNonExisting)
+			return createBuiltinScriptComponent(component);
+
+		return nullptr;
 	}
 	}
 
 
 	ScriptManagedComponent* ScriptGameObjectManager::getManagedScriptComponent(const HManagedComponent& component) const
 	ScriptManagedComponent* ScriptGameObjectManager::getManagedScriptComponent(const HManagedComponent& component) const

+ 2 - 2
Source/SBansheeEngine/BsScriptGameObjectManager.h

@@ -61,9 +61,9 @@ namespace bs
 
 
 		/**
 		/**
 		 * Attempts to find the interop object for the specified built-in component. If one cannot be found a new
 		 * Attempts to find the interop object for the specified built-in component. If one cannot be found a new
-		 * script interop object is created.
+		 * script interop object is created if @p createNonExisting is enabled, or returns null otherwise.
 		 */
 		 */
-		ScriptComponentBase* getBuiltinScriptComponent(const HComponent& component);
+		ScriptComponentBase* getBuiltinScriptComponent(const HComponent& component, bool createNonExisting = true);
 
 
 		/**
 		/**
 		 * Attempts to find the interop object for the specified managed component. If one cannot be found null is returned.
 		 * Attempts to find the interop object for the specified managed component. If one cannot be found null is returned.