public void EndMoving()
    {
        _movingHandle = false;
        _slicePreview.SetActive(false);
        _sliceNr.SetActive(false);

        _slicer.Slice = _indicator.Slice;

        _assnetwork.setSlice(_indicator.Slice);
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            _scrolling = false;
            _sliding   = false;

            if (_sliderArea.Contains(Input.mousePosition))
            {
                if (Input.mousePosition.x < left + sliderWidth)
                {
                    _sliding    = true;
                    _slideSpeed = 0;
                }
                else
                {
                    _scrolling     = true;
                    _offsetSpeed   = 0;
                    _slicesChanged = 0;
                }
            }
        }
        else if (Input.GetMouseButton(0))
        {
            if (_sliding || _scrolling)
            {
                float mouseDelta  = -Utils.MouseDelta.y;
                float mouseYSpeed = -Utils.MouseVelocity.y;

                if (_sliding)
                {
                    int slicesDelta = (int)Mathf.Round(mouseDelta / Screen.height * (float)_loader.SlicesCount);
                    _fakeSlice  = Mathf.Clamp(_fakeSlice - slicesDelta, 1, _loader.SlicesCount);
                    _slideSpeed = mouseYSpeed;
                }
                else if (_scrolling)
                {
                    _offset     += mouseDelta;
                    _offsetSpeed = mouseYSpeed;
                }
            }
        }
        else
        {
            // kinectic scrolling

            float speedLoss = 2000 * Time.deltaTime;

            if (_scrolling)
            {
                if (_offsetSpeed > 0)
                {
                    _offsetSpeed = Mathf.Max(_offsetSpeed - speedLoss, 0);
                }
                else
                {
                    _offsetSpeed = Mathf.Min(_offsetSpeed + speedLoss, 0);
                }

                if (_offsetSpeed == 0)
                {
                    _scrolling = false;
                    _slice     = _fakeSlice;
                    _sliceNr   = _loader.GetRealSliceNumber(_slice);
                    _loader.ForceSliceLoad();

                    _assnetwork.setSlice(_sliceNr);
                }
                else
                {
                    _offset += _offsetSpeed * Time.deltaTime;
                }
            }
            else if (_sliding)
            {
                if (_slideSpeed > 0)
                {
                    _slideSpeed = Mathf.Max(_slideSpeed - speedLoss, 0);
                }
                else
                {
                    _slideSpeed = Mathf.Min(_slideSpeed + speedLoss, 0);
                }

                if (_slideSpeed == 0)
                {
                    _sliding = false;
                    _slice   = _fakeSlice;
                    _sliceNr = _loader.GetRealSliceNumber(_slice);
                    _loader.ForceSliceLoad();

                    _assnetwork.setSlice(_sliceNr);
                }
                else
                {
                    int slicesDelta = (int)Mathf.Round(_slideSpeed * Time.deltaTime / Screen.height * (float)_loader.SlicesCount);
                    _fakeSlice = Mathf.Clamp(_fakeSlice - slicesDelta, 1, _loader.SlicesCount);

                    if (_fakeSlice == 1 || _fakeSlice == _loader.SlicesCount)
                    {
                        _slideSpeed = 0;
                    }
                }
            }
        }

        // change slice

        float halfSliceHeight = sliceHeight / 2.0f;

        while (_offset > halfSliceHeight)
        {
            if (_fakeSlice == 1)
            {
                break;
            }
            _offset -= sliceHeight;
            _fakeSlice--;
            _slicesChanged++;
        }
        while (_offset < -halfSliceHeight)
        {
            if (_fakeSlice == _loader.SlicesCount)
            {
                break;
            }
            _offset += sliceHeight;
            _fakeSlice++;
            _slicesChanged++;
        }

        // lock min & max slices
        if ((_fakeSlice == 1 && _offset > 0) || (_fakeSlice == _loader.SlicesCount && _offset < 0))
        {
            _offset      = 0;
            _offsetSpeed = 0;
        }
    }