private void FixedUpdate()
        {
            if (IsScaling)
            {
                var playerTransform = PlayerController.gameObject.transform;
                var center          = selectionFilter.GetCenter();
                if (Math3d.ClosestPointsOnTwoLines(out _, out Vector3 point, playerTransform.position, playerTransform.forward, center, scaleDirection))
                {
                    Vector3Int min = selectionFilter.min;
                    Vector3Int max = selectionFilter.max;

                    float desiredLength = Vector3.Dot(point - center, scaleDirection);
                    if (desiredLength > 0)
                    {
                        Vector3 offsetCenter = center + scaleDirection;

                        Vector3Int size          = selectionFilter.GetSize();
                        float      currentLength = Mathf.Abs(Vector3.Dot(size, scaleDirection)) / 2;
                        // determine closest point to scaling direction:
                        if ((min - offsetCenter).sqrMagnitude < (max - offsetCenter).sqrMagnitude)
                        {
                            min += scaleDirection * Mathf.RoundToInt(desiredLength - currentLength);
                        }
                        else
                        {
                            max += scaleDirection * Mathf.RoundToInt(desiredLength - currentLength);
                        }
                        selectionFilter = SelectionFilter.FromSelection(min, max, ~gizmoLayerMask);
                        OnSelect(selectionFilter);
                    }
                }
            }
            if (IsSelecting)
            {
                var playerTransform = PlayerController.gameObject.transform;
                if (Physics.Raycast(playerTransform.position, playerTransform.forward, out RaycastHit hit, 500, ~gizmoLayerMask))
                {
                    selectionFilter.DoSelection(hit);
                }
            }
        }
Beispiel #2
0
        // // don't do anything on clicking the function in the hotbar:
        // public override void OnHotBarFunctionClick() {}

        private void ShowMoveGizmo(SelectionFilter selectionFilter)
        {
            moveGizmo.SetActive(true, MoveObjects);
            moveGizmo.SetPosition(selectionFilter.GetCenter());
        }