Exemple #1
0
    private void UpdateContainer()
    {
        bool  isControlDown    = GetControl();
        bool  isShiftDown      = GetShift();
        float mouseScrollValue = Input.GetAxis("Mouse ScrollWheel");

        if (isControlDown && Math.Abs(mouseScrollValue) > 0.001f)
        {
            Vector2 prevPos = Utils.GetAnchoredPositionInContainer(Input.mousePosition);
            scaleSlider.value += mouseScrollValue * 10;
            Vector2 currPos    = Utils.GetAnchoredPositionInContainer(Input.mousePosition);
            Vector2 offset     = currPos - prevPos;
            Vector3 localScale = containerRect.localScale;
            Debug.Log($"prev: {prevPos}, curr: {currPos}, offset: {offset}, scale: {localScale.x}");
            containerRect.anchoredPosition += offset * localScale.x;
        }

        if (isControlDown || Input.GetMouseButton(0))
        {
            containerScrollRect.horizontal = false;
            containerScrollRect.vertical   = false;
        }
        else if (Input.GetMouseButton(2))
        {
            containerScrollRect.horizontal = true;
            containerScrollRect.vertical   = true;
            if (Input.GetMouseButtonDown(2))
            {
                _containerOffset = containerRect.anchoredPosition3D - Input.mousePosition;
            }
            else
            {
                containerRect.anchoredPosition3D = Input.mousePosition + _containerOffset;
            }
        }
        else
        {
            containerScrollRect.horizontal        = isShiftDown;
            containerScrollRect.vertical          = !isShiftDown;
            containerScrollRect.scrollSensitivity = Math.Abs(containerScrollRect.scrollSensitivity) * (isShiftDown ? -1 : 1);
        }

        if (isControlDown || !Input.anyKey)
        {
            return;
        }
        if (GetAlt())
        {
            Transform displayObject = GlobalData.CurrentSelectDisplayObjectDic.OnlyValue();
            if (!displayObject)
            {
                return;
            }
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                DisplayObjectUtil.SelectDisplayObjectByOffset(displayObject, -1, isShiftDown);
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                DisplayObjectUtil.SelectDisplayObjectByOffset(displayObject, 1, isShiftDown);
            }
            return;
        }
        Vector2 delta = Vector2.zero;

        if (Input.GetKey(KeyCode.UpArrow))
        {
            delta += Vector2.up * containerKeyMoveSensitivity;
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            delta += Vector2.down * containerKeyMoveSensitivity;
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            delta += Vector2.left * containerKeyMoveSensitivity;
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            delta += Vector2.right * containerKeyMoveSensitivity;
        }

        if (Utils.IsFocusOnInputText() || Utils.IsEqual(delta.x, 0) && Utils.IsEqual(delta.y, 0))
        {
            return;
        }
        Debug.Log($"delta: {delta}");
        containerRect.anchoredPosition += delta;
    }