/// <inheritdoc/> protected internal override void PreInput() { SceneObject[] selectedSceneObjects = Selection.SceneObjects; if (selectedSceneObjects.Length == 0) { if (activeHandle != null) { activeHandle.Destroy(); activeHandle = null; } } else { if (activeHandleType != EditorApplication.ActiveSceneTool || activeHandle == null) { if (activeHandle != null) { activeHandle.Destroy(); activeHandle = null; } switch (EditorApplication.ActiveSceneTool) { case SceneViewTool.Move: activeHandle = new MoveHandle(); break; case SceneViewTool.Rotate: activeHandle = new RotateHandle(); break; case SceneViewTool.Scale: activeHandle = new ScaleHandle(); break; } activeHandleType = EditorApplication.ActiveSceneTool; } } if (activeHandle != null) { // In case the object moved programmatically, make the handle reflect its current transform UpdateActiveHandleTransform(selectedSceneObjects); activeHandle.PreInput(); } }
/// <inheritdoc/> protected internal override void PreInput() { SceneObject[] selectedSceneObjects = Selection.SceneObjects; if (selectedSceneObjects.Length == 0) { if (activeHandle != null) { activeHandle.Destroy(); activeHandle = null; } } else { if (activeHandleType != EditorApplication.ActiveSceneTool || activeHandle == null) { if (activeHandle != null) { activeHandle.Destroy(); activeHandle = null; } switch (EditorApplication.ActiveSceneTool) { case SceneViewTool.Move: activeHandle = new MoveHandle(); break; case SceneViewTool.Rotate: activeHandle = new RotateHandle(); break; case SceneViewTool.Scale: activeHandle = new ScaleHandle(); break; } activeHandleType = EditorApplication.ActiveSceneTool; } } if (activeHandle != null) { Quaternion rotation; if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World) { rotation = Quaternion.Identity; } else { rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection } Vector3 position; if (EditorApplication.ActivePivotMode == HandlePivotMode.Pivot) { position = selectedSceneObjects[0].Position; // Just take pivot from the first one, no averaging } else { List <SceneObject> flatenedHierarchy = new List <SceneObject>(); foreach (var so in selectedSceneObjects) { flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so)); } position = EditorUtility.CalculateCenter(flatenedHierarchy.ToArray()); } activeHandle.Position = position; activeHandle.Rotation = rotation; activeHandle.PreInput(); } }
/// <inheritdoc/> protected internal override void PreInput() { SceneObject[] selectedSceneObjects = Selection.SceneObjects; if (selectedSceneObjects.Length == 0) { if (activeHandle != null) { activeHandle.Destroy(); activeHandle = null; } } else { if (activeHandleType != EditorApplication.ActiveSceneTool || activeHandle == null) { if (activeHandle != null) { activeHandle.Destroy(); activeHandle = null; } switch (EditorApplication.ActiveSceneTool) { case SceneViewTool.Move: activeHandle = new MoveHandle(); break; case SceneViewTool.Rotate: activeHandle = new RotateHandle(); break; case SceneViewTool.Scale: activeHandle = new ScaleHandle(); break; } activeHandleType = EditorApplication.ActiveSceneTool; } } if (activeHandle != null) { Quaternion rotation; if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World) rotation = Quaternion.Identity; else rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection Vector3 position; if (EditorApplication.ActivePivotMode == HandlePivotMode.Pivot) position = selectedSceneObjects[0].Position; // Just take pivot from the first one, no averaging else { List<SceneObject> flatenedHierarchy = new List<SceneObject>(); foreach (var so in selectedSceneObjects) flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so)); AABox selectionBounds = EditorUtility.CalculateBounds(flatenedHierarchy.ToArray()); position = selectionBounds.Center; } activeHandle.Position = position; activeHandle.Rotation = rotation; activeHandle.PreInput(); } }