2
0
Эх сурвалжийг харах

Added separate input callbacks for use in editor only that aren't affected by play-mode state

BearishSun 10 жил өмнө
parent
commit
8d2ecb2432

+ 173 - 0
MBansheeEditor/EditorInput.cs

@@ -0,0 +1,173 @@
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Companion class to <see cref="Input"/> for use in editor only. Supplies events that trigger regardless whether
+    /// game is playing or not (unlike <see cref="Input"/>) which makes them usable for editor only scripts. Pollable
+    /// input should still be used from <see cref="Input"/>.
+    /// </summary>
+    public static class EditorInput
+    {
+        public delegate void ButtonEventDelegate(ButtonEvent ev);
+        public delegate void TextInputEventDelegate(TextInputEvent ev);
+        public delegate void PointerEventDelegate(PointerEvent ev);
+
+        /// <summary>
+        /// Triggered when a button on any device is pressed.
+        /// </summary>
+        public static event ButtonEventDelegate OnButtonDown;
+
+        /// <summary>
+        /// Triggered when a button on any device is released.
+        /// </summary>
+        public static event ButtonEventDelegate OnButtonUp;
+
+        /// <summary>
+        /// Triggered when a textual character is entered.
+        /// </summary>
+        public static event TextInputEventDelegate OnCharInput;
+
+        /// <summary>
+        /// Triggered when the pointing device (mouse, touch) is moved.
+        /// </summary>
+        public static event PointerEventDelegate OnPointerMoved;
+
+        /// <summary>
+        /// Triggered when a button on the pointing device (mouse, touch) is pressed.
+        /// </summary>
+        public static event PointerEventDelegate OnPointerPressed;
+
+        /// <summary>
+        /// Triggered when a button on the pointing device (mouse, touch) is released.
+        /// </summary>
+        public static event PointerEventDelegate OnPointerReleased;
+
+        /// <summary>
+        /// Triggered when a button on the pointing device (mouse, touch) is pressed twice in rappid succession.
+        /// </summary>
+        public static event PointerEventDelegate OnPointerDoubleClick;
+
+        /// <summary>
+        /// Triggered by runtime when a button is pressed.
+        /// </summary>
+        /// <param name="code">Code of the pressed button.</param>
+        /// <param name="deviceIdx">Device the event originated from.</param>
+        private static void Internal_TriggerButtonDown(ButtonCode code, int deviceIdx)
+        {
+            ButtonEvent ev = new ButtonEvent(code, deviceIdx);
+
+            if (OnButtonDown != null)
+                OnButtonDown(ev);
+        }
+
+        /// <summary>
+        /// Triggered by runtime when a button is released.
+        /// </summary>
+        /// <param name="code">Code of the released button.</param>
+        /// <param name="deviceIdx">Device the event originated from.</param>
+        private static void Internal_TriggerButtonUp(ButtonCode code, int deviceIdx)
+        {
+            ButtonEvent ev = new ButtonEvent(code, deviceIdx);
+
+            if (OnButtonUp != null)
+                OnButtonUp(ev);
+        }
+
+        /// <summary>
+        /// Triggered by runtime when character is input.
+        /// </summary>
+        /// <param name="textChar">Code of input character.</param>
+        private static void Internal_TriggerCharInput(int textChar)
+        {
+            TextInputEvent ev = new TextInputEvent(textChar);
+
+            if (OnCharInput != null)
+                OnCharInput(ev);
+        }
+
+        /// <summary>
+        /// Triggers when some pointing device (mouse cursor, touch) moves.
+        /// </summary>
+        /// <param name="screenPos">Screen position where the input event occurred.</param>
+        /// <param name="delta">Change in movement since last sent event.</param>
+        /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type. 
+        ///                      (e.g. move events don't correspond to a button.</param>
+        /// <param name="shift">Is shift button on the keyboard being held down.</param>
+        /// <param name="ctrl">Is control button on the keyboard being held down.</param>
+        /// <param name="alt">Is alt button on the keyboard being held down.</param>
+        /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for 
+        ///                            move events.</param>
+        private static void Internal_TriggerPointerMove(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
+            bool ctrl, bool alt, float scrollAmount)
+        {
+            PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
+
+            if (OnPointerMoved != null)
+                OnPointerMoved(ev);
+        }
+
+        /// <summary>
+        /// Triggers when some pointing device (mouse cursor, touch) button is pressed.
+        /// </summary>
+        /// <param name="screenPos">Screen position where the input event occurred.</param>
+        /// <param name="delta">Change in movement since last sent event.</param>
+        /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type. 
+        ///                      (e.g. move events don't correspond to a button.</param>
+        /// <param name="shift">Is shift button on the keyboard being held down.</param>
+        /// <param name="ctrl">Is control button on the keyboard being held down.</param>
+        /// <param name="alt">Is alt button on the keyboard being held down.</param>
+        /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for 
+        ///                            move events.</param>
+        private static void Internal_TriggerPointerPressed(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
+            bool ctrl, bool alt, float scrollAmount)
+        {
+            PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
+
+            if (OnPointerPressed != null)
+                OnPointerPressed(ev);
+        }
+
+        /// <summary>
+        /// Triggers when some pointing device (mouse cursor, touch) button is released.
+        /// </summary>
+        /// <param name="screenPos">Screen position where the input event occurred.</param>
+        /// <param name="delta">Change in movement since last sent event.</param>
+        /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type. 
+        ///                      (e.g. move events don't correspond to a button.</param>
+        /// <param name="shift">Is shift button on the keyboard being held down.</param>
+        /// <param name="ctrl">Is control button on the keyboard being held down.</param>
+        /// <param name="alt">Is alt button on the keyboard being held down.</param>
+        /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for 
+        ///                            move events.</param>
+        private static void Internal_TriggerPointerReleased(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
+            bool ctrl, bool alt, float scrollAmount)
+        {
+            PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
+
+            if (OnPointerReleased != null)
+                OnPointerReleased(ev);
+        }
+
+        /// <summary>
+        /// Triggers when some pointing device (mouse cursor, touch) button is double clicked.
+        /// </summary>
+        /// <param name="screenPos">Screen position where the input event occurred.</param>
+        /// <param name="delta">Change in movement since last sent event.</param>
+        /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type. 
+        ///                      (e.g. move events don't correspond to a button.</param>
+        /// <param name="shift">Is shift button on the keyboard being held down.</param>
+        /// <param name="ctrl">Is control button on the keyboard being held down.</param>
+        /// <param name="alt">Is alt button on the keyboard being held down.</param>
+        /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for 
+        ///                            move events.</param>
+        private static void Internal_TriggerPointerDoubleClick(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
+            bool ctrl, bool alt, float scrollAmount)
+        {
+            PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
+
+            if (OnPointerDoubleClick != null)
+                OnPointerDoubleClick(ev);
+        }
+    }
+}

+ 66 - 0
MBansheeEditor/EditorVirtualInput.cs

@@ -0,0 +1,66 @@
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Handles virtual input that allows you to receive virtual input events that hide the actual physical input, allowing 
+    /// you to easily change the input keys while being transparent to the external code.
+    /// </summary>
+    /// <summary>
+    /// Companion class to <see cref="VirtualInput"/> for use in editor only. Supplies events that trigger regardless 
+    /// whether game is playing or not (unlike <see cref="VirtualInput"/>) which makes them usable for editor only scripts. 
+    /// Pollable input and other functionality should still be accessed on <see cref="VirtualInput"/>.
+    /// </summary>
+    public static class EditorVirtualInput
+    {
+        public delegate void OnButtonEventDelegate(VirtualButton btn, int deviceIdx);
+
+        /// <summary>
+        /// Triggered when a physical button combination corresponding to a virtual button is pressed.
+        /// </summary>
+        public static event OnButtonEventDelegate OnButtonDown;
+
+        /// <summary>
+        /// Triggered when a physical button combination corresponding to a virtual button is released.
+        /// </summary>
+        public static event OnButtonEventDelegate OnButtonUp;
+
+        /// <summary>
+        /// Triggered every frame while a physical button combination corresponding to a virtual button is being held down.
+        /// </summary>
+        public static event OnButtonEventDelegate OnButtonHeld;
+
+        /// <summary>
+        /// Triggered by the runtime when the virtual button is pressed.
+        /// </summary>
+        /// <param name="button">Virtual button that was pressed.</param>
+        /// <param name="deviceIdx">Index of the device the button was pressed on.</param>
+        private static void Internal_TriggerButtonDown(VirtualButton button, int deviceIdx)
+        {
+            if (OnButtonDown != null)
+                OnButtonDown(button, deviceIdx);
+        }
+
+        /// <summary>
+        /// Triggered by the runtime when the virtual button is released.
+        /// </summary>
+        /// <param name="button">Virtual button that was released.</param>
+        /// <param name="deviceIdx">Index of the device the button was released on.</param>
+        private static void Internal_TriggerButtonUp(VirtualButton button, int deviceIdx)
+        {
+            if (OnButtonUp != null)
+                OnButtonUp(button, deviceIdx);
+        }
+
+        /// <summary>
+        /// Triggered by the runtime every frame while a virtual button is being held down.
+        /// </summary>
+        /// <param name="button">Virtual button that is being held down.</param>
+        /// <param name="deviceIdx">Index of the device the button is being held down on.</param>
+        private static void Internal_TriggerButtonHeld(VirtualButton button, int deviceIdx)
+        {
+            if (OnButtonHeld != null)
+                OnButtonHeld(button, deviceIdx);
+        }
+    };
+}

+ 3 - 3
MBansheeEditor/Library/LibraryDropTarget.cs

@@ -89,9 +89,9 @@ namespace BansheeEditor
             dropTargetOS.OnEnter += DoOnOSDragEnter;
             dropTargetOS.OnLeave += DoOnOSDragLeave;
 
-            Input.OnPointerPressed += Input_OnPointerPressed;
-            Input.OnPointerReleased += Input_OnPointerReleased;
-            Input.OnPointerMoved += Input_OnPointerMoved;
+            EditorInput.OnPointerPressed += Input_OnPointerPressed;
+            EditorInput.OnPointerReleased += Input_OnPointerReleased;
+            EditorInput.OnPointerMoved += Input_OnPointerMoved;
         }
 
         /// <summary>

+ 2 - 0
MBansheeEditor/MBansheeEditor.csproj

@@ -50,6 +50,8 @@
     <Compile Include="DialogBox.cs" />
     <Compile Include="DragDrop.cs" />
     <Compile Include="DropDownWindow.cs" />
+    <Compile Include="EditorInput.cs" />
+    <Compile Include="EditorVirtualInput.cs" />
     <Compile Include="FolderMonitor.cs" />
     <Compile Include="GameWindow.cs" />
     <Compile Include="GUI\GUIDictionaryField.cs" />

+ 1 - 5
MBansheeEngine/VirtualInput.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
+using System.Runtime.CompilerServices;
 
 namespace BansheeEngine
 {

+ 89 - 0
SBansheeEditor/Include/BsScriptEditorInput.h

@@ -0,0 +1,89 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsInputFwd.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for Editor.
+	 */
+	class BS_SCR_BED_EXPORT ScriptEditorInput : public ScriptObject<ScriptEditorInput>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "EditorInput")
+
+		/**
+		 * @brief	Registers internal callbacks. Must be called on scripting system load.
+		 */
+		static void startUp();
+
+		/**
+		 * @brief	Unregisters internal callbacks. Must be called on scripting system shutdown.
+		 */
+		static void shutDown();
+	private:
+		ScriptEditorInput(MonoObject* instance);
+
+		/**
+		 * @brief	Triggered when the specified button is pressed.
+		 */
+		static void onButtonDown(const ButtonEvent& ev);
+
+		/**
+		 * @brief	Triggered when the specified button is released.
+		 */
+		static void onButtonUp(const ButtonEvent& ev);
+
+		/**
+		 * @brief	Triggered when the specified character is entered.
+		 */
+		static void onCharInput(const TextInputEvent& ev);
+
+		/**
+		 * @brief	Triggered when the pointer is moved.
+		 */
+		static void onPointerMoved(const PointerEvent& ev);
+
+		/**
+		 * @brief	Triggered when a pointer button is pressed.
+		 */
+		static void onPointerPressed(const PointerEvent& ev);
+
+		/**
+		 * @brief	Triggered when a pointer button is released.
+		 */
+		static void onPointerReleased(const PointerEvent& ev);
+
+		/**
+		 * @brief	Triggered when a pointer button is double-clicked.
+		 */
+		static void onPointerDoubleClick(const PointerEvent& ev);
+
+		static HEvent OnButtonPressedConn;
+		static HEvent OnButtonReleasedConn;
+		static HEvent OnCharInputConn;
+		static HEvent OnPointerPressedConn;
+		static HEvent OnPointerReleasedConn;
+		static HEvent OnPointerMovedConn;
+		static HEvent OnPointerDoubleClickConn;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+
+		typedef void(__stdcall *OnButtonEventThunkDef) (ButtonCode, UINT32, MonoException**);
+		typedef void(__stdcall *OnCharInputEventThunkDef) (UINT32, MonoException**);
+		typedef void(__stdcall *OnPointerEventThunkDef) (MonoObject*, MonoObject*, PointerEventButton,
+			bool, bool, bool, float, MonoException**);
+
+		static OnButtonEventThunkDef OnButtonPressedThunk;
+		static OnButtonEventThunkDef OnButtonReleasedThunk;
+		static OnCharInputEventThunkDef OnCharInputThunk;
+		static OnPointerEventThunkDef OnPointerPressedThunk;
+		static OnPointerEventThunkDef OnPointerReleasedThunk;
+		static OnPointerEventThunkDef OnPointerMovedThunk;
+		static OnPointerEventThunkDef OnPointerDoubleClickThunk;
+	};
+}

+ 67 - 0
SBansheeEditor/Include/BsScriptEditorVirtualInput.h

@@ -0,0 +1,67 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsInputConfiguration.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for EditorVirtualInput.
+	 */
+	class BS_SCR_BED_EXPORT ScriptEditorVirtualInput : public ScriptObject<ScriptEditorVirtualInput>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEngine", "EditorVirtualInput")
+
+		/**
+		 * @brief	Must be called on library load. Hooks up necessary callbacks.
+		 */
+		static void startUp();
+
+		/**
+		 * @brief	Must be called before library shutdown. Releases previously hooked callbacks.
+		 */
+		static void shutDown();
+	private:
+		/**
+		 * @brief	Triggered whenever a virtual button is pressed.
+		 *
+		 * @param	btn			Virtual button that was pressed.
+		 * @param	deviceIdx	Index of the device the button was pressed on.
+		 */
+		static void onButtonDown(const VirtualButton& btn, UINT32 deviceIdx);
+
+		/**
+		 * @brief	Triggered whenever a virtual button is released.
+		 *
+		 * @param	btn			Virtual button that was released.
+		 * @param	deviceIdx	Index of the device the button was released on.
+		 */
+		static void onButtonUp(const VirtualButton& btn, UINT32 deviceIdx);
+
+		/**
+		 * @brief	Triggered every frame while a virtual button is held down.
+		 *
+		 * @param	btn			Virtual button that is being held.
+		 * @param	deviceIdx	Index of the device the button is held.
+		 */
+		static void onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx);
+
+		static HEvent OnButtonPressedConn;
+		static HEvent OnButtonReleasedConn;
+		static HEvent OnButtonHeldConn;
+
+		ScriptEditorVirtualInput(MonoObject* instance);
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+
+		typedef void(__stdcall *OnButtonEventThunkDef) (MonoObject*, UINT32, MonoException**);
+
+		static OnButtonEventThunkDef OnButtonUpThunk;
+		static OnButtonEventThunkDef OnButtonDownThunk;
+		static OnButtonEventThunkDef OnButtonHeldThunk;
+	};
+}

+ 4 - 0
SBansheeEditor/SBansheeEditor.vcxproj

@@ -262,7 +262,9 @@
     <ClInclude Include="Include\BsScriptCodeEditor.h" />
     <ClInclude Include="Include\BsScriptDragDropManager.h" />
     <ClInclude Include="Include\BsScriptDropDownWindow.h" />
+    <ClInclude Include="Include\BsScriptEditorInput.h" />
     <ClInclude Include="Include\BsScriptEditorTestSuite.h" />
+    <ClInclude Include="Include\BsScriptEditorVirtualInput.h" />
     <ClInclude Include="Include\BsScriptFolderMonitor.h" />
     <ClInclude Include="Include\BsScriptGUIEnumField.h" />
     <ClInclude Include="Include\BsScriptGUIListBoxField.h" />
@@ -321,7 +323,9 @@
     <ClCompile Include="Source\BsGUIResourceField.cpp" />
     <ClCompile Include="Source\BsScriptBrowseDialog.cpp" />
     <ClCompile Include="Source\BsScriptDropDownWindow.cpp" />
+    <ClCompile Include="Source\BsScriptEditorInput.cpp" />
     <ClCompile Include="Source\BsScriptEditorTestSuite.cpp" />
+    <ClCompile Include="Source\BsScriptEditorVirtualInput.cpp" />
     <ClCompile Include="Source\BsScriptFolderMonitor.cpp" />
     <ClCompile Include="Source\BsScriptGUIEnumField.cpp" />
     <ClCompile Include="Source\BsScriptGUIListBoxField.cpp" />

+ 12 - 0
SBansheeEditor/SBansheeEditor.vcxproj.filters

@@ -186,6 +186,12 @@
     <ClInclude Include="Include\BsToolbarItemManager.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptEditorInput.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptEditorVirtualInput.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptEditorPlugin.cpp">
@@ -359,5 +365,11 @@
     <ClCompile Include="Source\BsToolbarItemManager.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptEditorInput.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptEditorVirtualInput.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 6 - 0
SBansheeEditor/Source/BsEditorScriptManager.cpp

@@ -21,6 +21,8 @@
 #include "BsScriptManager.h"
 #include "BsScriptEditorApplication.h"
 #include "BsScriptInspectorUtility.h"
+#include "BsScriptEditorInput.h"
+#include "BsScriptEditorVirtualInput.h"
 
 namespace BansheeEngine
 {
@@ -35,6 +37,8 @@ namespace BansheeEngine
 		loadMonoTypes();
 		ScriptAssemblyManager::instance().loadAssemblyInfo(EDITOR_ASSEMBLY);
 
+		ScriptEditorInput::startUp();
+		ScriptEditorVirtualInput::startUp();
 		ScriptEditorApplication::startUp();
 		ScriptHandleSliderManager::startUp();
 		ScriptGizmoManager::startUp(ScriptAssemblyManager::instance());
@@ -76,6 +80,8 @@ namespace BansheeEngine
 		HandleManager::shutDown();
 		ScriptGizmoManager::shutDown();
 		ScriptEditorApplication::shutDown();
+		ScriptEditorVirtualInput::shutDown();
+		ScriptEditorInput::shutDown();
 	}
 
 	void EditorScriptManager::update()

+ 117 - 0
SBansheeEditor/Source/BsScriptEditorInput.cpp

@@ -0,0 +1,117 @@
+#include "BsScriptEditorInput.h"
+#include "BsMonoManager.h"
+#include "BsMonoClass.h"
+#include "BsMonoMethod.h"
+#include "BsMonoUtil.h"
+#include "BsDebug.h"
+#include "BsInput.h"
+#include "BsScriptVector2I.h"
+
+namespace BansheeEngine
+{
+	ScriptEditorInput::OnButtonEventThunkDef ScriptEditorInput::OnButtonPressedThunk;
+	ScriptEditorInput::OnButtonEventThunkDef ScriptEditorInput::OnButtonReleasedThunk;
+	ScriptEditorInput::OnCharInputEventThunkDef ScriptEditorInput::OnCharInputThunk;
+	ScriptEditorInput::OnPointerEventThunkDef ScriptEditorInput::OnPointerPressedThunk;
+	ScriptEditorInput::OnPointerEventThunkDef ScriptEditorInput::OnPointerReleasedThunk;
+	ScriptEditorInput::OnPointerEventThunkDef ScriptEditorInput::OnPointerMovedThunk;
+	ScriptEditorInput::OnPointerEventThunkDef ScriptEditorInput::OnPointerDoubleClickThunk;
+
+	HEvent ScriptEditorInput::OnButtonPressedConn;
+	HEvent ScriptEditorInput::OnButtonReleasedConn;
+	HEvent ScriptEditorInput::OnCharInputConn;
+	HEvent ScriptEditorInput::OnPointerPressedConn;
+	HEvent ScriptEditorInput::OnPointerReleasedConn;
+	HEvent ScriptEditorInput::OnPointerMovedConn;
+	HEvent ScriptEditorInput::OnPointerDoubleClickConn;
+
+	ScriptEditorInput::ScriptEditorInput(MonoObject* instance)
+		:ScriptObject(instance)
+	{ }
+
+	void ScriptEditorInput::initRuntimeData()
+	{
+		OnButtonPressedThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonDown", "ButtonCode,int")->getThunk();
+		OnButtonReleasedThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonUp", "ButtonCode,int")->getThunk();
+		OnCharInputThunk = (OnCharInputEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerCharInput", "int")->getThunk();
+		OnPointerPressedThunk = (OnPointerEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerPointerPressed", "Vector2I,Vector2I,PointerButton,bool,bool,bool,single")->getThunk();
+		OnPointerReleasedThunk = (OnPointerEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerPointerReleased", "Vector2I,Vector2I,PointerButton,bool,bool,bool,single")->getThunk();
+		OnPointerMovedThunk = (OnPointerEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerPointerMove", "Vector2I,Vector2I,PointerButton,bool,bool,bool,single")->getThunk();
+		OnPointerDoubleClickThunk = (OnPointerEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerPointerDoubleClick", "Vector2I,Vector2I,PointerButton,bool,bool,bool,single")->getThunk();
+	}
+
+	void ScriptEditorInput::startUp()
+	{
+		Input& input = Input::instance();
+
+		OnButtonPressedConn = input.onButtonDown.connect(&ScriptEditorInput::onButtonDown);
+		OnButtonReleasedConn = input.onButtonUp.connect(&ScriptEditorInput::onButtonUp);
+		OnCharInputConn = input.onCharInput.connect(&ScriptEditorInput::onCharInput);
+		OnPointerPressedConn = input.onPointerPressed.connect(&ScriptEditorInput::onPointerPressed);
+		OnPointerReleasedConn = input.onPointerReleased.connect(&ScriptEditorInput::onPointerReleased);
+		OnPointerMovedConn = input.onPointerMoved.connect(&ScriptEditorInput::onPointerMoved);
+		OnPointerDoubleClickConn = input.onPointerDoubleClick.connect(&ScriptEditorInput::onPointerDoubleClick);
+	}
+
+	void ScriptEditorInput::shutDown()
+	{
+		OnButtonPressedConn.disconnect();
+		OnButtonReleasedConn.disconnect();
+		OnCharInputConn.disconnect();
+		OnPointerPressedConn.disconnect();
+		OnPointerReleasedConn.disconnect();
+		OnPointerMovedConn.disconnect();
+		OnPointerDoubleClickConn.disconnect();
+	}
+
+	void ScriptEditorInput::onButtonDown(const ButtonEvent& ev)
+	{
+		MonoUtil::invokeThunk(OnButtonPressedThunk, ev.buttonCode, ev.deviceIdx);
+	}
+
+	void ScriptEditorInput::onButtonUp(const ButtonEvent& ev)
+	{
+		MonoUtil::invokeThunk(OnButtonReleasedThunk, ev.buttonCode, ev.deviceIdx);
+	}
+
+	void ScriptEditorInput::onCharInput(const TextInputEvent& ev)
+	{
+		MonoUtil::invokeThunk(OnCharInputThunk, ev.textChar);
+	}
+
+	void ScriptEditorInput::onPointerMoved(const PointerEvent& ev)
+	{
+		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
+		MonoObject* delta = ScriptVector2I::box(ev.delta);
+
+		MonoUtil::invokeThunk(OnPointerMovedThunk, screenPos, delta,
+			ev.button, ev.shift, ev.control, ev.alt, ev.mouseWheelScrollAmount);
+	}
+
+	void ScriptEditorInput::onPointerPressed(const PointerEvent& ev)
+	{
+		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
+		MonoObject* delta = ScriptVector2I::box(ev.delta);
+
+		MonoUtil::invokeThunk(OnPointerPressedThunk, screenPos, delta,
+			ev.button, ev.shift, ev.control, ev.alt, ev.mouseWheelScrollAmount);
+	}
+
+	void ScriptEditorInput::onPointerReleased(const PointerEvent& ev)
+	{
+		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
+		MonoObject* delta = ScriptVector2I::box(ev.delta);
+
+		MonoUtil::invokeThunk(OnPointerReleasedThunk, screenPos, delta,
+			ev.button, ev.shift, ev.control, ev.alt, ev.mouseWheelScrollAmount);
+	}
+
+	void ScriptEditorInput::onPointerDoubleClick(const PointerEvent& ev)
+	{
+		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
+		MonoObject* delta = ScriptVector2I::box(ev.delta);
+
+		MonoUtil::invokeThunk(OnPointerDoubleClickThunk, screenPos, delta,
+			ev.button, ev.shift, ev.control, ev.alt, ev.mouseWheelScrollAmount);
+	}
+}

+ 63 - 0
SBansheeEditor/Source/BsScriptEditorVirtualInput.cpp

@@ -0,0 +1,63 @@
+#include "BsScriptEditorVirtualInput.h"
+#include "BsMonoManager.h"
+#include "BsMonoClass.h"
+#include "BsMonoMethod.h"
+#include "BsMonoUtil.h"
+#include "BsVirtualInput.h"
+#include "BsScriptVirtualButton.h"
+
+namespace BansheeEngine
+{
+	ScriptEditorVirtualInput::OnButtonEventThunkDef ScriptEditorVirtualInput::OnButtonUpThunk;
+	ScriptEditorVirtualInput::OnButtonEventThunkDef ScriptEditorVirtualInput::OnButtonDownThunk;
+	ScriptEditorVirtualInput::OnButtonEventThunkDef ScriptEditorVirtualInput::OnButtonHeldThunk;
+
+	HEvent ScriptEditorVirtualInput::OnButtonPressedConn;
+	HEvent ScriptEditorVirtualInput::OnButtonReleasedConn;
+	HEvent ScriptEditorVirtualInput::OnButtonHeldConn;
+
+	ScriptEditorVirtualInput::ScriptEditorVirtualInput(MonoObject* instance)
+		:ScriptObject(instance)
+	{ }
+
+	void ScriptEditorVirtualInput::initRuntimeData()
+	{
+		OnButtonUpThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonDown", "VirtualButton,int")->getThunk();
+		OnButtonDownThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonUp", "VirtualButton,int")->getThunk();
+		OnButtonHeldThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonHeld", "VirtualButton,int")->getThunk();
+	}
+
+	void ScriptEditorVirtualInput::startUp()
+	{
+		VirtualInput& input = VirtualInput::instance();
+
+		OnButtonPressedConn = input.onButtonDown.connect(&ScriptEditorVirtualInput::onButtonDown);
+		OnButtonReleasedConn = input.onButtonUp.connect(&ScriptEditorVirtualInput::onButtonUp);
+		OnButtonHeldConn = input.onButtonHeld.connect(&ScriptEditorVirtualInput::onButtonHeld);
+	}
+
+	void ScriptEditorVirtualInput::shutDown()
+	{
+		OnButtonPressedConn.disconnect();
+		OnButtonReleasedConn.disconnect();
+		OnButtonHeldConn.disconnect();
+	}
+
+	void ScriptEditorVirtualInput::onButtonDown(const VirtualButton& btn, UINT32 deviceIdx)
+	{
+		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
+		MonoUtil::invokeThunk(OnButtonDownThunk, virtualButton, deviceIdx);
+	}
+
+	void ScriptEditorVirtualInput::onButtonUp(const VirtualButton& btn, UINT32 deviceIdx)
+	{
+		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
+		MonoUtil::invokeThunk(OnButtonUpThunk, virtualButton, deviceIdx);
+	}
+
+	void ScriptEditorVirtualInput::onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx)
+	{
+		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
+		MonoUtil::invokeThunk(OnButtonHeldThunk, virtualButton, deviceIdx);
+	}
+}

+ 22 - 1
SBansheeEngine/Source/BsScriptInput.cpp

@@ -3,9 +3,9 @@
 #include "BsMonoClass.h"
 #include "BsMonoMethod.h"
 #include "BsMonoUtil.h"
-#include "BsDebug.h"
 #include "BsInput.h"
 #include "BsScriptVector2I.h"
+#include "BsPlayInEditorManager.h"
 
 namespace BansheeEngine
 {
@@ -77,21 +77,33 @@ namespace BansheeEngine
 
 	void ScriptInput::onButtonDown(const ButtonEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoUtil::invokeThunk(OnButtonPressedThunk, ev.buttonCode, ev.deviceIdx);
 	}
 
 	void ScriptInput::onButtonUp(const ButtonEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoUtil::invokeThunk(OnButtonReleasedThunk, ev.buttonCode, ev.deviceIdx);
 	}
 
 	void ScriptInput::onCharInput(const TextInputEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoUtil::invokeThunk(OnCharInputThunk, ev.textChar);
 	}
 
 	void ScriptInput::onPointerMoved(const PointerEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
 		MonoObject* delta = ScriptVector2I::box(ev.delta);
 
@@ -101,6 +113,9 @@ namespace BansheeEngine
 
 	void ScriptInput::onPointerPressed(const PointerEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
 		MonoObject* delta = ScriptVector2I::box(ev.delta);
 
@@ -110,6 +125,9 @@ namespace BansheeEngine
 
 	void ScriptInput::onPointerReleased(const PointerEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
 		MonoObject* delta = ScriptVector2I::box(ev.delta);
 
@@ -119,6 +137,9 @@ namespace BansheeEngine
 
 	void ScriptInput::onPointerDoubleClick(const PointerEvent& ev)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* screenPos = ScriptVector2I::box(ev.screenPos);
 		MonoObject* delta = ScriptVector2I::box(ev.delta);
 

+ 10 - 1
SBansheeEngine/Source/BsScriptVirtualInput.cpp

@@ -3,10 +3,10 @@
 #include "BsMonoClass.h"
 #include "BsMonoMethod.h"
 #include "BsMonoUtil.h"
-#include "BsDebug.h"
 #include "BsVirtualInput.h"
 #include "BsScriptVirtualButton.h"
 #include "BsScriptInputConfiguration.h"
+#include "BsPlayInEditorManager.h"
 
 namespace BansheeEngine
 {
@@ -54,18 +54,27 @@ namespace BansheeEngine
 
 	void ScriptVirtualInput::onButtonDown(const VirtualButton& btn, UINT32 deviceIdx)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
 		MonoUtil::invokeThunk(OnButtonDownThunk, virtualButton, deviceIdx);
 	}
 
 	void ScriptVirtualInput::onButtonUp(const VirtualButton& btn, UINT32 deviceIdx)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
 		MonoUtil::invokeThunk(OnButtonUpThunk, virtualButton, deviceIdx);
 	}
 
 	void ScriptVirtualInput::onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx)
 	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
 		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
 		MonoUtil::invokeThunk(OnButtonHeldThunk, virtualButton, deviceIdx);
 	}