Repository: FlaxEngine/FlaxEngine
File: Source/Editor/Viewport/MainEditorGizmoViewport.cs (C#)

Code before:
                const float scaleLimit = 99_999_999.0f;
                trans.Scale = Float3.Clamp(trans.Scale + scaleDelta, new Float3(-scaleLimit), new Float3(scaleLimit));

                // Apply translation
                trans.Translation += translationDelta;

                obj.Transform = trans;
            }
        }

        /// <inheritdoc />
        protected override void OrientViewport(ref Quaternion orientation)
        {
            if (TransformGizmo.SelectedParents.Count != 0)
                FocusSelection(ref orientation);
            else
                base.OrientViewport(ref orientation);
        }

        /// <inheritdoc />
        public override void OnMouseMove(Float2 location)
        {
            base.OnMouseMove(location);

            // Dont allow rubber band selection when gizmo is controlling mouse, vertex painting mode, or cloth painting is enabled
            if (_isRubberBandSpanning && ((Gizmos.Active.IsControllingMouse || Gizmos.Active is VertexPaintingGizmo || Gizmos.Active is ClothPaintingGizmo) || IsControllingMouse || IsRightMouseButtonDown))
            {
                _isRubberBandSpanning = false;
            }

            if (_tryStartRubberBand && (Mathf.Abs(MouseDelta.X) > 0.1f || Mathf.Abs(MouseDelta.Y) > 0.1f) && !_isRubberBandSpanning && !Gizmos.Active.IsControllingMouse && !IsControllingMouse && !IsRightMouseButtonDown)
            {
                _isRubberBandSpanning = true;
                _cachedStartingMousePosition = _viewMousePos;
                _rubberBandRect = new Rectangle(_cachedStartingMousePosition, Float2.Zero);
            }
            else if (_isRubberBandSpanning && !Gizmos.Active.IsControllingMouse && !IsControllingMouse && !IsRightMouseButtonDown)
            {
                _rubberBandRect.Width = _viewMousePos.X - _cachedStartingMousePosition.X;
                _rubberBandRect.Height = _viewMousePos.Y - _cachedStartingMousePosition.Y;

                if (_lastRubberBandRect != _rubberBandRect)
                {
                    // Select rubberbanded rect actor nodes
                    var adjustedRect = _rubberBandRect;
                    _lastRubberBandRect = _rubberBandRect;
                    if (adjustedRect.Width < 0 || adjustedRect.Height < 0)
                    {
                        // make sure we have a well-formed rectangle i.e. size is positive and X/Y is upper left corner
                        var size = adjustedRect.Size;
                        adjustedRect.X = Mathf.Min(adjustedRect.X, adjustedRect.X + adjustedRect.Width);

Review comment (refactor):
I would move whole logic from this function (and some local state vars fro the top) into a separate class like `RubberBandSelector` to be reusable in other viewports (like prefab in future) and have more organized code.

Code after:
        }

        /// <inheritdoc />
        protected override void OrientViewport(ref Quaternion orientation)
        {
            if (TransformGizmo.SelectedParents.Count != 0)
                FocusSelection(ref orientation);
            else
                base.OrientViewport(ref orientation);
        }

        /// <inheritdoc />
        public override void OnMouseMove(Float2 location)
        {
            base.OnMouseMove(location);

            // Dont allow rubber band selection when gizmo is controlling mouse, vertex painting mode, or cloth painting is enabled
            _rubberBandSelector.TryCreateRubberBand(!((Gizmos.Active.IsControllingMouse || Gizmos.Active is VertexPaintingGizmo || Gizmos.Active is ClothPaintingGizmo) || IsControllingMouse || IsRightMouseButtonDown), 
                                                   _viewMousePos, ViewFrustum);
        }

        /// <inheritdoc />
        protected override void OnLeftMouseButtonDown()
        {
            base.OnLeftMouseButtonDown();
            
            _rubberBandSelector.TryStartingRubberBandSelection();
        }

        /// <inheritdoc />
        protected override void OnLeftMouseButtonUp()
        {
            // Skip if was controlling mouse or mouse is not over the area
            if (_prevInput.IsControllingMouse || !Bounds.Contains(ref _viewMousePos))
                return;

            // Select rubberbanded rect actor nodes or pick with gizmo
            if (!_rubberBandSelector.ReleaseRubberBandSelection())
            {
                // Try to pick something with the current gizmo
                Gizmos.Active?.Pick();
            }

            // Keep focus
            Focus();

            base.OnLeftMouseButtonUp();
        }

        /// <inheritdoc />
        public override DragDropEffect OnDragEnter(ref Float2 location, DragData data)