浏览代码

Added GUISkin C# wrapper and proper C# resource support

Marko Pintera 10 年之前
父节点
当前提交
1c0c2110aa

+ 12 - 0
BansheeEngine/Include/BsGUISkin.h

@@ -27,6 +27,18 @@ namespace BansheeEngine
 		 */
 		 */
 		void setStyle(const String& guiElemType, const GUIElementStyle& style);
 		void setStyle(const String& guiElemType, const GUIElementStyle& style);
 
 
+		/**
+		 * @brief	Removes a style for the specified GUI element type.
+		 *
+		 * @see		GUIElement::getGUITypeName
+		 */
+		void removeStyle(const String& guiElemType);
+
+		/**
+		 * @brief	Returns names of all styles registered on this skin.
+		 */
+		Vector<String> getStyleNames() const;
+
 		/**
 		/**
 		 * @brief	Default style that may be used when no other is available.
 		 * @brief	Default style that may be used when no other is available.
 		 */
 		 */

+ 14 - 0
BansheeEngine/Source/BsGUISkin.cpp

@@ -33,6 +33,20 @@ namespace BansheeEngine
 		mStyles[guiElemType] = style;
 		mStyles[guiElemType] = style;
 	}
 	}
 
 
+	void GUISkin::removeStyle(const String& guiElemType)
+	{
+		mStyles.erase(guiElemType);
+	}
+
+	Vector<String> GUISkin::getStyleNames() const
+	{
+		Vector<String> output;
+		for (auto& pair : mStyles)
+			output.push_back(pair.first);
+
+		return output;
+	}
+
 	HGUISkin GUISkin::create()
 	HGUISkin GUISkin::create()
 	{
 	{
 		GUISkinPtr newSkin = _createPtr();
 		GUISkinPtr newSkin = _createPtr();

+ 1 - 1
MBansheeEditor/ProjectLibrary.cs

@@ -231,7 +231,7 @@ namespace BansheeEditor
     // Note: Must be the same as C++ enum ScriptResourceType
     // Note: Must be the same as C++ enum ScriptResourceType
     public enum ResourceType
     public enum ResourceType
     {
     {
-        Texture, SpriteTexture, Mesh, Font, Shader, Material, Prefab, PlainText, ScriptCode, StringTable, Undefined
+        Texture, SpriteTexture, Mesh, Font, Shader, Material, Prefab, PlainText, ScriptCode, StringTable, GUISkin, Undefined
     }
     }
 
 
     public class LibraryEntry : ScriptObject
     public class LibraryEntry : ScriptObject

+ 4 - 0
MBansheeEngine/GUI/GUIElementStyle.cs

@@ -25,6 +25,10 @@ namespace BansheeEngine
 
 
     public sealed class GUIElementStyle : ScriptObject
     public sealed class GUIElementStyle : ScriptObject
     {
     {
+        // Constructor for runtime use only (dummy parameter to differentiate from the normal constructor)
+        private GUIElementStyle(bool dummy)
+        {  }
+
 		public GUIElementStyle()
 		public GUIElementStyle()
         {
         {
 		    Internal_CreateInstance(this);
 		    Internal_CreateInstance(this);

+ 41 - 1
MBansheeEngine/GUI/GUISkin.cs

@@ -3,14 +3,54 @@ using System.Runtime.CompilerServices;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-    public sealed class GUISkin : ScriptObject
+    public sealed class GUISkin : Resource
     {
     {
+        // Constructor for runtime use only (dummy parameter to differentiate from the normal constructor)
+        private GUISkin(bool dummy)
+        {  }
+
         public GUISkin()
         public GUISkin()
         {
         {
             Internal_CreateInstance(this);
             Internal_CreateInstance(this);
         }
         }
 
 
+        public string[] StyleNames
+        {
+            get { return Internal_GetStyleNames(mCachedPtr); }
+        }
+
+        public GUIElementStyle GetStyle(string name)
+        {
+            return Internal_GetStyle(mCachedPtr, name);
+        }
+
+        public void SetStyle(string name, GUIElementStyle style)
+        {
+            IntPtr stylePtr = IntPtr.Zero;
+            if (style != null)
+                stylePtr = style.GetCachedPtr();
+
+            Internal_SetStyle(mCachedPtr, name, stylePtr);
+        }
+
+        public void RemoveStyle(string name)
+        {
+            Internal_RemoveStyle(mCachedPtr, name);
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CreateInstance(GUISkin instance);
         private static extern void Internal_CreateInstance(GUISkin instance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern GUIElementStyle Internal_GetStyle(IntPtr thisPtr, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetStyle(IntPtr thisPtr, string name, IntPtr style);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_RemoveStyle(IntPtr thisPtr, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern string[] Internal_GetStyleNames(IntPtr thisPtr);
     }
     }
 }
 }

+ 10 - 0
SBansheeEditor/Source/BsGUIResourceField.cpp

@@ -28,6 +28,7 @@
 #include "BsScriptPlainText.h"
 #include "BsScriptPlainText.h"
 #include "BsScriptScriptCode.h"
 #include "BsScriptScriptCode.h"
 #include "BsScriptStringTable.h"
 #include "BsScriptStringTable.h"
+#include "BsScriptGUISkin.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptManagedResource.h"
 #include "BsSelection.h"
 #include "BsSelection.h"
@@ -352,6 +353,15 @@ namespace BansheeEngine
 				}
 				}
 			}
 			}
 				break;
 				break;
+			case TID_GUISkin:
+			{
+				if (ScriptGUISkin::getMetaData()->scriptClass->isSubClassOf(acceptedClass))
+				{
+					setUUID(uuid);
+					found = true;
+				}
+			}
+				break;
 			case TID_ManagedResource:
 			case TID_ManagedResource:
 			{
 			{
 				ManagedResourceMetaDataPtr managedResMetaData = std::static_pointer_cast<ManagedResourceMetaData>(meta->getResourceMetaData());
 				ManagedResourceMetaDataPtr managedResMetaData = std::static_pointer_cast<ManagedResourceMetaData>(meta->getResourceMetaData());

+ 1 - 0
SBansheeEngine/Include/BsManagedSerializableObjectInfo.h

@@ -37,6 +37,7 @@ namespace BansheeEngine
 		PrefabRef,
 		PrefabRef,
 		FontRef,
 		FontRef,
 		StringTableRef,
 		StringTableRef,
+		GUISkinRef,
 		SceneObjectRef,
 		SceneObjectRef,
 		ComponentRef
 		ComponentRef
 	};
 	};

+ 1 - 0
SBansheeEngine/Include/BsScriptEnginePrerequisites.h

@@ -72,6 +72,7 @@ namespace BansheeEngine
 	class ScriptAssemblyManager;
 	class ScriptAssemblyManager;
 	class ScriptHString;
 	class ScriptHString;
 	class ScriptContextMenu;
 	class ScriptContextMenu;
+	class ScriptGUISkin;
 
 
 	typedef GameObjectHandle<ManagedComponent> HManagedComponent;
 	typedef GameObjectHandle<ManagedComponent> HManagedComponent;
 	typedef ResourceHandle<ManagedResource> HManagedResource;
 	typedef ResourceHandle<ManagedResource> HManagedResource;

+ 8 - 5
SBansheeEngine/Include/BsScriptGUIElementStyle.h

@@ -22,7 +22,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Returns the wrapped GUIElementStyle instance.
 		 * @brief	Returns the wrapped GUIElementStyle instance.
 		 */
 		 */
-		GUIElementStyle* getInternalValue() const { return mElementStyle; }
+		GUIElementStyle& getInternalValue() { return mElementStyle; }
+
+		/**
+		 * @brief	Creates a new managed object containing a copy of the provided style.
+		 */
+		static MonoObject* create(const String& name, const GUIElementStyle& style);
 
 
 	private:
 	private:
 		/**
 		/**
@@ -33,11 +38,10 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Creates the interop object referencing an existing style.
 		 * @brief	Creates the interop object referencing an existing style.
 		 */
 		 */
-		ScriptGUIElementStyle(MonoObject* instance, const String& name, GUIElementStyle* externalStyle);
+		ScriptGUIElementStyle(MonoObject* instance, const String& name, const GUIElementStyle& externalStyle);
 
 
 		String mName;
 		String mName;
-		GUIElementStyle* mElementStyle;
-		bool mOwnsStyle;
+		GUIElementStyle mElementStyle;
 
 
 		ScriptFont* mFont;
 		ScriptFont* mFont;
 		ScriptGUIElementStateStyle* mNormal;
 		ScriptGUIElementStateStyle* mNormal;
@@ -53,7 +57,6 @@ namespace BansheeEngine
 		/* 								CLR HOOKS						   		*/
 		/* 								CLR HOOKS						   		*/
 		/************************************************************************/
 		/************************************************************************/
 		static void internal_createInstance(MonoObject* instance, MonoString* name);
 		static void internal_createInstance(MonoObject* instance, MonoString* name);
-		static void internal_createInstanceExternal(MonoObject* instance, MonoString* name, GUIElementStyle* externalStyle);
 		static void internal_addSubStyle(ScriptGUIElementStyle* nativeInstance, MonoString* guiType, MonoString* styleName);
 		static void internal_addSubStyle(ScriptGUIElementStyle* nativeInstance, MonoString* guiType, MonoString* styleName);
 
 
 		static void internal_GetFont(ScriptGUIElementStyle* nativeInstance, MonoObject** value);
 		static void internal_GetFont(ScriptGUIElementStyle* nativeInstance, MonoObject** value);

+ 50 - 0
SBansheeEngine/Include/BsScriptGUISkin.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptResource.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for GUISkin.
+	 */
+	class BS_SCR_BE_EXPORT ScriptGUISkin : public ScriptObject <ScriptGUISkin, ScriptResourceBase>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "GUISkin")
+
+		ScriptGUISkin(MonoObject* instance, const HGUISkin& skin);
+
+		/**
+		 * @copydoc	ScriptResourceBase::getNativeHandle
+		 */
+		HResource getNativeHandle() const override { return mSkin; }
+
+		/**
+		 * @copydoc	ScriptResourceBase::setNativeHandle
+		 */
+		void setNativeHandle(const HResource& resource) override;
+
+		/**
+		 * @brief	Returns the native internal GUI skin resource.
+		 */
+		HGUISkin getGUIUSkinHandle() const { return mSkin; }
+
+	private:
+		/**
+		 * @copydoc	ScriptObjectBase::_onManagedInstanceDeleted
+		 */
+		void _onManagedInstanceDeleted() override;
+
+		HGUISkin mSkin;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_CreateInstance(MonoObject* instance);
+		static MonoObject* internal_GetStyle(ScriptGUISkin* thisPtr, MonoString* name);
+		static void internal_SetStyle(ScriptGUISkin* thisPtr, MonoString* name, ScriptGUIElementStyle* style);
+		static void internal_RemoveStyle(ScriptGUISkin* thisPtr, MonoString* name);
+		static MonoArray* internal_GetStyleNames(ScriptGUISkin* thisPtr);
+	};
+}

+ 1 - 1
SBansheeEngine/Include/BsScriptResource.h

@@ -11,7 +11,7 @@ namespace BansheeEngine
 	// Note: Must be the same as C# enum ScriptResourceType
 	// Note: Must be the same as C# enum ScriptResourceType
 	enum class ScriptResourceType
 	enum class ScriptResourceType
 	{
 	{
-		Texture, SpriteTexture, Mesh, Font, Shader, Material, Prefab, PlainText, ScriptCode, StringTable, Undefined
+		Texture, SpriteTexture, Mesh, Font, Shader, Material, Prefab, PlainText, ScriptCode, StringTable, GUISkin, Undefined
 	};
 	};
 
 
 	/**
 	/**

+ 2 - 0
SBansheeEngine/SBansheeEngine.vcxproj

@@ -279,6 +279,7 @@
     <ClInclude Include="Include\BsScriptGUIProgressBar.h" />
     <ClInclude Include="Include\BsScriptGUIProgressBar.h" />
     <ClInclude Include="Include\BsScriptGUIRenderTexture.h" />
     <ClInclude Include="Include\BsScriptGUIRenderTexture.h" />
     <ClInclude Include="Include\BsScriptGUIScrollArea.h" />
     <ClInclude Include="Include\BsScriptGUIScrollArea.h" />
+    <ClInclude Include="Include\BsScriptGUISkin.h" />
     <ClInclude Include="Include\BsScriptGUISlider.h" />
     <ClInclude Include="Include\BsScriptGUISlider.h" />
     <ClInclude Include="Include\BsScriptGUITexture.h" />
     <ClInclude Include="Include\BsScriptGUITexture.h" />
     <ClInclude Include="Include\BsScriptGUIToggle.h" />
     <ClInclude Include="Include\BsScriptGUIToggle.h" />
@@ -366,6 +367,7 @@
     <ClCompile Include="Source\BsScriptGUIProgressBar.cpp" />
     <ClCompile Include="Source\BsScriptGUIProgressBar.cpp" />
     <ClCompile Include="Source\BsScriptGUIRenderTexture.cpp" />
     <ClCompile Include="Source\BsScriptGUIRenderTexture.cpp" />
     <ClCompile Include="Source\BsScriptGUIScrollArea.cpp" />
     <ClCompile Include="Source\BsScriptGUIScrollArea.cpp" />
+    <ClCompile Include="Source\BsScriptGUISkin.cpp" />
     <ClCompile Include="Source\BsScriptGUISlider.cpp" />
     <ClCompile Include="Source\BsScriptGUISlider.cpp" />
     <ClCompile Include="Source\BsScriptGUITexture.cpp" />
     <ClCompile Include="Source\BsScriptGUITexture.cpp" />
     <ClCompile Include="Source\BsScriptGUIToggle.cpp" />
     <ClCompile Include="Source\BsScriptGUIToggle.cpp" />

+ 6 - 0
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -330,6 +330,9 @@
     <ClInclude Include="Include\BsScriptStringTableManager.h">
     <ClInclude Include="Include\BsScriptStringTableManager.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUISkin.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -599,5 +602,8 @@
     <ClCompile Include="Source\BsScriptStringTableManager.cpp">
     <ClCompile Include="Source\BsScriptStringTableManager.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUISkin.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 28 - 0
SBansheeEngine/Source/BsManagedSerializableField.cpp

@@ -18,6 +18,7 @@
 #include "BsScriptPrefab.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptFont.h"
 #include "BsScriptFont.h"
 #include "BsScriptStringTable.h"
 #include "BsScriptStringTable.h"
+#include "BsScriptGUISkin.h"
 #include "BsScriptSceneObject.h"
 #include "BsScriptSceneObject.h"
 #include "BsScriptComponent.h"
 #include "BsScriptComponent.h"
 #include "BsManagedSerializableObject.h"
 #include "BsManagedSerializableObject.h"
@@ -283,6 +284,18 @@ namespace BansheeEngine
 
 
 				return fieldData;
 				return fieldData;
 			}
 			}
+			case ScriptPrimitiveType::GUISkinRef:
+			{
+				auto fieldData = bs_shared_ptr_new<ManagedSerializableFieldDataResourceRef>();
+
+				if (value != nullptr)
+				{
+					ScriptGUISkin* scriptGUISkin = ScriptGUISkin::toNative(value);
+					fieldData->value = static_resource_cast<GUISkin>(scriptGUISkin->getNativeHandle());
+				}
+
+				return fieldData;
+			}
 			case ScriptPrimitiveType::ManagedResourceRef:
 			case ScriptPrimitiveType::ManagedResourceRef:
 				{
 				{
 					auto fieldData = bs_shared_ptr_new<ManagedSerializableFieldDataResourceRef>();
 					auto fieldData = bs_shared_ptr_new<ManagedSerializableFieldDataResourceRef>();
@@ -730,6 +743,21 @@ namespace BansheeEngine
 				else
 				else
 					return nullptr;
 					return nullptr;
 			}
 			}
+			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::GUISkinRef)
+			{
+				if (value)
+				{
+					HGUISkin guiSkin = static_resource_cast<GUISkin>(value);
+
+					ScriptGUISkin* scriptResource;
+					ScriptResourceManager::instance().getScriptResource(guiSkin, &scriptResource, true);
+
+					if (scriptResource != nullptr)
+						return scriptResource->getManagedInstance();
+				}
+				else
+					return nullptr;
+			}
 			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::ManagedResourceRef)
 			else if (primitiveTypeInfo->mType == ScriptPrimitiveType::ManagedResourceRef)
 			{
 			{
 				if (value)
 				if (value)

+ 3 - 0
SBansheeEngine/Source/BsManagedSerializableObjectInfo.cpp

@@ -23,6 +23,7 @@
 #include "BsScriptPlainText.h"
 #include "BsScriptPlainText.h"
 #include "BsScriptScriptCode.h"
 #include "BsScriptScriptCode.h"
 #include "BsScriptStringTable.h"
 #include "BsScriptStringTable.h"
+#include "BsScriptGUISkin.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptManagedResource.h"
 
 
@@ -186,6 +187,8 @@ namespace BansheeEngine
 			return ScriptFont::getMetaData()->scriptClass->_getInternalClass();
 			return ScriptFont::getMetaData()->scriptClass->_getInternalClass();
 		case ScriptPrimitiveType::StringTableRef:
 		case ScriptPrimitiveType::StringTableRef:
 			return ScriptStringTable::getMetaData()->scriptClass->_getInternalClass();
 			return ScriptStringTable::getMetaData()->scriptClass->_getInternalClass();
+		case ScriptPrimitiveType::GUISkinRef:
+			return ScriptGUISkin::getMetaData()->scriptClass->_getInternalClass();
 		case ScriptPrimitiveType::SceneObjectRef:
 		case ScriptPrimitiveType::SceneObjectRef:
 			return ScriptAssemblyManager::instance().getSceneObjectClass()->_getInternalClass();
 			return ScriptAssemblyManager::instance().getSceneObjectClass()->_getInternalClass();
 		case ScriptPrimitiveType::ComponentRef:
 		case ScriptPrimitiveType::ComponentRef:

+ 7 - 0
SBansheeEngine/Source/BsScriptAssemblyManager.cpp

@@ -20,6 +20,7 @@
 #include "BsScriptPlainText.h"
 #include "BsScriptPlainText.h"
 #include "BsScriptScriptCode.h"
 #include "BsScriptScriptCode.h"
 #include "BsScriptStringTable.h"
 #include "BsScriptStringTable.h"
+#include "BsScriptGUISkin.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptPrefab.h"
 #include "BsMonoUtil.h"
 #include "BsMonoUtil.h"
 #include "BsRTTIType.h"
 #include "BsRTTIType.h"
@@ -350,6 +351,12 @@ namespace BansheeEngine
 				typeInfo->mType = ScriptPrimitiveType::StringTableRef;
 				typeInfo->mType = ScriptPrimitiveType::StringTableRef;
 				return typeInfo;
 				return typeInfo;
 			}
 			}
+			else if (monoClass->isSubClassOf(ScriptGUISkin::getMetaData()->scriptClass))
+			{
+				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
+				typeInfo->mType = ScriptPrimitiveType::GUISkinRef;
+				return typeInfo;
+			}
 			else if(monoClass->isSubClassOf(mSceneObjectClass))
 			else if(monoClass->isSubClassOf(mSceneObjectClass))
 			{
 			{
 				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
 				std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();

+ 57 - 54
SBansheeEngine/Source/BsScriptGUIElementStyle.cpp

@@ -12,14 +12,14 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUIElementStyle::ScriptGUIElementStyle(MonoObject* instance, const String& name)
 	ScriptGUIElementStyle::ScriptGUIElementStyle(MonoObject* instance, const String& name)
-		:ScriptObject(instance), mName(name), mElementStyle(bs_new<GUIElementStyle>()), mFont(nullptr), mOwnsStyle(true), mNormal(nullptr), mHover(nullptr),
+		:ScriptObject(instance), mName(name), mFont(nullptr), mNormal(nullptr), mHover(nullptr),
 		mActive(nullptr), mFocused(nullptr), mNormalOn(nullptr), mHoverOn(nullptr), mActiveOn(nullptr), mFocusedOn(nullptr)
 		mActive(nullptr), mFocused(nullptr), mNormalOn(nullptr), mHoverOn(nullptr), mActiveOn(nullptr), mFocusedOn(nullptr)
 	{
 	{
 
 
 	}
 	}
 
 
-	ScriptGUIElementStyle::ScriptGUIElementStyle(MonoObject* instance, const String& name, GUIElementStyle* externalStyle)
-		:ScriptObject(instance), mName(name), mElementStyle(externalStyle), mFont(nullptr), mOwnsStyle(false), mNormal(nullptr), mHover(nullptr),
+	ScriptGUIElementStyle::ScriptGUIElementStyle(MonoObject* instance, const String& name, const GUIElementStyle& externalStyle)
+		:ScriptObject(instance), mName(name), mElementStyle(externalStyle), mFont(nullptr), mNormal(nullptr), mHover(nullptr),
 		mActive(nullptr), mFocused(nullptr), mNormalOn(nullptr), mHoverOn(nullptr), mActiveOn(nullptr), mFocusedOn(nullptr)
 		mActive(nullptr), mFocused(nullptr), mNormalOn(nullptr), mHoverOn(nullptr), mActiveOn(nullptr), mFocusedOn(nullptr)
 	{
 	{
 
 
@@ -27,8 +27,7 @@ namespace BansheeEngine
 
 
 	ScriptGUIElementStyle::~ScriptGUIElementStyle()
 	ScriptGUIElementStyle::~ScriptGUIElementStyle()
 	{
 	{
-		if(mOwnsStyle)
-			bs_delete(mElementStyle);
+
 	}
 	}
 
 
 	void ScriptGUIElementStyle::initRuntimeData()
 	void ScriptGUIElementStyle::initRuntimeData()
@@ -93,22 +92,26 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetFixedHeight", &ScriptGUIElementStyle::internal_SetFixedHeight);
 		metaData.scriptClass->addInternalCall("Internal_SetFixedHeight", &ScriptGUIElementStyle::internal_SetFixedHeight);
 	}
 	}
 
 
-	void ScriptGUIElementStyle::internal_createInstance(MonoObject* instance, MonoString* name)
+	MonoObject* ScriptGUIElementStyle::create(const String& name, const GUIElementStyle& style)
 	{
 	{
-		char* nativeName = mono_string_to_utf8(name);
-		String styleName(nativeName);
-		free(nativeName);
+		bool dummy = false;
 
 
-		ScriptGUIElementStyle* nativeInstance = new (bs_alloc<ScriptGUIElementStyle>()) ScriptGUIElementStyle(instance, styleName);
+		void* params[1];
+		params[0] = &dummy;;
+
+		MonoObject* instance = metaData.scriptClass->createInstance(params, true);
+
+		ScriptGUIElementStyle* nativeInstance = new (bs_alloc<ScriptGUIElementStyle>()) ScriptGUIElementStyle(instance, name, style);
+		return instance;
 	}
 	}
 
 
-	void ScriptGUIElementStyle::internal_createInstanceExternal(MonoObject* instance, MonoString* name, GUIElementStyle* externalStyle)
+	void ScriptGUIElementStyle::internal_createInstance(MonoObject* instance, MonoString* name)
 	{
 	{
 		char* nativeName = mono_string_to_utf8(name);
 		char* nativeName = mono_string_to_utf8(name);
 		String styleName(nativeName);
 		String styleName(nativeName);
 		free(nativeName);
 		free(nativeName);
 
 
-		ScriptGUIElementStyle* nativeInstance = new (bs_alloc<ScriptGUIElementStyle>()) ScriptGUIElementStyle(instance, styleName, externalStyle);
+		ScriptGUIElementStyle* nativeInstance = new (bs_alloc<ScriptGUIElementStyle>()) ScriptGUIElementStyle(instance, styleName);
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_addSubStyle(ScriptGUIElementStyle* nativeInstance, MonoString* guiType, MonoString* styleName)
 	void ScriptGUIElementStyle::internal_addSubStyle(ScriptGUIElementStyle* nativeInstance, MonoString* guiType, MonoString* styleName)
@@ -116,7 +119,7 @@ namespace BansheeEngine
 		String guiTypeStr = MonoUtil::monoToString(guiType);
 		String guiTypeStr = MonoUtil::monoToString(guiType);
 		String styleNameStr = MonoUtil::monoToString(styleName);
 		String styleNameStr = MonoUtil::monoToString(styleName);
 
 
-		nativeInstance->getInternalValue()->subStyles[guiTypeStr] = styleNameStr;
+		nativeInstance->getInternalValue().subStyles[guiTypeStr] = styleNameStr;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetFont(ScriptGUIElementStyle* nativeInstance, MonoObject** value)
 	void ScriptGUIElementStyle::internal_GetFont(ScriptGUIElementStyle* nativeInstance, MonoObject** value)
@@ -133,58 +136,58 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetFont(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetFont(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptFont* nativeValue = ScriptFont::toNative(value);
 		ScriptFont* nativeValue = ScriptFont::toNative(value);
-		nativeInstance->mElementStyle->font = static_resource_cast<Font>(nativeValue->getNativeHandle());
+		nativeInstance->mElementStyle.font = static_resource_cast<Font>(nativeValue->getNativeHandle());
 		nativeInstance->mFont = nativeValue;
 		nativeInstance->mFont = nativeValue;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetFontSize(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetFontSize(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->fontSize;
+		*value = nativeInstance->mElementStyle.fontSize;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetFontSize(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetFontSize(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->fontSize = value;
+		nativeInstance->mElementStyle.fontSize = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetTextHorzAlign(ScriptGUIElementStyle* nativeInstance, TextHorzAlign*value)
 	void ScriptGUIElementStyle::internal_GetTextHorzAlign(ScriptGUIElementStyle* nativeInstance, TextHorzAlign*value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->textHorzAlign;
+		*value = nativeInstance->mElementStyle.textHorzAlign;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetTextHorzAlign(ScriptGUIElementStyle* nativeInstance, TextHorzAlign value)
 	void ScriptGUIElementStyle::internal_SetTextHorzAlign(ScriptGUIElementStyle* nativeInstance, TextHorzAlign value)
 	{
 	{
-		nativeInstance->mElementStyle->textHorzAlign = value;
+		nativeInstance->mElementStyle.textHorzAlign = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetTextVertAlign(ScriptGUIElementStyle* nativeInstance, TextVertAlign* value)
 	void ScriptGUIElementStyle::internal_GetTextVertAlign(ScriptGUIElementStyle* nativeInstance, TextVertAlign* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->textVertAlign;
+		*value = nativeInstance->mElementStyle.textVertAlign;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetTextVertAlign(ScriptGUIElementStyle* nativeInstance, TextVertAlign value)
 	void ScriptGUIElementStyle::internal_SetTextVertAlign(ScriptGUIElementStyle* nativeInstance, TextVertAlign value)
 	{
 	{
-		nativeInstance->mElementStyle->textVertAlign = value;
+		nativeInstance->mElementStyle.textVertAlign = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetImagePosition(ScriptGUIElementStyle* nativeInstance, GUIImagePosition* value)
 	void ScriptGUIElementStyle::internal_GetImagePosition(ScriptGUIElementStyle* nativeInstance, GUIImagePosition* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->imagePosition;
+		*value = nativeInstance->mElementStyle.imagePosition;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetImagePosition(ScriptGUIElementStyle* nativeInstance, GUIImagePosition value)
 	void ScriptGUIElementStyle::internal_SetImagePosition(ScriptGUIElementStyle* nativeInstance, GUIImagePosition value)
 	{
 	{
-		nativeInstance->mElementStyle->imagePosition = value;
+		nativeInstance->mElementStyle.imagePosition = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetWordWrap(ScriptGUIElementStyle* nativeInstance, bool* value)
 	void ScriptGUIElementStyle::internal_GetWordWrap(ScriptGUIElementStyle* nativeInstance, bool* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->wordWrap;
+		*value = nativeInstance->mElementStyle.wordWrap;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetWordWrap(ScriptGUIElementStyle* nativeInstance, bool value)
 	void ScriptGUIElementStyle::internal_SetWordWrap(ScriptGUIElementStyle* nativeInstance, bool value)
 	{
 	{
-		nativeInstance->mElementStyle->wordWrap = value;
+		nativeInstance->mElementStyle.wordWrap = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetNormal(ScriptGUIElementStyle* nativeInstance, MonoObject** value)
 	void ScriptGUIElementStyle::internal_GetNormal(ScriptGUIElementStyle* nativeInstance, MonoObject** value)
@@ -201,7 +204,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetNormal(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetNormal(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->normal = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.normal = nativeValue->getInternalValue();
 		nativeInstance->mNormal = nativeValue;
 		nativeInstance->mNormal = nativeValue;
 	}
 	}
 
 
@@ -220,7 +223,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetHover(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetHover(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->hover = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.hover = nativeValue->getInternalValue();
 		nativeInstance->mHover = nativeValue;
 		nativeInstance->mHover = nativeValue;
 	}
 	}
 
 
@@ -238,7 +241,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetActive(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetActive(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->active = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.active = nativeValue->getInternalValue();
 		nativeInstance->mActive = nativeValue;
 		nativeInstance->mActive = nativeValue;
 	}
 	}
 
 
@@ -256,7 +259,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetFocused(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetFocused(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->focused = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.focused = nativeValue->getInternalValue();
 		nativeInstance->mFocused = nativeValue;
 		nativeInstance->mFocused = nativeValue;
 	}
 	}
 
 
@@ -274,7 +277,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetNormalOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetNormalOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->normalOn = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.normalOn = nativeValue->getInternalValue();
 		nativeInstance->mNormalOn = nativeValue;
 		nativeInstance->mNormalOn = nativeValue;
 	}
 	}
 
 
@@ -292,7 +295,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetHoverOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetHoverOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->hoverOn = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.hoverOn = nativeValue->getInternalValue();
 		nativeInstance->mHoverOn = nativeValue;
 		nativeInstance->mHoverOn = nativeValue;
 	}
 	}
 
 
@@ -310,7 +313,7 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetActiveOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetActiveOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->activeOn = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.activeOn = nativeValue->getInternalValue();
 		nativeInstance->mActiveOn = nativeValue;
 		nativeInstance->mActiveOn = nativeValue;
 	}
 	}
 
 
@@ -328,117 +331,117 @@ namespace BansheeEngine
 	void ScriptGUIElementStyle::internal_SetFocusedOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	void ScriptGUIElementStyle::internal_SetFocusedOn(ScriptGUIElementStyle* nativeInstance, MonoObject* value)
 	{
 	{
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
 		ScriptGUIElementStateStyle* nativeValue = ScriptGUIElementStateStyle::toNative(value);
-		nativeInstance->mElementStyle->focusedOn = nativeValue->getInternalValue();
+		nativeInstance->mElementStyle.focusedOn = nativeValue->getInternalValue();
 		nativeInstance->mFocusedOn = nativeValue;
 		nativeInstance->mFocusedOn = nativeValue;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetBorder(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	void ScriptGUIElementStyle::internal_GetBorder(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->border;
+		*value = nativeInstance->mElementStyle.border;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetBorder(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	void ScriptGUIElementStyle::internal_SetBorder(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	{
 	{
-		nativeInstance->mElementStyle->border = *value;
+		nativeInstance->mElementStyle.border = *value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetMargins(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	void ScriptGUIElementStyle::internal_GetMargins(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->margins;
+		*value = nativeInstance->mElementStyle.margins;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetMargins(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	void ScriptGUIElementStyle::internal_SetMargins(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	{
 	{
-		nativeInstance->mElementStyle->margins = *value;
+		nativeInstance->mElementStyle.margins = *value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetContentOffset(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	void ScriptGUIElementStyle::internal_GetContentOffset(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->contentOffset;
+		*value = nativeInstance->mElementStyle.contentOffset;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetContentOffset(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	void ScriptGUIElementStyle::internal_SetContentOffset(ScriptGUIElementStyle* nativeInstance, RectOffset* value)
 	{
 	{
-		nativeInstance->mElementStyle->contentOffset = *value;
+		nativeInstance->mElementStyle.contentOffset = *value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetWidth(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetWidth(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->width;
+		*value = nativeInstance->mElementStyle.width;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetWidth(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetWidth(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->width = value;
+		nativeInstance->mElementStyle.width = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetHeight(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetHeight(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->height;
+		*value = nativeInstance->mElementStyle.height;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetHeight(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetHeight(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->height = value;
+		nativeInstance->mElementStyle.height = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetMinWidth(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetMinWidth(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->minWidth;
+		*value = nativeInstance->mElementStyle.minWidth;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetMinWidth(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetMinWidth(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->minWidth = value;
+		nativeInstance->mElementStyle.minWidth = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetMaxWidth(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetMaxWidth(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->maxWidth;
+		*value = nativeInstance->mElementStyle.maxWidth;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetMaxWidth(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetMaxWidth(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->maxWidth = value;
+		nativeInstance->mElementStyle.maxWidth = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetMinHeight(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetMinHeight(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->minHeight;
+		*value = nativeInstance->mElementStyle.minHeight;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetMinHeight(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetMinHeight(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->minHeight = value;
+		nativeInstance->mElementStyle.minHeight = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetMaxHeight(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	void ScriptGUIElementStyle::internal_GetMaxHeight(ScriptGUIElementStyle* nativeInstance, UINT32* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->maxHeight;
+		*value = nativeInstance->mElementStyle.maxHeight;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetMaxHeight(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	void ScriptGUIElementStyle::internal_SetMaxHeight(ScriptGUIElementStyle* nativeInstance, UINT32 value)
 	{
 	{
-		nativeInstance->mElementStyle->maxHeight = value;
+		nativeInstance->mElementStyle.maxHeight = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetFixedWidth(ScriptGUIElementStyle* nativeInstance, bool* value)
 	void ScriptGUIElementStyle::internal_GetFixedWidth(ScriptGUIElementStyle* nativeInstance, bool* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->fixedWidth;
+		*value = nativeInstance->mElementStyle.fixedWidth;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetFixedWidth(ScriptGUIElementStyle* nativeInstance, bool value)
 	void ScriptGUIElementStyle::internal_SetFixedWidth(ScriptGUIElementStyle* nativeInstance, bool value)
 	{
 	{
-		nativeInstance->mElementStyle->fixedWidth = value;
+		nativeInstance->mElementStyle.fixedWidth = value;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_GetFixedHeight(ScriptGUIElementStyle* nativeInstance, bool* value)
 	void ScriptGUIElementStyle::internal_GetFixedHeight(ScriptGUIElementStyle* nativeInstance, bool* value)
 	{
 	{
-		*value = nativeInstance->mElementStyle->fixedHeight;
+		*value = nativeInstance->mElementStyle.fixedHeight;
 	}
 	}
 
 
 	void ScriptGUIElementStyle::internal_SetFixedHeight(ScriptGUIElementStyle* nativeInstance, bool value)
 	void ScriptGUIElementStyle::internal_SetFixedHeight(ScriptGUIElementStyle* nativeInstance, bool value)
 	{
 	{
-		nativeInstance->mElementStyle->fixedHeight = value;
+		nativeInstance->mElementStyle.fixedHeight = value;
 	}
 	}
 }
 }

+ 86 - 0
SBansheeEngine/Source/BsScriptGUISkin.cpp

@@ -0,0 +1,86 @@
+#include "BsScriptGUISkin.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoUtil.h"
+#include "BsGUISkin.h"
+#include "BsScriptResourceManager.h"
+#include "BsScriptGUIElementStyle.h"
+
+namespace BansheeEngine
+{
+	ScriptGUISkin::ScriptGUISkin(MonoObject* instance, const HGUISkin& skin)
+		:ScriptObject(instance), mSkin(skin)
+	{ }
+
+	void ScriptGUISkin::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUISkin::internal_CreateInstance);
+
+		metaData.scriptClass->addInternalCall("Internal_GetStyle", &ScriptGUISkin::internal_GetStyle);
+		metaData.scriptClass->addInternalCall("Internal_SetStyle", &ScriptGUISkin::internal_SetStyle);
+
+		metaData.scriptClass->addInternalCall("Internal_RemoveStyle", &ScriptGUISkin::internal_RemoveStyle);
+		metaData.scriptClass->addInternalCall("Internal_GetStyleNames", &ScriptGUISkin::internal_GetStyleNames);
+	}
+
+	void ScriptGUISkin::internal_CreateInstance(MonoObject* instance)
+	{
+		HGUISkin skin = GUISkin::create();
+
+		ScriptGUISkin* scriptInstance;
+		ScriptResourceManager::instance().createScriptResource(instance, skin, &scriptInstance);
+	}
+
+	MonoObject* ScriptGUISkin::internal_GetStyle(ScriptGUISkin* thisPtr, MonoString* name)
+	{
+		String nativeName = MonoUtil::monoToString(name);
+
+		const GUIElementStyle* style = thisPtr->mSkin->getStyle(nativeName);
+		if (style == nullptr)
+			return nullptr;
+		
+		return ScriptGUIElementStyle::create(nativeName, *style);
+	}
+
+	void ScriptGUISkin::internal_SetStyle(ScriptGUISkin* thisPtr, MonoString* name, ScriptGUIElementStyle* style)
+	{
+		String nativeName = MonoUtil::monoToString(name);
+
+		if (style != nullptr)
+			thisPtr->mSkin->setStyle(nativeName, style->getInternalValue());
+	}
+
+	void ScriptGUISkin::internal_RemoveStyle(ScriptGUISkin* thisPtr, MonoString* name)
+	{
+		String nativeName = MonoUtil::monoToString(name);
+
+		thisPtr->mSkin->removeStyle(nativeName);
+	}
+
+	MonoArray* ScriptGUISkin::internal_GetStyleNames(ScriptGUISkin* thisPtr)
+	{
+		Vector<String> styleNames = thisPtr->mSkin->getStyleNames();
+		UINT32 numNames = (UINT32)styleNames.size();
+
+		ScriptArray output = ScriptArray::create<String>(numNames);
+		for (UINT32 i = 0; i < numNames; i++)
+			output.set(i, styleNames[i]);
+
+		return output.getInternal();
+	}
+
+	void ScriptGUISkin::setNativeHandle(const HResource& resource)
+	{
+		mSkin = static_resource_cast<GUISkin>(resource);
+	}
+
+	void ScriptGUISkin::_onManagedInstanceDeleted()
+	{
+		mManagedInstance = nullptr;
+
+		if (!mRefreshInProgress)
+			ScriptResourceManager::instance().destroyScriptResource(this);
+	}
+}

+ 4 - 0
SBansheeEngine/Source/BsScriptResource.cpp

@@ -49,6 +49,8 @@ namespace BansheeEngine
 			return ScriptResourceType::PlainText;
 			return ScriptResourceType::PlainText;
 		case TID_ScriptCode:
 		case TID_ScriptCode:
 			return ScriptResourceType::ScriptCode;
 			return ScriptResourceType::ScriptCode;
+		case TID_GUISkin:
+			return ScriptResourceType::GUISkin;
 		}
 		}
 
 
 		return ScriptResourceType::Undefined;
 		return ScriptResourceType::Undefined;
@@ -78,6 +80,8 @@ namespace BansheeEngine
 			return TID_PlainText;
 			return TID_PlainText;
 		case ScriptResourceType::ScriptCode:
 		case ScriptResourceType::ScriptCode:
 			return TID_ScriptCode;
 			return TID_ScriptCode;
+		case ScriptResourceType::GUISkin:
+			return TID_GUISkin;
 		}
 		}
 
 
 		return 0;
 		return 0;

+ 7 - 1
SBansheeEngine/Source/BsScriptResourceManager.cpp

@@ -14,6 +14,7 @@
 #include "BsScriptFont.h"
 #include "BsScriptFont.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptPrefab.h"
 #include "BsScriptStringTable.h"
 #include "BsScriptStringTable.h"
+#include "BsScriptGUISkin.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptAssemblyManager.h"
 #include "BsScriptAssemblyManager.h"
 
 
@@ -108,6 +109,8 @@ namespace BansheeEngine
 			return createScriptResource(static_resource_cast<Material>(resourceHandle), (ScriptMaterial**)out);
 			return createScriptResource(static_resource_cast<Material>(resourceHandle), (ScriptMaterial**)out);
 		case TID_Mesh:
 		case TID_Mesh:
 			return createScriptResource(static_resource_cast<Mesh>(resourceHandle), (ScriptMesh**)out);
 			return createScriptResource(static_resource_cast<Mesh>(resourceHandle), (ScriptMesh**)out);
+		case TID_GUISkin:
+			return createScriptResource(static_resource_cast<GUISkin>(resourceHandle), (ScriptGUISkin**)out);
 		case TID_ManagedResource:
 		case TID_ManagedResource:
 			BS_EXCEPT(InternalErrorException, "Managed resources must have a managed instance by default, this call is invalid.")
 			BS_EXCEPT(InternalErrorException, "Managed resources must have a managed instance by default, this call is invalid.")
 				break;
 				break;
@@ -129,6 +132,7 @@ namespace BansheeEngine
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<PlainText>&, ScriptPlainText**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<PlainText>&, ScriptPlainText**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<ScriptCode>&, ScriptScriptCode**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<ScriptCode>&, ScriptScriptCode**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<StringTable>&, ScriptStringTable**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<StringTable>&, ScriptStringTable**);
+	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(const ResourceHandle<GUISkin>&, ScriptGUISkin**);
 
 
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<Texture>&, ScriptTexture2D**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<Texture>&, ScriptTexture2D**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<Texture>&, ScriptTexture3D**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<Texture>&, ScriptTexture3D**);
@@ -142,8 +146,9 @@ namespace BansheeEngine
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<PlainText>&, ScriptPlainText**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<PlainText>&, ScriptPlainText**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<ScriptCode>&, ScriptScriptCode**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<ScriptCode>&, ScriptScriptCode**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<StringTable>&, ScriptStringTable**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<StringTable>&, ScriptStringTable**);
+	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<GUISkin>&, ScriptGUISkin**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<ManagedResource>&, ScriptManagedResource**);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::createScriptResource(MonoObject*, const ResourceHandle<ManagedResource>&, ScriptManagedResource**);
-	
+
 	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, 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, 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, ScriptTextureCube** out, bool create);
@@ -156,6 +161,7 @@ namespace BansheeEngine
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<PlainText>& resourceHandle, ScriptPlainText** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<PlainText>& resourceHandle, ScriptPlainText** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<ScriptCode>& resourceHandle, ScriptScriptCode** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<ScriptCode>& resourceHandle, ScriptScriptCode** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<StringTable>& resourceHandle, ScriptStringTable** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<StringTable>& resourceHandle, ScriptStringTable** out, bool create);
+	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<GUISkin>& resourceHandle, ScriptGUISkin** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<ManagedResource>& resourceHandle, ScriptManagedResource** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<ManagedResource>& resourceHandle, ScriptManagedResource** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Resource>& resourceHandle, ScriptResourceBase** out, bool create);
 	template BS_SCR_BE_EXPORT void ScriptResourceManager::getScriptResource(const ResourceHandle<Resource>& resourceHandle, ScriptResourceBase** out, bool create);
 
 

+ 7 - 1
TODO.txt

@@ -54,8 +54,14 @@ Code quality improvements:
 ----------------------------------------------------------------------
 ----------------------------------------------------------------------
 Polish
 Polish
 
 
+Test:
+ - If level load works by doing main menu -> Load
+  - This should clear existing level
+  - Internal scene objects should remain
+ - If level prefab instantiation works by dragging it from project to scene
+ - When starting drag from hierarchy tree view it tends to select another object (can't repro)
+
 Ribek use:
 Ribek use:
- - Test level save/load (also test hidden & non-saveable scene objects)
  - Hook up color picker to guicolor field
  - Hook up color picker to guicolor field
  - Camera, Renderable, Material, Texture inspector
  - Camera, Renderable, Material, Texture inspector
  - Project create/open window
  - Project create/open window