예제 #1
0
        public void Reset()
        {
            Init();

            _mouseDown = false;
            transform.position = _startPosition;
            if (_currentCell != null)
                _currentCell.currentPlate = null;
            _currentCell = null;
        }
예제 #2
0
        void OnTriggerExit(Collider other)
        {
            if (!_mouseDown)
                return;

            PlateCell cell = other.GetComponent<PlateCell>();
            if (cell != null && cell == _currentCell)
            {
                _currentCell = null;
            }
        }
예제 #3
0
        private void Init()
        {
            if (_isInit)
                return;

            _collider = GetComponent<BoxCollider>();
            _sprite = GetComponent<UISprite>();
            _startPosition = transform.position;
            _currentCell = null;

            _isInit = true;
        }
예제 #4
0
        void Update()
        {
            if (!MiniGame5_Manager.instance.isPlay || _collider == null || !_collider.enabled)
                return;

            if (UICamera.hoveredObject == this.gameObject)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    _mouseDown = true;
                    if (_sprite != null)
                        _sprite.depth++;
                    if (_currentCell != null)
                        _currentCell.currentPlate = null;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    _mouseDown = false;
                    if (_sprite != null)
                        _sprite.depth--;

                    if (_currentCell != null)
                    {
                        if (_currentCell.currentPlate == null)
                            _currentCell.currentPlate = this;
                        else
                            _currentCell = null;
                    }
                }
            }

            if (_mouseDown)
            {
                if (UICamera.hoveredObject != null)
                {
                    transform.position = new Vector3(UICamera.lastHit.point.x, UICamera.lastHit.point.y, transform.position.z);
                    transform.localPosition = new Vector3(Mathf.Clamp(transform.localPosition.x, xLocalMin, xLocalMax), Mathf.Clamp(transform.localPosition.y, yLocalMin, yLocalMax), transform.localPosition.z);
                }
            }
            else if (_currentCell != null && _currentCell.currentPlate == this)
                transform.position = _currentCell.transform.position;
            else if (transform.position != _startPosition)
            {
                // Расчет перемещения
                transform.position = Vector3.Lerp(transform.position, _startPosition, 0.1f);
                if (Vector3.Distance(_startPosition, transform.position) < 0.01f)
                    transform.position = _startPosition;
            }
        }