marco.bellan пре 9 година
родитељ
комит
d0853cb785

+ 1 - 1
Source/MBansheeEditor/Windows/Scene/SceneCamera.cs

@@ -271,7 +271,7 @@ namespace BansheeEditor
             }
 
             SceneWindow sceneWindow = EditorWindow.GetWindow<SceneWindow>();
-            if (sceneWindow.Active && sceneWindow.HasFocus)
+            if ((sceneWindow.Active && sceneWindow.HasFocus) || sceneWindow.IsPointerHovering)
             {
                 Rect2I bounds = sceneWindow.Bounds;
 

+ 5 - 6
Source/MBansheeEditor/Windows/Scene/SceneSelection.cs

@@ -77,13 +77,12 @@ namespace BansheeEditor
         /// Returns the 3D position of an object under the cursor, along with the surface normal in that point.
         /// </summary>
         /// <param name="pointerPos">Position of the pointer relative to the scene camera viewport.</param>
+        /// <param name="data">A struct containing the position on the object surface and the normal in that point.</param>
         /// <param name="ignoreSceneObjects">An array of renderables that should not be rendered during scene picking.</param>
-        /// <returns>The position on the object surface and the normal in that point.</returns>
-        internal SnapData Snap(Vector2I pointerPos, SceneObject[] ignoreSceneObjects = null)
+        /// <returns>The object the pointer is snapping to.</returns>
+        internal SceneObject Snap(Vector2I pointerPos, out SnapData data, SceneObject[] ignoreSceneObjects = null)
         {
-            SnapData data;
-            Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
-            return data;
+            return Internal_Snap(mCachedPtr, ref pointerPos, out data, ignoreSceneObjects);
         }
 
         [MethodImpl(MethodImplOptions.InternalCall)]
@@ -99,7 +98,7 @@ namespace BansheeEditor
         private static extern void Internal_PickObjects(IntPtr thisPtr, ref Vector2I pointerPos, ref Vector2I extents, bool controlHeld, SceneObject[] ignoreRenderables);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
+        private static extern SceneObject Internal_Snap(IntPtr thisPtr, ref Vector2I pointerPos, out SnapData data, SceneObject[] ignoreRenderables);
     }
 
     /** @} */

+ 11 - 33
Source/MBansheeEditor/Windows/Scene/SceneWindow.cs

@@ -24,6 +24,8 @@ namespace BansheeEditor
         internal const string ScaleToolBinding = "ScaleTool";
         internal const string FrameBinding = "SceneFrame";
 
+        public SceneSelection sceneSelection;
+
         private const int HeaderHeight = 20;
         private const float DefaultPlacementDepth = 5.0f;
         private static readonly Color ClearColor = new Color(83.0f/255.0f, 83.0f/255.0f, 83.0f/255.0f);
@@ -41,7 +43,6 @@ namespace BansheeEditor
 
         private GUIRenderTexture renderTextureGUI;
         private SceneGrid sceneGrid;
-        private SceneSelection sceneSelection;
         private SceneGizmos sceneGizmos;
         private SceneHandles sceneHandles;
 
@@ -436,7 +437,7 @@ namespace BansheeEditor
         /// <param name="screenPos">Coordinates relative to the screen.</param>
         /// <param name="scenePos">Output coordinates relative to the scene view texture.</param>
         /// <returns>True if the coordinates are within the scene view texture, false otherwise.</returns>
-        private bool ScreenToScenePos(Vector2I screenPos, out Vector2I scenePos)
+        public bool ScreenToScenePos(Vector2I screenPos, out Vector2I scenePos)
         {
             scenePos = screenPos;
             Vector2I windowPos = ScreenToWindowPos(screenPos);
@@ -455,7 +456,6 @@ namespace BansheeEditor
 
         private void OnEditorUpdate()
         {
-
             if (HasFocus)
             {
                 if (!Input.IsPointerButtonHeld(PointerButton.Right))
@@ -519,9 +519,7 @@ namespace BansheeEditor
             {
                 if (DragDrop.DropInProgress)
                 {
-                    #region Drop and select
                     dragActive = false;
-                    Debug.Log("hey");
                     if (draggedSO != null)
                     {
                         Selection.SceneObject = draggedSO;
@@ -529,7 +527,6 @@ namespace BansheeEditor
                     }
                     
                     draggedSO = null;
-                    #endregion
                 }
                 else
                 {
@@ -588,12 +585,10 @@ namespace BansheeEditor
 
                     if (draggedSO != null)
                     {
-                        #region Move dragged object
                         if (Input.IsButtonHeld(ButtonCode.Space))
                         {
-                            SnapData snapData = sceneSelection.Snap(scenePos, new SceneObject[] {draggedSO});
-                            Debug.Log(snapData.normal);
-                            Debug.Log(snapData.position);
+                            SnapData snapData;
+                            sceneSelection.Snap(scenePos, out snapData, new SceneObject[] {draggedSO});
                             Quaternion q = Quaternion.FromToRotation(Vector3.YAxis, snapData.normal);
                             draggedSO.Position = snapData.position;
                             draggedSO.Rotation = q;
@@ -603,7 +598,6 @@ namespace BansheeEditor
                             Ray worldRay = camera.ViewportToWorldRay(scenePos);
                             draggedSO.Position = worldRay * DefaultPlacementDepth - draggedSOOffset;
                         }
-                        #endregion
                     }
                 }
 
@@ -623,11 +617,11 @@ namespace BansheeEditor
                 }
             }
 
-            if (HasContentFocus)
+            if (HasContentFocus || IsPointerHovering)
             {
                 cameraController.EnableInput(true);
 
-                if (inBounds)
+                if (inBounds && HasContentFocus)
                 {
                     bool newHandle = false;
                     SceneHandles.BeginInput();
@@ -959,7 +953,6 @@ namespace BansheeEditor
         /// <param name="scenePos">Coordinates relative to the scene where the drag originated.</param>
         private void StartDragSelection(Vector2I scenePos)
         {
-            Debug.Log("Started");
             isDraggingSelection = true;
             dragSelectionStart = scenePos;
             dragSelectionEnd = dragSelectionStart;
@@ -975,25 +968,12 @@ namespace BansheeEditor
         {
             if (!isDraggingSelection)
                 return false;
-            Debug.Log("Updated");
+
             if (dragSelection == null)
             {
-                Debug.Log("Created texture");
-                try
-                {
-                    dragSelection = new GUITexture(null, true, EditorStyles.SelectionArea);
-                    selectionPanel.AddElement(dragSelection);
-                }
-                catch (Exception e)
-                {
-                    Debug.Log(e.ToString());   
-                }
-            }
-            else
-            {
-                Debug.Log("Texture is here");
+                dragSelection = new GUITexture(null, true, EditorStyles.SelectionArea);
+                selectionPanel.AddElement(dragSelection);
             }
-
             
             dragSelectionEnd = scenePos;
 
@@ -1019,7 +999,7 @@ namespace BansheeEditor
         {
             if (!isDraggingSelection)
                 return false;
-            Debug.Log("Ended");
+
             if (dragSelection != null)
             {
                 dragSelection.Destroy();
@@ -1036,8 +1016,6 @@ namespace BansheeEditor
                     Math.Min(dragSelectionStart.y, dragSelectionEnd.y));
             Vector2I max = new Vector2I(Math.Max(dragSelectionStart.x, dragSelectionEnd.x),
                 Math.Max(dragSelectionStart.y, dragSelectionEnd.y));
-            Debug.Log(min);
-            Debug.Log(max);
             sceneSelection.PickObjects(min, max - min,
                 Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl));
             isDraggingSelection = false;

+ 1 - 1
Source/SBansheeEditor/Include/BsScriptSceneSelection.h

@@ -32,7 +32,7 @@ namespace BansheeEngine
 		static void internal_Draw(ScriptSceneSelection* thisPtr);
 		static void internal_PickObject(ScriptSceneSelection* thisPtr, Vector2I* inputPos, bool additive, MonoArray* ignoreRenderables);
 		static void internal_PickObjects(ScriptSceneSelection* thisPtr, Vector2I* inputPos, Vector2I* area, bool additive, MonoArray* ignoreRenderables);
-		static void internal_Snap(ScriptSceneSelection* thisPtr, Vector2I* inputPos, SnapData* data, MonoArray* ignoreRenderables);
+		static MonoObject* internal_Snap(ScriptSceneSelection* thisPtr, Vector2I* inputPos, SnapData* data, MonoArray* ignoreRenderables);
 	};
 
 	/** @} */

+ 8 - 3
Source/SBansheeEditor/Source/BsScriptSceneSelection.cpp

@@ -4,8 +4,10 @@
 #include "BsScriptCamera.h"
 #include "BsSelectionRenderer.h"
 #include "BsScriptSceneObject.h"
+#include "BsScriptGameObjectManager.h"
 #include "BsScenePicking.h"
 #include "BsSelection.h"
+#include "BsMonoPrerequisites.h"
 #include <BsMonoArray.h>
 
 namespace BansheeEngine
@@ -81,7 +83,6 @@ namespace BansheeEngine
 			else
 			{
 				Vector<HSceneObject> selectedSOs = { pickedObject };
-
 				Selection::instance().setSceneObjects(selectedSOs);
 			}
 		}
@@ -145,7 +146,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void ScriptSceneSelection::internal_Snap(ScriptSceneSelection* thisPtr, Vector2I* inputPos, SnapData* data, MonoArray* ignoreRenderables)
+	MonoObject* ScriptSceneSelection::internal_Snap(ScriptSceneSelection* thisPtr, Vector2I* inputPos, SnapData* data, MonoArray* ignoreRenderables)
 	{
 		Vector<HSceneObject> ignoredSceneObjects;
 
@@ -166,8 +167,12 @@ namespace BansheeEngine
 				ignoredSceneObjects.push_back(so);
 			}
 		}
+		HSceneObject instance = ScenePicking::instance().pickClosestObject(thisPtr->mCamera, *inputPos, Vector2I(1, 1), ignoredSceneObjects, data);
+		MonoObject* managedInstance = ScriptGameObjectManager::instance().getOrCreateScriptSceneObject(instance)->getManagedInstance();
+		if (instance == nullptr)
+			return nullptr;
 
-  		ScenePicking::instance().pickClosestObject(thisPtr->mCamera, *inputPos, Vector2I(1, 1), ignoredSceneObjects, data);
+		return  managedInstance;
 	}
 
 }