Просмотр исходного кода

Fixed GUITextureField so its value change is properly triggered

BearishSun 10 лет назад
Родитель
Сommit
c89c1b6107

+ 0 - 8
BansheeEditor/Include/BsEditorApplication.h

@@ -174,14 +174,6 @@ namespace BansheeEngine
 		WString mProjectName;
 
 		DynLib* mSBansheeEditorPlugin;
-
-		// DEBUG ONLY
-
-		HShader mTestShader;
-		HMaterial mTestMaterial;
-		HTexture mTestTexRef;
-		HMesh mDbgMeshRef;
-		HSceneObject mTestModelGO;
 	};
 
 	/**

+ 0 - 94
BansheeEditor/Source/BsEditorApplication.cpp

@@ -28,26 +28,7 @@
 #include "BsCoreSceneManager.h"
 
 // DEBUG ONLY
-#include "BsFileSystem.h"
-#include "BsSceneObject.h"
-#include "BsGpuProgram.h"
 #include "BsShader.h"
-#include "BsTexture.h"
-#include "BsMaterial.h"
-#include "BsTechnique.h"
-#include "BsPass.h"
-#include "BsCRenderable.h"
-#include "BsFolderMonitor.h"
-#include "BsCCamera.h"
-#include "BsCGUIWidget.h"
-#include "BsGUIButton.h"
-#include "BsGUILayout.h"
-#include "BsEvent.h"
-#include "BsCoreRenderer.h"
-#include "BsMesh.h"
-#include "BsMath.h"
-#include "BsDebug.h"
-#include "BsInput.h"
 
 namespace BansheeEngine
 {
@@ -77,26 +58,6 @@ namespace BansheeEngine
 
 	EditorApplication::~EditorApplication()
 	{
-#if BS_DEBUG_MODE
-		/************************************************************************/
-		/* 								DEBUG CODE                      		*/
-		/************************************************************************/
-
-		gResources().unload(mTestTexRef);
-		gResources().unload(mDbgMeshRef);
-		gResources().unload(mTestShader);
-		gResources().unload(mTestMaterial);
-
-		mTestMaterial = nullptr;
-		mTestTexRef = nullptr;
-		mDbgMeshRef = nullptr;
-		mTestShader = nullptr;
-
-		/************************************************************************/
-		/* 							END DEBUG CODE                      		*/
-		/************************************************************************/
-#endif
-
 		ProjectLibrary::shutDown();
 		BuiltinEditorResources::shutDown();
 	}
@@ -149,63 +110,8 @@ namespace BansheeEngine
 		ScriptManager::instance().initialize();
 
 #if BS_DEBUG_MODE
-		/************************************************************************/
-		/* 								DEBUG CODE                      		*/
-		/************************************************************************/
 		HShader dummyParsedShader = Importer::instance().import<Shader>(RUNTIME_DATA_PATH + "Raw\\Engine\\Shaders\\TestFX.bsl");
 		assert(dummyParsedShader != nullptr); // Ad hoc unit test
-
-		RenderAPICore* renderAPI = RenderAPICore::instancePtr();
-
-		mTestModelGO = SceneObject::create("TestMesh");
-		HRenderable testRenderable = mTestModelGO->addComponent<CRenderable>();
-
-		Path testShaderLoc = RUNTIME_DATA_PATH + L"Test.bsl";;
-
-		mTestShader = Importer::instance().import<Shader>(testShaderLoc);
-
-		gResources().save(mTestShader, L"E:\\testShader.asset", true);
-		gResources().unload(mTestShader);
-		mTestShader = gResources().load<Shader>(L"E:\\testShader.asset");
-
-		mTestMaterial = Material::create(mTestShader);
-
-		mTestTexRef = static_resource_cast<Texture>(Importer::instance().import(RUNTIME_DATA_PATH + L"Examples\\Dragon.tga"));
-		mDbgMeshRef = static_resource_cast<Mesh>(Importer::instance().import(RUNTIME_DATA_PATH + L"Examples\\Dragon.fbx"));
-
-		gResources().save(mTestTexRef, L"E:\\ExportTest.tex", true);
-		gResources().save(mDbgMeshRef, L"E:\\ExportMesh.mesh", true);
-
-		gResources().unload(mTestTexRef);
-		gResources().unload(mDbgMeshRef);
-
-		mTestTexRef = static_resource_cast<Texture>(gResources().loadAsync(L"E:\\ExportTest.tex"));
-		mDbgMeshRef = static_resource_cast<Mesh>(gResources().loadAsync(L"E:\\ExportMesh.mesh"));
-
-		mDbgMeshRef.blockUntilLoaded();
-		mDbgMeshRef->blockUntilCoreInitialized();
-		mTestTexRef.blockUntilLoaded();
-		mTestTexRef->blockUntilCoreInitialized();
-
-		mTestMaterial->setTexture("tex", mTestTexRef);
-		gResources().save(mTestShader, L"E:\\ExportShader.asset", true);
-		gResources().save(mTestMaterial, L"E:\\ExportMaterial.mat", true);
-
-		gResources().unload(mTestMaterial);
-		gResources().unload(mTestShader);
-
-		mTestShader = gResources().load<Shader>(L"E:\\ExportShader.asset");
-		mTestMaterial = gResources().load<Material>(L"E:\\ExportMaterial.mat");
-
-		testRenderable->setMesh(mDbgMeshRef);
-		testRenderable->setMaterial(0, mTestMaterial);
-
-		HSceneObject clone = mTestModelGO->clone();
-		mTestModelGO->destroy();
-
-		/************************************************************************/
-		/* 							END DEBUG CODE                      		*/
-		/************************************************************************/
 #endif
 	}
 

+ 2 - 2
SBansheeEditor/Include/BsScriptGUITextureField.h

@@ -18,9 +18,9 @@ namespace BansheeEngine
 		 * @brief	Triggered when the value in the native texture field changes.
 		 *
 		 * @param	instance	Managed GUITextureField instance.
-		 * @param	newValue	New texture.
+		 * @param	newValue	UUID of thew new texture.
 		 */
-		static void onChanged(MonoObject* instance, const HTexture& newValue);
+		static void onChanged(MonoObject* instance, const String& newUUID);
 
 		/**
 		 * @brief	Retrieves a managed instance of the specified native texture.

+ 10 - 12
SBansheeEditor/Source/BsScriptGUITextureField.cpp

@@ -16,6 +16,7 @@
 #include "BsScriptGUIContent.h"
 #include "BsScriptTexture.h"
 #include "BsScriptResourceManager.h"
+#include "BsResources.h"
 
 using namespace std::placeholders;
 
@@ -93,25 +94,22 @@ namespace BansheeEngine
 		textureField->setTint(color);
 	}
 
-	void ScriptGUITextureField::onChanged(MonoObject* instance, const HTexture& newValue)
+	void ScriptGUITextureField::onChanged(MonoObject* instance, const String& newUUID)
 	{
-		MonoObject* managedObj = nativeToManagedResource(newValue);
+		HTexture texture = static_resource_cast<Texture>(gResources().loadFromUUID(newUUID));
+
+		MonoObject* managedObj = nativeToManagedResource(texture);
 		MonoUtil::invokeThunk(onChangedThunk, instance, managedObj);
 	}
 
 	MonoObject* ScriptGUITextureField::nativeToManagedResource(const HTexture& instance)
 	{
 		if (instance == nullptr)
-		{
 			return nullptr;
-		}
-		else
-		{
-			ScriptResourceBase* scriptResource = ScriptResourceManager::instance().getScriptResource(instance.getUUID());
-			if (scriptResource == nullptr)
-				return nullptr;
-			else
-				return scriptResource->getManagedInstance();
-		}
+
+		ScriptTextureBase* scriptResource = nullptr;
+		ScriptResourceManager::instance().getScriptResource(instance, &scriptResource, true);
+
+		return scriptResource->getManagedInstance();
 	}
 }

+ 15 - 0
SBansheeEngine/Source/BsScriptResourceManager.cpp

@@ -77,6 +77,19 @@ namespace BansheeEngine
 		createScriptResource(monoInstance, resourceHandle, out);
 	}
 
+	template<>
+	void ScriptResourceManager::createScriptResource(const ResourceHandle<Texture>& resourceHandle, ScriptTextureBase** out)
+	{
+		TextureType type = resourceHandle->getProperties().getTextureType();
+
+		if (type == TEX_TYPE_3D)
+			return createScriptResource(resourceHandle, (ScriptTexture3D**)out);
+		else if (type == TEX_TYPE_CUBE_MAP)
+			return createScriptResource(resourceHandle, (ScriptTextureCube**)out);
+		else
+			return createScriptResource(resourceHandle, (ScriptTexture2D**)out);
+	}
+
 	template<>
 	void ScriptResourceManager::createScriptResource(const HResource& resourceHandle, ScriptResourceBase** out)
 	{
@@ -132,6 +145,7 @@ namespace BansheeEngine
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<Texture>&, ScriptTexture2D**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<Texture>&, ScriptTexture3D**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<Texture>&, ScriptTextureCube**);
+	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<Texture>&, ScriptTextureBase**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<SpriteTexture>&, ScriptSpriteTexture**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<Mesh>&, ScriptMesh**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<Material>&, ScriptMaterial**);
@@ -161,6 +175,7 @@ namespace BansheeEngine
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Texture>& resourceHandle, ScriptTexture2D** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Texture>& resourceHandle, ScriptTexture3D** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Texture>& resourceHandle, ScriptTextureCube** out, bool create);
+	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Texture>& resourceHandle, ScriptTextureBase** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<SpriteTexture>& resourceHandle, ScriptSpriteTexture** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Mesh>& resourceHandle, ScriptMesh** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Material>& resourceHandle, ScriptMaterial** out, bool create);

+ 1 - 1
TODO.txt

@@ -66,12 +66,12 @@ Optional:
   - Test & finalize undo/redo system
  - Add "focus on object" key (F) - animate it: rotate camera towards then speed towards while zooming in (+ menu entry)
  - Ortographic camera views (+ gizmo in scene view corner that shows camera orientation)
- - Drag to select in scene view
  - MenuBar - will likely need a way to mark elements as disabled when not appropriate (e.g. no "frame selected unless scene is focused")
    - Likely use a user-provided callback to trigger when populating the menus (I already added a callback to MenuItem, just need to implement it)
  - Need to list all script components in the Components menu
 
 Seriously optional:
+ - Drag to select in scene view
  - Automatically generate readable inspector names and add [Name] attribute that allows custom naming
  - Add Range[] attribute to C# that forces a float/int to be displayed as a slider
  - GUI tabbing to switch between elements